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

View File

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