I have the following context menu objects:
var nodeMenu = // right click context menu for each Node
$(go.Adornment, "Vertical",
{
background: "#F5F5F5"
},
makeButton("Rediger",
function (e, obj) { showDialog(obj.part.adornedPart) }),
makeButton("Slett",
function (e, obj) { myDiagram.remove(obj.part.adornedPart) })
);
var linkMenu = // right click context menu for each Link
$(go.Adornment, "Vertical",
{
background: "#F5F5F5"
},
makeButton("Slett",
function (e, obj) { myDiagram.remove(showDialog(obj.part.adornedPart)) })
);
Firstly: the “remove”-call just removes the node from the diagram. What I need is for the node to trigger all the same events as selecting the node and pressing delete does. I have currently mapped deletion of nodes and links to my backend through the addModelChangedListener, but the .remove call doesn’t trigger this. How do I run a deletion that also triggers the same events as a delete keypress?
Secondly: When I run the remove call on the link, this just outright crashes. But when I have the correct method of handling node deletion maybe this will also fix this? If not, how do I trigger a deletion of links without skipping the deletion event? I tried using removeLinkData in place of .remove.
This is the makeButton function:
function makeButton(text, action, visiblePredicate) {
return $("ContextMenuButton",
$(go.TextBlock, { margin: new go.Margin(0, 50, 0, 5), text: text, font: "0.9375rem Verdana, sans-serif" }),
{ click: action },
// don't bother with binding GraphObject.visible if there's no predicate
visiblePredicate ? new go.Binding("visible", "", function(o, e) { return o.diagram ? visiblePredicate(o, e) : false; }).ofObject() : {});
}
Edit: From further testing, it seems the reason .remove doesn’t trigger the events is because it makes the change “outisde of a transaction”. So essentially I want a way to call it through a transaction, I suppose?