Exemplo n.º 1
0
        internal void DeleteModelInternal(List<ModelBase> modelsToDelete)
        {
            if (null == CurrentWorkspace)
                return;

            //Check for empty group
            var annotations = Workspaces.SelectMany(ws => ws.Annotations);
            foreach (var annotation in annotations)
            {
                //record the annotation before the models in it are deleted.
                foreach (var model in modelsToDelete)
                {
                    //If there is only one model, then deleting that model should delete the group. In that case, do not record 
                    //the group for modification. Until we have one model in a group, group should be recorded for modification
                    //otherwise, undo operation cannot get the group back.
                    if (annotation.SelectedModels.Count() > 1 && annotation.SelectedModels.Where(x => x.GUID == model.GUID).Any())
                    {
                        CurrentWorkspace.RecordGroupModelBeforeUngroup(annotation);
                    }
                }

                if (annotation.SelectedModels.Any() && !annotation.SelectedModels.Except(modelsToDelete).Any())
                {
                    //Annotation Model has to be serialized first - before the nodes.
                    //so, store the Annotation model as first object. This will serialize the 
                    //annotation before the nodes are deleted. So, when Undo is pressed,
                    //annotation model is deserialized correctly.
                    modelsToDelete.Insert(0, annotation);                   
                }
            }

            OnDeletionStarted();

            CurrentWorkspace.RecordAndDeleteModels(modelsToDelete);

            var selection = DynamoSelection.Instance.Selection;
            foreach (ModelBase model in modelsToDelete)
            {
                selection.Remove(model); // Remove from selection set.
                model.Dispose();              
            }

            OnDeletionComplete(this, EventArgs.Empty);
        }