Example #1
0
        public override void OnShapesDeleted(List <Shape> affectedShapes)
        {
            base.OnShapesDeleted(affectedShapes);

            var questsToDelete = affectedShapes.OfType <Box>().Select(FindQuestForShape).ToList();

            if (questsToDelete.Count > 0)
            {
                var command = new CompositeCommand();
                foreach (var q in questsToDelete)
                {
                    var links = Context.Flow.Graph.GetLinksForNode(Context.Flow.Graph.FindNodeForQuest(q));
                    command.AddCommands(links.Select(l => CommandsCreation.RemoveLink(l, Context, DiagramWrapper)));
                }
                command.AddCommands(questsToDelete.Select(
                                        q => CommandsCreation.DeactivateQuest(q, Context, DiagramWrapper)
                                        ));
                command.AddCommands(questsToDelete.Select(
                                        q => CommandsCreation.RemoveQuest(
                                            q,
                                            Context,
                                            Context.Flow.Graph.FindNodeForQuest(q),
                                            DiagramWrapper,
                                            DiagramWrapper.GetShapeForQuest(q))
                                        )
                                    );
                Context.History.Do(command);
            }
            else
            {
                var commands = affectedShapes.Select(FindLinkForShape)
                               .Where(l => l.HasValue)
                               .Select(l => CommandsCreation.RemoveLink(l.Value, Context, DiagramWrapper))
                               .ToList();
                if (commands.Count > 0)
                {
                    Context.History.Do(new CompositeCommand(commands));
                }
            }
        }