Skip to content
10 changes: 2 additions & 8 deletions src/DynamoCore/Graph/Workspaces/UndoRedo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public bool CanUndo
{
get
{
return (null != undoRecorder && undoRecorder.CanUndo) && !IsUndoRedoLocked;
return (null != undoRecorder && undoRecorder.CanUndo);
}
}

Expand All @@ -48,16 +48,10 @@ public bool CanRedo
{
get
{
return (null != undoRecorder && undoRecorder.CanRedo) && !IsUndoRedoLocked;
return (null != undoRecorder && undoRecorder.CanRedo);
}
}

internal bool IsUndoRedoLocked
{
get;
set;
}

internal void Undo()
{
if (null != undoRecorder)
Expand Down
2 changes: 1 addition & 1 deletion src/DynamoCore/Models/DynamoModelCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void ExecuteCommand(RecordableCommand command)
if (CommandCompleted != null)
CommandCompleted(command);
}

private PortModel[] activeStartPorts;
private PortModel firstStartPort;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,16 +309,8 @@ internal void ConsolidateTransientNodes()

(node.WorkspaceViewModel.Model as HomeWorkspaceModel)?.MarkNodesAsModifiedAndRequestRun(transientNodes.Select(x => x.NodeModel));

ToggleUndoRedoLocked(false);
}

internal void ToggleUndoRedoLocked(bool toggle = true)
{
var node = PortViewModel.NodeViewModel;
//unlock undo/redo
node.WorkspaceViewModel.Model.IsUndoRedoLocked = toggle;
//allow for undo/redo again
node.DynamoViewModel.RaiseCanExecuteUndoRedo();
//add the new items to the undo recorder (this ensures the elements are valid at this point in time before any other manipulation occurs)
DynamoModel.RecordUndoModels(node.WorkspaceViewModel.Model, createdClusterItems);
}

/// <summary>
Expand Down Expand Up @@ -807,13 +799,24 @@ internal void DeleteTransientNodes()
var wsViewModel = node.WorkspaceViewModel;

var transientNodes = wsViewModel.Nodes.Where(x => x.IsTransient).ToList();
var transientConnectors = wsViewModel.Connectors.Where(c => c.IsTransient).ToList();

if (transientConnectors.Any())
{
foreach (var connector in transientConnectors)
{
connector.ConnectorModel.Delete();
connector.ConnectorModel.Dispose();
wsViewModel.Connectors.Remove(connector);
}
}

if (transientNodes.Any())
{
dynamoViewModel.Model.ExecuteCommand(new DynamoModel.DeleteModelCommand(transientNodes.Select(x => x.Id), true));
//remove the deletion of the elements from the undo stack
wsViewModel.Model.UndoRecorder.PopFromUndoGroup();
//remove the layout of the elements from the undo stack
wsViewModel.Model.UndoRecorder.PopFromUndoGroup();
foreach (var transientNode in transientNodes)
{
wsViewModel.Model.RemoveAndDisposeNode(transientNode.NodeModel);
}
}
}

Expand All @@ -830,8 +833,11 @@ internal void AddCluster(int filterredIndex)
}

// Add Cluster from server result into the workspace
private List<ModelBase> createdClusterItems = new List<ModelBase>();
internal void AddCluster(ClusterResultItem clusterResultItem)
{
createdClusterItems.Clear();

if (clusterResultItem == null || clusterResultItem.Topology == null)
return;
var nextCluster = JsonConvert.SerializeObject(clusterResultItem);
Expand All @@ -841,16 +847,11 @@ internal void AddCluster(ClusterResultItem clusterResultItem)
}
lastSerializedAddedCluster = nextCluster;

List<ModelBase> createdClusterItems = new List<ModelBase>();

var workspaceViewModel = PortViewModel.NodeViewModel.WorkspaceViewModel;
var workspaceModel = workspaceViewModel.Model;
var dynamoModel = PortViewModel.NodeViewModel.DynamoViewModel.Model;
var entryNodeId = clusterResultItem.Topology.Nodes.ElementAtOrDefault(clusterResultItem.EntryNodeIndex)?.Id;

// Lock undo/redo
ToggleUndoRedoLocked(true);

// Delete any existing transient nodes
DeleteTransientNodes();

Expand All @@ -870,7 +871,7 @@ internal void AddCluster(ClusterResultItem clusterResultItem)
var typeInfo = new NodeModelTypeId(nodeItem.Type.Id);

NodeModel newNode = dynamoModel.CreateNodeFromNameOrType(Guid.NewGuid(), typeInfo.FullName, true);

if (newNode != null)
{
newNode.X = offset; // Adjust X position
Expand Down Expand Up @@ -944,9 +945,6 @@ internal void AddCluster(ClusterResultItem clusterResultItem)
}
}

//add the new items to the undo recorder (this ensures the elements are valid at this point in time before any other manipulation occurs)
DynamoModel.RecordUndoModels(workspaceModel, createdClusterItems);

// Perform auto-layout for the newly added nodes
NodeAutoCompleteUtilities.PostAutoLayoutNodes(
workspaceViewModel.DynamoViewModel.CurrentSpace,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ internal void CloseAutoComplete()
Dispatcher.BeginInvoke(new Action(() =>
{
ViewModel?.DeleteTransientNodes();
ViewModel?.ToggleUndoRedoLocked(false);
}), DispatcherPriority.Loaded);

Close();
Expand Down
Loading