示例#1
0
        internal void RecordAndDeleteModels(List <ModelBase> models)
        {
            if (!ShouldProceedWithRecording(models))
            {
                return; // There's nothing for deletion.
            }
            // Gather a list of connectors first before the nodes they connect
            // to are deleted. We will have to delete the connectors first
            // before

            this.undoRecorder.BeginActionGroup(); // Start a new action group.

            foreach (ModelBase model in models)
            {
                if (model is NoteModel)
                {
                    // Take a snapshot of the note before it goes away.
                    this.undoRecorder.RecordDeletionForUndo(model);
                    this.Notes.Remove(model as NoteModel);
                }
                else if (model is NodeModel)
                {
                    // Just to make sure we don't end up deleting nodes from
                    // another workspace (potentially two issues: the node was
                    // having its "Workspace" pointing to another workspace,
                    // or the selection set was not quite set up properly.
                    //
                    NodeModel node = model as NodeModel;
                    System.Diagnostics.Debug.Assert(this == node.WorkSpace);

                    foreach (var conn in node.AllConnectors().ToList())
                    {
                        conn.NotifyConnectedPortsOfDeletion();
                        this.Connectors.Remove(conn);
                        this.undoRecorder.RecordDeletionForUndo(conn);
                    }

                    // Take a snapshot of the node before it goes away.
                    this.undoRecorder.RecordDeletionForUndo(model);

                    node.DisableReporting();
                    node.Destroy();
                    node.Cleanup();
                    node.WorkSpace.Nodes.Remove(node);
                }
                else if (model is ConnectorModel)
                {
                    ConnectorModel connector = model as ConnectorModel;
                    this.Connectors.Remove(connector);
                    this.undoRecorder.RecordDeletionForUndo(model);
                }
            }

            this.undoRecorder.EndActionGroup(); // Conclude the deletion.
        }