Profile Picture

How to remove auto generated context menu items for the selected shape conditionally?

Posted By Niranjan Singh 8 Years Ago

How to remove auto generated context menu items for the selected shape...

Author
Message
Niranjan Singh
Question Posted 8 Years Ago
View Quick Profile
Forum Member

Forum Member (41 reputation)Forum Member (41 reputation)Forum Member (41 reputation)Forum Member (41 reputation)Forum Member (41 reputation)Forum Member (41 reputation)Forum Member (41 reputation)Forum Member (41 reputation)Forum Member (41 reputation)

Group: Forum Members
Last Active: 4 Years Ago
Posts: 49, Visits: 179
Hi,
I need to remove all the context menu items for the selected diagram shape except the "Delete" and "update bounds" item. I have tried to remove all the command from the CommandBarManager contexts. It has removed most of the items from the context menu for the selected shape but I want it to display only two elements:
Update model bounds 
Delete


How can i remove another element the context menu. Specially the "Properties" menu item.

NControlHelper.BeginUpdate(nDiagramCommandBarsManager1.ParentControl);
// replace the toolbar builder with a custom one
nDiagramCommandBarsManager1.ToolbarsBuilder = new
  NCustomDiagramToolbarsBuilder(toolBarsItemCount,
  nDiagramCommandBarsManager1);

// recreate the command bars. Since we have replaced the toolbars builder,
// this will add the new commands in the toolbars.
// without this statement toolbar will not be refreshed with newly added
// tools. In addition to newly added tools even predefined tools will be available
// which are removed below.
nDiagramCommandBarsManager1.Recreate();
List<int[]> removingContexts = new List<int[]>(){{nDiagramCommandBarsManager1.
                  ToolbarsBuilder.
                  StandardCommandIds},
{nDiagramCommandBarsManager1.ToolbarsBuilder.LibraryCommandIds},
{nDiagramCommandBarsManager1.ToolbarsBuilder.ViewCommandIds},
{nDiagramCommandBarsManager1.ToolbarsBuilder.FormatCommandIds},
{nDiagramCommandBarsManager1.ToolbarsBuilder.ActionCommandIds},
{nDiagramCommandBarsManager1.ToolbarsBuilder.LayoutCommandIds},
{nDiagramCommandBarsManager1.ToolbarsBuilder.ToolsCommandIds}};


for (int iList = 0; iList < removingContexts.Count; iList++)
{
  for (int iContext = 0; iContext < removingContexts[iList].Length;
   iContext++)
  {
   NCommandContext commandContext = nDiagramCommandBarsManager1.Contexts.ContextFromID(removingContexts[iList][iContext]);
   if (commandContext != null && commandContext.ToString() == "Delete")
   {
    continue;
   }
   nDiagramCommandBarsManager1.Contexts.Remove(commandContext);
  }
}

nDiagramCommandBarsManager1.CommandContextExecuted += new
  CommandContextEventHandler(nDiagramCommandBarsManager1_CommandContextExecuted);
NControlHelper.EndUpdate(nDiagramCommandBarsManager1.ParentControl,
  true);


https://www.nevron.com/forum/uploads/images/e269ebf4-9d6b-4cbe-b53e-726b.png
Hope there is some way to customize the auto generated context menu. I am not able to get the context menu on  
on mouse down event. It found null always.

// Make sure the right mouse button was clicked
if (e.Button != MouseButtons.Right)
  return;

// Hit test the drawing document
NPointF location = new NPointF(e.Location);
NNodeList shapes = nDrawingView1.document.HitTest(location, -1, Nevron.Diagram.Filters.NFilters.TypeNCompositeShape, nDrawingView1.ProvideDocumentHitTestContext());
if (shapes.Count != 0 && nDrawingView1.ContextMenu != null)
{


Please suggest me the correct way to implement this..

Thanks,
Niranjan


Tags
Nevron Support
This post has been flagged as an answer
Posted 8 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)

Group: Forum Members
Last Active: Last Year
Posts: 3,039, Visits: 3,746
Hi,

There's a much easier way to achieve what you want. Instead of removing almost all commands one by one, you can simply create a custom context menu builder and add only the commands you want:

internal class CustomContextMenuBuilder : NDiagramContextMenuBuilder
{
    public override NContextMenu BuildContextMenu(object obj)
    {
        NContextMenu contextMenu = new NContextMenu();
        contextMenu.Commands.Add(CreateCommand((int)DiagramCommand.UpdateModelBounds, false));
        contextMenu.Commands.Add(CreateCommand((int)DiagramCommand.Delete, false));

        return contextMenu;
    }
}


You can then create an instance of this custom context menu builder and assign it to the ContextMenuBuilder property of your diagram command bars manager:

nDiagramCommandBarsManager1.ContextMenuBuilder = new CustomContextMenuBuilder();



Best Regards,
Nevron Support Team





Similar Topics


Reading This Topic