Hide Context Menu

Hi ,

I have a context menu which is define in the template of my nodes and i need to close the context menu on an event.

I tried this but it seems doesnt correct:

  myLocalDiagram.toolManager.contextMenuTool.hideContextMenu();

Thanks

That should work. You are talking about a context menu that you have defined as an Adornment as the value of some GraphObject.contextMenu, yes? And it shows properly when the user context clicks? Or are you showing the context menu programmatically too?

If the ContextMenuTool.currentContextMenu is null because the tool is not showing any context menu, it’s a no-op, as you would expect.

First question , yes.
Second , yes.
Third No.

The context menu disapears but when the user clik on the same node with the left clik the menu appear again

var contextMenuButonsAsset = GO(go.Adornment, go.Panel.Vertical,
                                      GO("ContextMenuButton",
                                   GO(go.TextBlock, "Add"),
                                   { click: RedictEditScreenADD }),
                                          GO("ContextMenuButton",
                                   GO(go.TextBlock, "Update"),
                                   { click: RedictEditScreen })
                                   );


 myFullDiagram.nodeTemplateMap.add("Asset",
                                              GO(go.Node, go.Panel.Vertical, { locationSpot: go.Spot.Center, selectionObjectName: 'selection' },
                                                     new go.Binding("location", "loc", go.Point.parse).makeTwoWay(go.Point.stringify),
                                                          new go.Binding("text", "key"),
                                                           GO(go.Panel, go.Panel.Auto, { name: 'selection' },
                                                               GO(go.Shape, "RoundedRectangle",
                                                                  { fill: assetColor, stroke: null }),
                                                               GO(go.Panel, go.Panel.Horizontal,
                                                                    GO(go.Picture,
                                                                           new go.Binding("source", "category", nodeTypeImage), { width: 20, height: 20 }),
                                                                    GO(go.TextBlock, textStyle(),
                                                                      { text: 'Asset' },
                                                                      new go.Binding("text", "text").makeTwoWay())
                                                                  ))
                                                             ,
                                                             GO(go.TextBlock, { margin: new go.Margin(5, 0, 0, 0), font: smallfont }, new go.Binding("text", "counter1")),
                                                               {
                                                                   contextMenu: contextMenuButonsAsset
                                                               },
                                                              {
                                                                  click: function (e, obj) { LeftFullClick() }
                                                              }
                                                         )
                                               );

Oh, so you do not want to continue running the ContextMenuTool? Then you should stop or cancel the tool.

Perhaps you want to call myDiagram.currentTool.doCancel()? That would of course also hide the currentContextMenu, if it is showing.

I tried with myDiagram.currentTool.doCancel() and that was be good!

Thanks.

2 posts were split to a new topic: Customizing context menu