private void CreateAndConnectNodeImpl(CreateAndConnectNodeCommand command) { using (CurrentWorkspace.UndoRecorder.BeginActionGroup()) { CreateAndConnectNodeImplWithUndoGroup(command); } }
/// <summary> /// This method assumes that there exists an undo-redo action group already /// that can be used to record creation and deletion of models. /// </summary> /// <param name="command"></param> private void CreateAndConnectNodeImplWithUndoGroup(CreateAndConnectNodeCommand command) { var newNode = CreateNodeFromNameOrType(command.ModelGuid, command.NewNodeName); if (newNode == null) { return; } newNode.X = command.X; newNode.Y = command.Y; var existingNode = CurrentWorkspace.GetModelInternal(command.ModelGuids.ElementAt(1)) as NodeModel; if (existingNode == null) { return; } AddNodeToCurrentWorkspace(newNode, false, command.AddNewNodeToSelection); CurrentWorkspace.UndoRecorder.RecordCreationForUndo(newNode); PortModel inPortModel, outPortModel; if (command.CreateAsDownstreamNode) { // Connect output port of Existing Node to input port of New node outPortModel = existingNode.OutPorts[command.OutputPortIndex]; inPortModel = newNode.InPorts[command.InputPortIndex]; } else { // Connect output port of New Node to input port of existing node outPortModel = newNode.OutPorts[command.OutputPortIndex]; inPortModel = existingNode.InPorts[command.InputPortIndex]; } var models = GetConnectorsToAddAndDelete(inPortModel, outPortModel); foreach (var modelPair in models) { switch (modelPair.Value) { case UndoRedoRecorder.UserAction.Creation: CurrentWorkspace.UndoRecorder.RecordCreationForUndo(modelPair.Key); break; case UndoRedoRecorder.UserAction.Deletion: CurrentWorkspace.UndoRecorder.RecordDeletionForUndo(modelPair.Key); break; } } }
void CreateAndConnectNodeImpl(CreateAndConnectNodeCommand command) { using (CurrentWorkspace.UndoRecorder.BeginActionGroup()) { var newNode = CreateNodeFromNameOrType(command.ModelGuid, command.NewNodeName); newNode.X = command.X; newNode.Y = command.Y; var existingNode = CurrentWorkspace.GetModelInternal(command.ModelGuids.ElementAt(1)) as NodeModel; if(newNode == null || existingNode == null) return; AddNodeToCurrentWorkspace(newNode, false, command.AddNewNodeToSelection); CurrentWorkspace.UndoRecorder.RecordCreationForUndo(newNode); PortModel inPortModel, outPortModel; if (command.CreateAsDownstreamNode) { // Connect output port of Existing Node to input port of New node outPortModel = existingNode.OutPorts[command.OutputPortIndex]; inPortModel = newNode.InPorts[command.InputPortIndex]; } else { // Connect output port of New Node to input port of existing node outPortModel = newNode.OutPorts[command.OutputPortIndex]; inPortModel = existingNode.InPorts[command.InputPortIndex]; } var models = GetConnectorsToAddAndDelete(inPortModel, outPortModel); foreach (var modelPair in models) { switch (modelPair.Value) { case UndoRedoRecorder.UserAction.Creation: CurrentWorkspace.UndoRecorder.RecordCreationForUndo(modelPair.Key); break; case UndoRedoRecorder.UserAction.Deletion: CurrentWorkspace.UndoRecorder.RecordDeletionForUndo(modelPair.Key); break; } } } }