/// <summary> /// Shows the secondary context menu. /// </summary> /// <param name="location">The location in the Surface Space.</param> /// <param name="controlUnderMouse">The Surface Control that is under the cursor. Used to customize the menu.</param> public virtual void ShowSecondaryCM(Vector2 location, SurfaceControl controlUnderMouse) { var selection = SelectedNodes; if (selection.Count == 0) { return; } // Create secondary context menu var menu = new FlaxEditor.GUI.ContextMenu.ContextMenu(); if (_onSave != null) { menu.AddButton("Save", _onSave).Enabled = CanEdit; menu.AddSeparator(); } _cmCopyButton = menu.AddButton("Copy", Copy); menu.AddButton("Paste", Paste).Enabled = CanEdit && CanPaste(); _cmDuplicateButton = menu.AddButton("Duplicate", Duplicate); _cmDuplicateButton.Enabled = CanEdit; var canRemove = CanEdit && selection.All(node => (node.Archetype.Flags & NodeFlags.NoRemove) == 0); menu.AddButton("Cut", Cut).Enabled = canRemove; menu.AddButton("Delete", Delete).Enabled = canRemove; if (_supportsDebugging) { menu.AddSeparator(); if (selection.Count == 1) { menu.AddButton(selection[0].Breakpoint.Set ? "Delete breakpoint" : "Add breakpoint", () => { foreach (var node in Nodes) { if (node.IsSelected) { node.Breakpoint.Set = !node.Breakpoint.Set; node.Breakpoint.Enabled = true; OnNodeBreakpointEdited(node); break; } } }); menu.AddButton("Toggle breakpoint", () => { foreach (var node in Nodes) { if (node.IsSelected) { node.Breakpoint.Enabled = !node.Breakpoint.Enabled; OnNodeBreakpointEdited(node); break; } } }).Enabled = selection[0].Breakpoint.Set; } menu.AddSeparator(); menu.AddButton("Delete all breakpoints", () => { foreach (var node in Nodes) { if (node.Breakpoint.Set) { node.Breakpoint.Set = false; OnNodeBreakpointEdited(node); } } }).Enabled = Nodes.Any(x => x.Breakpoint.Set); menu.AddButton("Enable all breakpoints", () => { foreach (var node in Nodes) { if (!node.Breakpoint.Enabled) { node.Breakpoint.Enabled = true; OnNodeBreakpointEdited(node); } } }).Enabled = Nodes.Any(x => x.Breakpoint.Set && !x.Breakpoint.Enabled); menu.AddButton("Disable all breakpoints", () => { foreach (var node in Nodes) { if (node.Breakpoint.Enabled) { node.Breakpoint.Enabled = false; OnNodeBreakpointEdited(node); } } }).Enabled = Nodes.Any(x => x.Breakpoint.Set && x.Breakpoint.Enabled); } menu.AddSeparator(); _cmFormatNodesConnectionButton = menu.AddButton("Format node(s)", () => { FormatGraph(SelectedNodes); }); _cmFormatNodesConnectionButton.Enabled = CanEdit && HasNodesSelection; _cmRemoveNodeConnectionsButton = menu.AddButton("Remove all connections to that node(s)", () => { var nodes = ((List <SurfaceNode>)menu.Tag); if (Undo != null) { var actions = new List <IUndoAction>(nodes.Count); foreach (var node in nodes) { var action = new EditNodeConnections(Context, node); node.RemoveConnections(); action.End(); actions.Add(action); } Undo.AddAction(new MultiUndoAction(actions, actions[0].ActionString)); } else { foreach (var node in nodes) { node.RemoveConnections(); } } MarkAsEdited(); }); _cmRemoveNodeConnectionsButton.Enabled = CanEdit; _cmRemoveBoxConnectionsButton = menu.AddButton("Remove all connections to that box", () => { var boxUnderMouse = (Box)_cmRemoveBoxConnectionsButton.Tag; if (Undo != null) { var action = new EditNodeConnections(Context, boxUnderMouse.ParentNode); boxUnderMouse.RemoveConnections(); action.End(); Undo.AddAction(action); } else { boxUnderMouse.RemoveConnections(); } MarkAsEdited(); }); _cmRemoveBoxConnectionsButton.Enabled = CanEdit; { var boxUnderMouse = GetChildAtRecursive(location) as Box; _cmRemoveBoxConnectionsButton.Enabled = boxUnderMouse != null && boxUnderMouse.HasAnyConnection; _cmRemoveBoxConnectionsButton.Tag = boxUnderMouse; } controlUnderMouse?.OnShowSecondaryContextMenu(menu, controlUnderMouse.PointFromParent(location)); OnShowSecondaryContextMenu(menu, controlUnderMouse); // Show secondary context menu _cmStartPos = location; menu.Tag = selection; menu.MaximumItemsInViewCount = 24; menu.Show(this, location); }
/// <summary> /// Shows the secondary context menu. /// </summary> /// <param name="location">The location in the Surface Space.</param> /// <param name="controlUnderMouse">The Surface Control that is under the cursor. Used to customize the menu.</param> public virtual void ShowSecondaryCM(Vector2 location, SurfaceControl controlUnderMouse) { var selection = SelectedNodes; if (selection.Count == 0) { return; } // Create secondary context menu var menu = new FlaxEditor.GUI.ContextMenu.ContextMenu(); menu.AddButton("Save", _onSave); menu.AddSeparator(); _cmCopyButton = menu.AddButton("Copy", Copy); menu.AddButton("Paste", Paste).Enabled = CanPaste(); _cmDuplicateButton = menu.AddButton("Duplicate", Duplicate); var canRemove = selection.All(node => (node.Archetype.Flags & NodeFlags.NoRemove) == 0); menu.AddButton("Cut", Cut).Enabled = canRemove; menu.AddButton("Delete", Delete).Enabled = canRemove; menu.AddSeparator(); _cmRemoveNodeConnectionsButton = menu.AddButton("Remove all connections to that node(s)", () => { var nodes = ((List <SurfaceNode>)menu.Tag); if (Undo != null) { var actions = new List <IUndoAction>(nodes.Count); foreach (var node in nodes) { var action = new EditNodeConnections(Context, node); node.RemoveConnections(); action.End(); actions.Add(action); } Undo.AddAction(new MultiUndoAction(actions, actions[0].ActionString)); } else { foreach (var node in nodes) { node.RemoveConnections(); } } MarkAsEdited(); }); _cmRemoveBoxConnectionsButton = menu.AddButton("Remove all connections to that box", () => { var boxUnderMouse = (Box)_cmRemoveBoxConnectionsButton.Tag; if (Undo != null) { var action = new EditNodeConnections(Context, boxUnderMouse.ParentNode); boxUnderMouse.RemoveConnections(); action.End(); Undo.AddAction(action); } else { boxUnderMouse.RemoveConnections(); } MarkAsEdited(); }); { var boxUnderMouse = GetChildAtRecursive(location) as Box; _cmRemoveBoxConnectionsButton.Enabled = boxUnderMouse != null && boxUnderMouse.HasAnyConnection; _cmRemoveBoxConnectionsButton.Tag = boxUnderMouse; } controlUnderMouse?.OnShowSecondaryContextMenu(menu, controlUnderMouse.PointFromParent(location)); OnShowSecondaryContextMenu(menu, controlUnderMouse); // Show secondary context menu _cmStartPos = location; menu.Tag = selection; menu.Show(this, location); }