Thanks Walter, this is helping me move forward. I am now able to use key up/down to select menu items.
One issue that I have here (and in another case as well) has to do with bindings. We’ve been using GoJS for a long time (still on 1.7.27), but I wasn’t the one managing this before. The context menu already contained bindings to change disabled menu items but that was/isn’t working. The opacity bindings were there and I added the background but they are not getting called. The same enablement function works fine on mouseEnter for example.
function createContextMenuItem(pictureSource, label, tooltip, action, enablementFunction) {
return $g(go.Panel, go.Panel.Auto,
{
click : function(e, obj) {
if (isEnabled(obj.part.data, enablementFunction)) {
action(e, obj);
}
},
desiredSize : new go.Size(200, 25),
mouseEnter: function(e, menuItem, prev) {
if (isEnabled(menuItem.part.data, enablementFunction)) {
var shape = menuItem.findObject("mainShape");
shape.fill = "rgb(243,243,243)";
return true;
}
return false;
},
mouseLeave: function(e, menuItem, prev) {
if (isEnabled(menuItem.part.data, enablementFunction)) {
var shape = menuItem.findObject("mainShape");
shape.fill = "white";
return true;
}
return false;
},
toolTip: createToolTip(tooltip)
},
$g(go.Shape, "Rectangle", {
name: "mainShape",
// background: "white",
fill: "white",
stroke: "lightgray"
},
getShadowVisibleBinding(),
new go.Binding("background", "", function(obj) {
return isEnabled(obj.part.data, enablementFunction) ? white : "rgb(197,197,197)";
}).ofObject()
),
$g(go.Picture,
{
width : 16,
height : 16,
margin : new go.Margin(3, 2, 5, 3),
alignment : go.Spot.MiddleLeft,
imageStretch : go.GraphObject.Uniform,
source : pictureSource,
shadowVisible: false
},
new go.Binding("opacity", "", function(obj) {
return isEnabled(obj.part.data, enablementFunction) ? 1 : 0.3;
}).ofObject()
),
$g(go.TextBlock, label,
{
name: "label",
textAlign : "left",
isMultiline: true,
alignment : go.Spot.MiddleLeft,
margin : new go.Margin(0, 2, 0, 25),
font: "13px Arial, sans-serif",
shadowVisible: false
},
new go.Binding("opacity", "", function(obj) {
return isEnabled(obj.part.data, enablementFunction) ? 1 : 0.3;
}).ofObject()
)
);
}
My other binding issue has to do with wanting to change the selection adornment style. I am using the DrawCommandHelper in select mode and want to show the focus node differently than the selected ones when doing multi-select (btw fixed to allow tracking last selected). Debugging I can see that transaction is called correctly but the node loosing the focus doesn’t gets updated, but the one gaining the focus is fine. Just added updateTargetBindings and same results.
function updateCurrentSelection(entering) {
runInTransaction("Update current selection", true, function() {
var model = mainDiagram.model;
if (model.modelData._lastSelection !== undefined) {
model.setDataProperty(model.modelData._lastSelection.data, "_selectionDashArray", null);
model.modelData._lastSelection.updateTargetBindings("_selectionDashArray");
}
if (entering !== undefined) {
model.setDataProperty(entering.data, "_selectionDashArray", currentSelectionDashArray);
}
model.modelData._lastSelection = entering;
});
}
and the template with binding:
var selectionTemplate =
$g(go.Adornment, "Auto",
$g(go.Shape, "RoundedRectangle",
{
fill: null,
stroke: "dodgerblue",
strokeWidth: 3
},
new go.Binding("strokeDashArray", "_selectionDashArray").makeTwoWay()),
$g(go.Placeholder)
);