- Fix do and undo buttons disable action

This commit is contained in:
Paulo Gustavo Veiga 2012-07-15 23:35:45 -03:00
parent 8d4b336908
commit 3986a97717
2 changed files with 54 additions and 23 deletions

View File

@ -239,17 +239,34 @@ mindplot.widget.Menu = new Class({
this._registerTooltip('zoomOut', $msg('ZOOM_OUT'));
this._addButton('undoEdition', false, false, function () {
var undoButton = this._addButton('undoEdition', false, false, function () {
designer.undo();
});
undoButton.disable();
this._registerTooltip('undoEdition', $msg('UNDO'), "meta+Z");
this._addButton('redoEdition', false, false, function () {
var redoButton = this._addButton('redoEdition', false, false, function () {
designer.redo();
});
redoButton.disable();
this._registerTooltip('redoEdition', $msg('REDO'), "meta+shift+Z");
if (redoButton && undoButton) {
designer.addEvent('modelUpdate', function (event) {
if (event.undoSteps > 0) {
undoButton.enable();
} else {
undoButton.disable();
}
if (event.redoSteps > 0) {
redoButton.enable();
} else {
redoButton.disable();
}
}.bind(this));
}
this._addButton('addTopics', true, false, function () {
designer.createChildForSelectedNode();
@ -442,6 +459,9 @@ mindplot.widget.Menu = new Class({
var rels = designer.getModel().filterSelectedRelationships();
this._toolbarElems.each(function (button) {
var buttonId = button.getButtonId();
if (buttonId != "undoEdition" && buttonId != "redoEdition") {
var disable = false;
if (button.isTopicAction() && button.isRelAction()) {
disable = rels.length == 0 && topics.length == 0;
@ -459,7 +479,7 @@ mindplot.widget.Menu = new Class({
} else {
button.enable();
}
}
})
}.bind(this));
@ -468,6 +488,9 @@ mindplot.widget.Menu = new Class({
var rels = designer.getModel().filterSelectedRelationships();
this._toolbarElems.each(function (button) {
var buttonId = button.getButtonId();
if (buttonId != "undoEdition" && buttonId != "redoEdition") {
if (button.isTopicAction() && topics.length > 0) {
button.enable();
}
@ -475,12 +498,14 @@ mindplot.widget.Menu = new Class({
if (button.isRelAction() && rels.length > 0) {
button.enable();
}
}
})
}.bind(this));
},
_addButton:function (buttonId, topic, rel, fn) {
// Register Events ...
var result = null;
if ($(buttonId)) {
var button = new mindplot.widget.ToolbarItem(buttonId, function (event) {
@ -489,7 +514,9 @@ mindplot.widget.Menu = new Class({
}.bind(this), {topicAction:topic, relAction:rel});
this._toolbarElems.push(button);
result = button;
}
return result;
},
_registerTooltip:function (buttonId, text, shortcut) {

View File

@ -55,6 +55,10 @@ mindplot.widget.ToolbarItem = new Class({
return elem;
}.protect(),
getButtonId : function(){
return this._buttonId;
},
show : function() {
this.fireEvent('show');
},