mirror of
https://github.com/Siccity/xNode.git
synced 2026-03-26 22:49:02 +08:00
Changed from GetContextMenu to AddContextMenuItems
This commit is contained in:
parent
8d09e54fd8
commit
a2cb736811
@ -81,25 +81,24 @@ namespace XNodeEditor {
|
||||
return NodeEditorResources.styles.nodeBody;
|
||||
}
|
||||
|
||||
/// <summary> Show right-click context menu for selected nodes </summary>
|
||||
public virtual GenericMenu GetContextMenu() {
|
||||
GenericMenu contextMenu = new GenericMenu();
|
||||
// If only one node is selected
|
||||
/// <summary> Add items for the context menu when right-clicking this node. Override to add custom menu items. </summary>
|
||||
public virtual void AddContextMenuItems(GenericMenu menu) {
|
||||
// Actions if only one node is selected
|
||||
if (Selection.objects.Length == 1 && Selection.activeObject is XNode.Node) {
|
||||
XNode.Node node = Selection.activeObject as XNode.Node;
|
||||
contextMenu.AddItem(new GUIContent("Move To Top"), false, () => NodeEditorWindow.current.MoveNodeToTop(node));
|
||||
contextMenu.AddItem(new GUIContent("Rename"), false, NodeEditorWindow.current.RenameSelectedNode);
|
||||
menu.AddItem(new GUIContent("Move To Top"), false, () => NodeEditorWindow.current.MoveNodeToTop(node));
|
||||
menu.AddItem(new GUIContent("Rename"), false, NodeEditorWindow.current.RenameSelectedNode);
|
||||
}
|
||||
|
||||
contextMenu.AddItem(new GUIContent("Duplicate"), false, NodeEditorWindow.current.DuplicateSelectedNodes);
|
||||
contextMenu.AddItem(new GUIContent("Remove"), false, NodeEditorWindow.current.RemoveSelectedNodes);
|
||||
// Add actions to any number of selected nodes
|
||||
menu.AddItem(new GUIContent("Duplicate"), false, NodeEditorWindow.current.DuplicateSelectedNodes);
|
||||
menu.AddItem(new GUIContent("Remove"), false, NodeEditorWindow.current.RemoveSelectedNodes);
|
||||
|
||||
// If only one node is selected
|
||||
// Custom sctions if only one node is selected
|
||||
if (Selection.objects.Length == 1 && Selection.activeObject is XNode.Node) {
|
||||
XNode.Node node = Selection.activeObject as XNode.Node;
|
||||
NodeEditorWindow.AddCustomContextMenuItems(contextMenu, node);
|
||||
NodeEditorWindow.AddCustomContextMenuItems(menu, node);
|
||||
}
|
||||
return contextMenu;
|
||||
}
|
||||
|
||||
public void InitiateRename() {
|
||||
|
||||
@ -260,7 +260,9 @@ namespace XNodeEditor {
|
||||
ShowPortContextMenu(hoveredPort);
|
||||
} else if (IsHoveringNode && IsHoveringTitle(hoveredNode)) {
|
||||
if (!Selection.Contains(hoveredNode)) SelectNode(hoveredNode, false);
|
||||
NodeEditor.GetEditor(hoveredNode).GetContextMenu().DropDown(new Rect(Event.current.mousePosition, Vector2.zero));
|
||||
GenericMenu menu = new GenericMenu();
|
||||
NodeEditor.GetEditor(hoveredNode).AddContextMenuItems(menu);
|
||||
menu.DropDown(new Rect(Event.current.mousePosition, Vector2.zero));
|
||||
} else if (!IsHoveringNode) {
|
||||
ShowGraphContextMenu();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user