diff --git a/Source/Editor/Surface/ContextMenu/VisjectCM.cs b/Source/Editor/Surface/ContextMenu/VisjectCM.cs index 21d0e7470..e1a61fd5f 100644 --- a/Source/Editor/Surface/ContextMenu/VisjectCM.cs +++ b/Source/Editor/Surface/ContextMenu/VisjectCM.cs @@ -585,7 +585,7 @@ namespace FlaxEditor.Surface.ContextMenu private void UpdateFilters() { - if (string.IsNullOrEmpty(_searchBox.Text) && _selectedBoxes[0] == null) + if (string.IsNullOrEmpty(_searchBox.Text) && _selectedBoxes.Count == 0) { ResetView(); Profiler.EndEvent(); diff --git a/Source/Editor/Surface/VisjectSurface.ContextMenu.cs b/Source/Editor/Surface/VisjectSurface.ContextMenu.cs index d8dfb8ad3..ffb1c725a 100644 --- a/Source/Editor/Surface/VisjectSurface.ContextMenu.cs +++ b/Source/Editor/Surface/VisjectSurface.ContextMenu.cs @@ -410,8 +410,11 @@ namespace FlaxEditor.Surface } menu.AddSeparator(); - _cmFormatNodesMenu = menu.AddChildMenu("Format node(s)"); - _cmFormatNodesMenu.Enabled = CanEdit && HasNodesSelection; + bool allNodesNoMove = SelectedNodes.All(n => n.Archetype.Flags.HasFlag(NodeFlags.NoMove)); + bool clickedNodeNoMove = ((SelectedNodes.Count == 1 && controlUnderMouse is SurfaceNode n && n.Archetype.Flags.HasFlag(NodeFlags.NoMove))); + + _cmFormatNodesMenu = menu.AddChildMenu("Format nodes"); + _cmFormatNodesMenu.Enabled = CanEdit && HasNodesSelection && !(allNodesNoMove || clickedNodeNoMove); _cmFormatNodesConnectionButton = _cmFormatNodesMenu.ContextMenu.AddButton("Auto format", Editor.Instance.Options.Options.Input.NodesAutoFormat, () => { FormatGraph(SelectedNodes); }); _cmFormatNodesConnectionButton = _cmFormatNodesMenu.ContextMenu.AddButton("Straighten connections", Editor.Instance.Options.Options.Input.NodesStraightenConnections, () => { StraightenGraphConnections(SelectedNodes); }); diff --git a/Source/Editor/Surface/VisjectSurface.Formatting.cs b/Source/Editor/Surface/VisjectSurface.Formatting.cs index e1b9a6777..e55a4eb8a 100644 --- a/Source/Editor/Surface/VisjectSurface.Formatting.cs +++ b/Source/Editor/Surface/VisjectSurface.Formatting.cs @@ -39,6 +39,8 @@ namespace FlaxEditor.Surface if (nodes.Count <= 1) return; + List undoActions = new List(); + var nodesToVisit = new HashSet(nodes); // While we haven't formatted every node @@ -73,18 +75,23 @@ namespace FlaxEditor.Surface } } - FormatConnectedGraph(connectedNodes); + undoActions.AddRange(FormatConnectedGraph(connectedNodes)); } + + Undo?.AddAction(new MultiUndoAction(undoActions, "Format nodes")); + MarkAsEdited(false); } /// /// Formats a graph where all nodes are connected. /// /// List of connected nodes. - protected void FormatConnectedGraph(List nodes) + private List FormatConnectedGraph(List nodes) { + List undoActions = new List(); + if (nodes.Count <= 1) - return; + return undoActions; var boundingBox = GetNodesBounds(nodes); @@ -140,7 +147,6 @@ namespace FlaxEditor.Surface } // Set the node positions - var undoActions = new List(); var topRightPosition = endNodes[0].Location; for (int i = 0; i < nodes.Count; i++) { @@ -155,16 +161,18 @@ namespace FlaxEditor.Surface } } - MarkAsEdited(false); - Undo?.AddAction(new MultiUndoAction(undoActions, "Format nodes")); + return undoActions; } /// /// Straightens every connection between nodes in . /// /// List of nodes. + /// List of undo actions. public void StraightenGraphConnections(List nodes) - { + { + nodes = nodes.Where(n => !n.Archetype.Flags.HasFlag(NodeFlags.NoMove)).ToList(); + if (nodes.Count <= 1) return; @@ -350,8 +358,10 @@ namespace FlaxEditor.Surface /// List of nodes. /// Alignemnt type. public void AlignNodes(List nodes, NodeAlignmentType alignmentType) - { - if(nodes.Count <= 1) + { + nodes = nodes.Where(n => !n.Archetype.Flags.HasFlag(NodeFlags.NoMove)).ToList(); + + if (nodes.Count <= 1) return; var undoActions = new List(); @@ -392,6 +402,8 @@ namespace FlaxEditor.Surface /// If false will be done horizontally, if true will be done vertically. public void DistributeNodes(List nodes, bool vertically) { + nodes = nodes.Where(n => !n.Archetype.Flags.HasFlag(NodeFlags.NoMove)).ToList(); + if(nodes.Count <= 1) return;