From d79dd4aaf7bfd189fb0c939b47070e4d4ceeb5a4 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 6 Nov 2023 08:41:36 +0100 Subject: [PATCH] Add undo for `Convert to Parameter` connections change in #1671 --- Source/Editor/Surface/Archetypes/Constants.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Source/Editor/Surface/Archetypes/Constants.cs b/Source/Editor/Surface/Archetypes/Constants.cs index 458fd4af3..e58d917d1 100644 --- a/Source/Editor/Surface/Archetypes/Constants.cs +++ b/Source/Editor/Surface/Archetypes/Constants.cs @@ -75,6 +75,7 @@ namespace FlaxEditor.Surface.Archetypes InitValue = initValue, }; paramAction.Do(); + Surface.AddBatchedUndoAction(paramAction); // Spawn Get Parameter Node based on the added parameter Guid parameterGuid = Surface.Parameters[paramIndex].ID; @@ -85,9 +86,12 @@ namespace FlaxEditor.Surface.Archetypes Surface.Undo.Enabled = undoEnabled; if (node is not Parameters.SurfaceNodeParamsGet getNode) throw new Exception("Node is not a ParamsGet node!"); + Surface.AddBatchedUndoAction(new AddRemoveNodeAction(getNode, true)); // Recreate connections of constant node // Constant nodes and parameter nodes should have the same ports, so we can just iterate through the connections + var editConnectionsAction1 = new EditNodeConnections(Context, this); + var editConnectionsAction2 = new EditNodeConnections(Context, node); var boxes = GetBoxes(); for (int i = 0; i < boxes.Count; i++) { @@ -104,12 +108,16 @@ namespace FlaxEditor.Surface.Archetypes paramBox.CreateConnection(connectedBox); } } + editConnectionsAction1.End(); + editConnectionsAction2.End(); + Surface.AddBatchedUndoAction(editConnectionsAction1); + Surface.AddBatchedUndoAction(editConnectionsAction2); // Add undo actions and remove constant node - var spawnNodeAction = new AddRemoveNodeAction(getNode, true); var removeConstantAction = new AddRemoveNodeAction(this, false); - Surface.AddBatchedUndoAction(new MultiUndoAction(paramAction, spawnNodeAction, removeConstantAction)); + Surface.AddBatchedUndoAction(removeConstantAction); removeConstantAction.Do(); + Surface.MarkAsEdited(); } private bool OnParameterRenameValidate(string value)