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
using (undoRecorder.BeginActionGroup()) // Start a new action group.
{
foreach (var model in models)
{
if (model is NoteModel)
{
// Take a snapshot of the note before it goes away.
undoRecorder.RecordDeletionForUndo(model);
RemoveNote(model as NoteModel);
}
else if (model is AnnotationModel)
{
undoRecorder.RecordDeletionForUndo(model);
RemoveAnnotation(model as AnnotationModel);
}
else if (model is PresetModel)
{
undoRecorder.RecordDeletionForUndo(model);
RemovePreset(model as PresetModel);
}
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.
//
var node = model as NodeModel;
Debug.Assert(Nodes.Contains(node));
bool silentFlag = node.RaisesModificationEvents;
node.RaisesModificationEvents = false;
// Note that AllConnectors is duplicated as a separate list
// by calling its "ToList" method. This is the because the
// "Connectors.Remove" will modify "AllConnectors", causing
// the Enumerator in this "foreach" to become invalid.
foreach (var conn in node.AllConnectors.ToList())
{
conn.Delete();
undoRecorder.RecordDeletionForUndo(conn);
}
node.RaisesModificationEvents = silentFlag;
// Take a snapshot of the node before it goes away.
undoRecorder.RecordDeletionForUndo(node);
RemoveAndDisposeNode(node);
}
else if (model is ConnectorModel)
{
undoRecorder.RecordDeletionForUndo(model);
}
}
RequestRun();
} // Conclude the deletion.
}