I created a ContextMenu object with ContextMenuButtons for undo and redo. I bound isEnabled to functions calling diagram.commandHandler.canUndo()/canRedo().
Now, I discovered that as soon as I click the undo/redo ContextMenuButton once, it afterwards gets stuck with its _buttonFillOver color. It still does change to _buttonFillDisabled when it’s disabled, but never changes back to _buttonFillNormal again. Am I doing something wrong here?
I also had a look into Buttons.js and was thinking that maybe btn[‘_buttonFillNormal’] gets messed up at some point when shape.fill is assigned to it but still may contain the value of btn['_buttonFillOver]?
Here is how I define the buttons:
function getContextMenuButton(text, onClick, isEnabled) {
return go.GraphObject.build("ContextMenuButton", {click: onClick, "_buttonFillDisabled": COLOR_LIGHTGREY})
.bindObject("isEnabled", "", isEnabled)
.bindObject("cursor", "", (o) => isEnabled(o) ? "pointer" : "auto")
.add(new go.TextBlock(text, {width: CONTEXT_MENU_W, textAlign: "center"})
.bindObject("stroke", "", (o) => isEnabled(o) ? COLOR_BLACK: COLOR_GREY));
}
function isUndoEnabled(o) {
if ((o !== null) && (o.diagram !== null)) {
return o.diagram.commandHandler.canUndo();
}
return false;
}
function isRedoEnabled(o) {
if ((o !== null) && (o.diagram !== null)) {
return o.diagram.commandHandler.canRedo();
}
return false;
}
const undoButton = getContextMenuButton("Undo", (e, o) => e.diagram.commandHandler.undo(), isUndoEnabled);
const redoButton = getContextMenuButton("Redo", (e, o) => e.diagram.commandHandler.redo(), isRedoEnabled);