private void AddNewQuest_FormClosing(AddNewQuest form, Box shape)
        {
            if (form.Accepted)
            {
                Command command = null;
                var     quest   = Quest.Default;
                quest.Name       = form.QuestName;
                quest.SectorName = form.Sector.Name;

                var addQuestCommand = CommandsCreation.AddQuest(quest, form.Sector, Context, DiagramWrapper, shape);
                if (form.ActivateByDefault)
                {
                    var c = new CompositeCommand();
                    c.AddCommand(addQuestCommand);
                    c.AddCommand(CommandsCreation.ActivateQuest(quest, form.Sector, Context, DiagramWrapper));
                    command = c;
                }
                else
                {
                    command = addQuestCommand;
                }
                Context.History.Do(command);

                shape.SetCaptionText(0, quest.Name);
            }
            else
            {
                DiagramWrapper.RemoveNodeShape(shape);
            }
        }
Example #2
0
        private void PushUndoStack()
        {
            // Undo/Redo
            ISupportUndo    pageVMUndo  = designerCanvas.DataContext as ISupportUndo;
            IGroupOperation pageVMGroup = designerCanvas.DataContext as IGroupOperation;

            if (pageVMUndo == null)
            {
                return;
            }

            CompositeCommand cmds = new CompositeCommand();

            IPagePropertyData Page = designerCanvas.DataContext as IPagePropertyData;
            bool bHasGroup         = Page.GetSelectedwidgets().Any(a => a.IsGroup);

            // Create undoable command for widgets
            foreach (WidgetViewModBase item in _infoItems)
            {
                item.PropertyMementos.SetPropertyNewValue("Left", item.Raw_Left);
                item.PropertyMementos.SetPropertyNewValue("Top", item.Raw_Top);

                if (item.WidgetType == WidgetType.Toast && item.Top != 0)
                {
                    item.PropertyMementos.SetPropertyNewValue("DisplayPosition", ToastDisplayPosition.UserSetting);
                }

                PropertyChangeCommand cmd = new PropertyChangeCommand(item, item.PropertyMementos);
                cmds.AddCommand(cmd);
            }

            // Create undoable command for groups
            if (pageVMGroup != null)
            {
                List <Guid> groupGuids = _groups.Select(x => x.WidgetID).ToList();

                if (designerItem.ParentID != Guid.Empty)
                {
                    groupGuids.Add(designerItem.ParentID);
                }

                if (groupGuids.Count > 0)
                {
                    UpdateGroupCommand cmd = new UpdateGroupCommand(pageVMGroup, groupGuids);
                    cmds.AddCommand(cmd);
                }
            }

            // Push to undo stack
            if (cmds.Count > 0)
            {
                List <IWidgetPropertyData> allSelects = _selectionService.GetSelectedWidgets();
                cmds.AddCommand(new SelectCommand(pageVMGroup, allSelects));

                cmds.DeselectAllWidgetsFirst();
                pageVMUndo.UndoManager.Push(cmds);
            }
        }
Example #3
0
        private void SetGroupTargetObjectContinue(List <WidgetViewModBase> targetWidgets, CompositeCommand cmds, GroupViewModel NewGroupVM)
        {
            if (targetWidgets.Count < 1)
            {
                return;
            }

            int maxZOrder = targetWidgets.Max(a => a.ZOrder);
            int minZOrder = targetWidgets.Min(a => a.ZOrder);

            if (targetWidgets.Count() < (maxZOrder - minZOrder + 1))
            {
                targetWidgets.Sort(delegate(WidgetViewModBase a1, WidgetViewModBase a2)
                {
                    if (a1.ZOrder == a2.ZOrder)
                    {
                        return(0);
                    }
                    return((a1.ZOrder < a2.ZOrder) ? 1 : -1);
                });

                int maxZ = maxZOrder;
                foreach (WidgetViewModBase item in targetWidgets)
                {
                    //Undo command
                    if (cmds != null)
                    {
                        PropertyChangeCommand cmd = new PropertyChangeCommand(item, "ZOrder", item.ZOrder, maxZ);
                        cmds.AddCommand(cmd);
                    }
                    item.ZOrder = maxZ--;
                }

                List <WidgetViewModBase> widgets = items.OfType <WidgetViewModBase>().Where(a => a.ZOrder > minZOrder && a.ZOrder < maxZOrder && !(NewGroupVM.IsChild(a.widgetGID, false))).ToList <WidgetViewModBase>();
                widgets.Sort(delegate(WidgetViewModBase a1, WidgetViewModBase a2)
                {
                    if (a1.ZOrder == a2.ZOrder)
                    {
                        return(0);
                    }
                    return((a1.ZOrder > a2.ZOrder) ? 1 : -1);
                });

                int minZ = minZOrder;
                foreach (WidgetViewModBase item in widgets)
                {
                    //Undo command
                    if (cmds != null)
                    {
                        PropertyChangeCommand cmd = new PropertyChangeCommand(item, "ZOrder", item.ZOrder, minZ);
                        cmds.AddCommand(cmd);
                    }
                    item.ZOrder = minZ++;
                }
            }
        }
        private CompositeCommand CreateRemoveShapeCommand(RadDiagramShapeBase shape)
        {
            if (shape == null)
            {
                return(null);
            }
            var compositeRemoveShapeCommand = new CompositeCommand(CommandNames.RemoveShapes);
            var removeCommand = new UndoableDelegateCommand(CommandNames.RemoveShape, s => this.Diagram.RemoveShape(shape), s => this.Diagram.AddShape(shape));

            var parentContainer = shape.ParentContainer;

            if (parentContainer != null)
            {
                var execute = new Action <object>((o) => parentContainer.RemoveItem(shape));
                var undo    = new Action <object>((o) =>
                {
                    if (!parentContainer.Items.Contains(shape))
                    {
                        parentContainer.AddItem(shape);
                    }
                });
                compositeRemoveShapeCommand.AddCommand(new UndoableDelegateCommand(CommandNames.RemoveItemFromContainer, execute, undo));
            }

            foreach (var changeSourceCommand in shape.OutgoingLinks.Union(shape.IncomingLinks).ToList().Select(connection => this.CreateRemoveConnectionCommand(connection)))
            {
                compositeRemoveShapeCommand.AddCommand(changeSourceCommand);
            }

            compositeRemoveShapeCommand.AddCommand(removeCommand);

            var container = shape as RadDiagramContainerShape;

            if (container != null)
            {
                for (int i = container.Items.Count - 1; i >= 0; i--)
                {
                    var shapeToRemove = container.Items[i] as RadDiagramShapeBase;
                    if (shapeToRemove != null)
                    {
                        compositeRemoveShapeCommand.AddCommand(this.CreateRemoveShapeCommand(shapeToRemove));
                    }
                    else
                    {
                        var connection = container.Items[i] as IConnection;
                        if (connection != null && connection.Source == null && connection.Target == null)
                        {
                            compositeRemoveShapeCommand.AddCommand(this.CreateRemoveConnectionCommand(container.Items[i] as IConnection));
                        }
                    }
                }
            }

            return(compositeRemoveShapeCommand);
        }
Example #5
0
        public CompositeCommand ParseCommandList(params string[] terminators)
        {
            CompositeCommand commands = new CompositeCommand();

            Token token = this.lexer.NextToken();

            while (token != null && !terminators.Contains(token.Value))
            {
                this.lexer.PushToken(token);
                ICommand command = this.ParseCommand();

                if (command != null)
                {
                    commands.AddCommand(command);
                }

                token = this.lexer.NextToken();
            }

            if (token != null)
            {
                this.lexer.PushToken(token);
            }

            return(commands);
        }
Example #6
0
    // Use this for initialization
    void Start()
    {
        t         = new EnterFrameTimer(200);
        t.OnTimer = onTimer;
        t.Start();

        ConsoleCommand   command;
        CompositeCommand cc = new CompositeCommand(CompositeCommandMode.SEQUENCE);

        cc.OnCommandItemComplete = delegate(AbstractCommand _command) {
            Debug.Log("Item Complete" + " " + (_command as ConsoleCommand).index.ToString());
        };
        cc.OnCommandComplete = delegate(AbstractCommand _command) {
            Debug.Log("All Complete");
        };
        int max = 10;

        for (int i = 0; i < max; i++)
        {
            command       = new ConsoleCommand();
            command.index = i;
            cc.AddCommand(command);
        }

        cc.Execute();
    }
Example #7
0
        internal CompositeCommand Build(JsonCompositeCommandConfiguration commandConfiguration)
        {
            if (commandConfiguration == null)
            {
                throw new System.ArgumentNullException(nameof(commandConfiguration));
            }

            commandConfiguration.Validate();

            var command = new CompositeCommand(commandConfiguration.CommandName,
                                               GetExpectedParameters(commandConfiguration), commandConfiguration.ExpectedInputFilesInfo);

            foreach (var childCommand in commandConfiguration.ChildCommands)
            {
                var helper = new Helper(commandConfiguration, childCommand);
                command.AddCommand(childCommand.StepName,
                                   new ChildCommandConfiguration()
                {
                    StepName           = childCommand.StepName,
                    StepNumber         = childCommand.StepNumber,
                    Command            = _commandFactory.GetCommand(childCommand.CommandName),
                    FileInputProvider  = helper,
                    InputParamProvider = helper,
                    OutputPath         = childCommand.OutputPath,
                });
            }
            return(command);
        }
Example #8
0
        private ICommand ParseFunctionCommand()
        {
            string        name           = this.ParseName();
            List <string> parameterNames = this.ParseParameterNameList();

            this.ParseEndOfLine();

            CompositeCommand command = this.ParseCommandList("return");

            this.lexer.NextToken();

            Token token = this.lexer.NextToken();

            if (token != null)
            {
                this.lexer.PushToken(token);

                if (token.TokenType != TokenType.EndOfLine)
                {
                    command.AddCommand(new ReturnCommand(this.ParseExpression()));
                }
            }

            ProcedureCommand procedureCommand = new ProcedureCommand(name, parameterNames, command);

            return(procedureCommand);
        }
        protected override void OnDeleteCommandExecutedOverride(object sender, ExecutedRoutedEventArgs e)
        {
            var compositeRemoveCommand = new CompositeCommand("Remove Connections");
            foreach (var item in this.SelectedItems)
            {
                var container = this.ContainerGenerator.ContainerFromItem(item) as IShape;
                if (container != null)
                {
                    foreach (var connection in this.GetConnectionsForShape(container).ToList())
                    {
                        compositeRemoveCommand.AddCommand(new UndoableDelegateCommand("Remove Connection",
                                                                 new Action<object>((o) => this.RemoveConnection(connection)),
                                                                 new Action<object>((o) => this.AddConnection(connection))));
                    }
                }
            }

            base.OnDeleteCommandExecutedOverride(sender, e);

            if (compositeRemoveCommand.Commands.Count() > 0)
            {
                compositeRemoveCommand.Execute();
                ((this.UndoRedoService.UndoStack.FirstOrDefault() as CompositeCommand).Commands as IList<Telerik.Windows.Diagrams.Core.ICommand>).Add(compositeRemoveCommand);
            }
        }
Example #10
0
        /// <summary>
        /// 根据命令名称获取命令对象
        /// </summary>
        /// <param name="cmd">命令名称</param>
        /// <returns>命令对象</returns>
        public static ICommand GetCommand(string cmd)
        {
            ICommand command = AppCtx.Cache.RetrieveObject <ICommand>(GetCommandKey(cmd));

            if (command == null)
            {
                command = Utils.CreateInstance <ICommand>(ModelConfig.Commands[cmd]);
                if (command == null)
                {
                    throw new SysException("CmdFactory::[" + ModelConfig.Commands[cmd] + "]当前命令不存在!");
                }
                if (command is CompositeCommand)
                {
                    CompositeCommand compCmd = command as CompositeCommand;
                    foreach (NameValue nv in ModelConfig.Commands.Get(cmd).Params)
                    {
                        ICommand subCmd = Utils.CreateInstance <ICommand>(nv.Value);
                        if (subCmd == null)
                        {
                            throw new SysException("CmdFactory::[" + nv.Value + "]当前命令不存在!");
                        }
                        compCmd.AddCommand(subCmd);
                    }
                }
                AppCtx.Cache.AddObjectWithFileChange(GetCommandKey(cmd), command, ModelConfig.ConfigFilePath);
            }
            return(command);
        }
Example #11
0
        protected override void OnThumbDragCompleted(DragCompletedEventArgs e)
        {
            base.OnThumbDragCompleted(e);
            if (_initialCornerRadius == Value)
            {
                return;
            }

            CompositeCommand cmds = new CompositeCommand();

            // Create undoable command for widgets
            foreach (RoundedRecWidgetViewModel item in _infoItems)
            {
                item.PropertyMementos.SetPropertyNewValue("CornerRadius", item.CornerRadius);
                PropertyChangeCommand cmd = new PropertyChangeCommand(item, item.PropertyMementos);
                cmds.AddCommand(cmd);
            }

            // Push to undo stack
            if (cmds.Count > 0)
            {
                DesignerCanvas designerCanvas = VisualTreeHelper.GetParent(VisualTreeHelper.GetParent(VisualTreeHelper.GetParent(this.designerItem))) as DesignerCanvas;
                ISupportUndo   pageVMUndo     = designerCanvas.DataContext as ISupportUndo;
                pageVMUndo.UndoManager.Push(cmds);
            }
        }
Example #12
0
        public void ExecuteCompositeCommand()
        {
            SimpleAssignmentCommand command1 = new SimpleAssignmentCommand("foo", new ConstantExpression("bar"));
            SimpleAssignmentCommand command2 = new SimpleAssignmentCommand("one", new ConstantExpression(1));

            CompositeCommand command = new CompositeCommand();

            command.AddCommand(command1);
            command.AddCommand(command2);

            Machine machine = new Machine();

            command.Execute(machine, machine.Environment);

            Assert.AreEqual("bar", machine.Environment.GetValue("foo"));
            Assert.AreEqual(1, machine.Environment.GetValue("one"));
        }
        public void ExecuteFunctionWithPrint()
        {
            IList <Parameter> parameters = new Parameter[] { new Parameter("a", null, false), new Parameter("b", null, false) };
            CompositeCommand  body       = new CompositeCommand();

            body.AddCommand(new ExpressionCommand(new CallExpression(new NameExpression("print"), new IExpression[] { new NameExpression("a") })));
            body.AddCommand(new ExpressionCommand(new CallExpression(new NameExpression("print"), new IExpression[] { new NameExpression("b") })));

            Machine      machine = new Machine();
            StringWriter writer  = new StringWriter();

            machine.Output = writer;

            DefinedFunction func = new DefinedFunction("foo", parameters, body, machine.Environment);

            func.Apply(machine.Environment, new object[] { 1, 2 }, null);
            Assert.AreEqual("1\r\n2\r\n", writer.ToString());
        }
        private UndoableDelegateCommand CreateRemoveConnectionCommand(IConnection connection)
        {
            var compositeRemoveConnectionCommand = new CompositeCommand(CommandNames.RemoveConnections);

            UndoableDelegateCommand removeCommand = new UndoableDelegateCommand(CommandNames.RemoveConnection, s => this.Diagram.RemoveConnection(connection), s => this.Diagram.AddConnection(connection));

            compositeRemoveConnectionCommand.AddCommand(removeCommand);

            return(compositeRemoveConnectionCommand);
        }
		private void DeleteShape(IShape shape)
		{
			var compositeRemoveShapeCommand = new CompositeCommand(CommandNames.RemoveShapes);
			var observableGraphSource = this.GraphSource as IObservableGraphSource;
			if (observableGraphSource != null)
			{
				foreach (var connection in this.GetConnectionsForShape(shape))
				{
					compositeRemoveShapeCommand.AddCommand(this.CreateRemoveConnectionCommand(connection, observableGraphSource));
					if (!shape.Equals(connection.Target))
					{
						compositeRemoveShapeCommand.AddCommand(this.CreateRemoveShapeCommand(connection.Target, observableGraphSource));
					}
				}

				compositeRemoveShapeCommand.AddCommand(this.CreateRemoveShapeCommand(shape, observableGraphSource));

				this.UndoRedoService.ExecuteCommand(compositeRemoveShapeCommand);
			}
		}
Example #16
0
        public void ExecuteCompositeCommandWithReturn()
        {
            SetCommand    command1 = new SetCommand("foo", new ConstantExpression("bar"));
            ReturnCommand command2 = new ReturnCommand(new ConstantExpression("spam"));
            SetCommand    command3 = new SetCommand("one", new ConstantExpression(1));

            CompositeCommand command = new CompositeCommand();

            command.AddCommand(command1);
            command.AddCommand(command2);
            command.AddCommand(command3);

            Machine            machine     = new Machine();
            BindingEnvironment environment = new BindingEnvironment(machine.Environment);

            command.Execute(environment);

            Assert.AreEqual("bar", environment.GetValue("foo"));
            Assert.IsNull(environment.GetValue("one"));
            Assert.IsTrue(environment.HasReturnValue());
            Assert.AreEqual("spam", environment.GetReturnValue());
            Assert.IsNotNull(command.Commands);
        }
Example #17
0
        public void PrintHelloWorldUsingCompositeCommand()
        {
            ICommand         firstCommand  = new PrintCommand(new ConstantExpression("Hello "));
            ICommand         secondCommand = new PrintLineCommand(new ConstantExpression("World"));
            CompositeCommand command       = new CompositeCommand();

            command.AddCommand(firstCommand);
            command.AddCommand(secondCommand);

            StringWriter writer = new StringWriter();

            lock (System.Console.Out)
            {
                TextWriter originalWriter = System.Console.Out;
                System.Console.SetOut(writer);

                command.Execute(null, null);

                System.Console.SetOut(originalWriter);
            }

            Assert.AreEqual("Hello World\r\n", writer.ToString());
        }
        private void RemoveRowModel(RowModel rowModel, CompositeCommand command)
        {
            var container = this.tlrDiagram.ContainerGenerator.ContainerFromItem(rowModel) as IShape;

            if (container == null)
            {
                return;
            }

            foreach (var connection in this.tlrDiagram.GetConnectionsForShape(container).ToList())
            {
                var link = this.tlrDiagram.ContainerGenerator.ItemFromContainer(connection) as LinkViewModelBase <NodeViewModelBase>;
                command.AddCommand(new UndoableDelegateCommand(
                                       "Remove link",
                                       new Action <object>((o) => (this.tlrDiagram.GraphSource as TablesGraphSource).RemoveLink(link)),
                                       new Action <object>((o) => (this.tlrDiagram.GraphSource as TablesGraphSource).AddLink(link))));
            }
        }
        public void ExecuteFunctionWithReturn()
        {
            IList <Parameter> parameters = new Parameter[] { new Parameter("a", null, false), new Parameter("b", null, false) };
            CompositeCommand  body       = new CompositeCommand();

            body.AddCommand(new ReturnCommand(new BinaryOperatorExpression(new NameExpression("a"), new NameExpression("b"), BinaryOperator.Add)));

            Machine      machine = new Machine();
            StringWriter writer  = new StringWriter();

            machine.Output = writer;

            DefinedFunction func = new DefinedFunction("foo", parameters, body, null);

            var result = func.Apply(machine.Environment, new object[] { 1, 2 }, null);

            Assert.IsNotNull(result);
            Assert.AreEqual(3, result);
        }
Example #20
0
	// Use this for initialization
	void Start(){
		t = new EnterFrameTimer(200);
		t.OnTimer = onTimer;
		t.Start();

		ConsoleCommand command;
		CompositeCommand cc = new CompositeCommand(CompositeCommandMode.SEQUENCE);
		cc.OnCommandItemComplete = delegate(AbstractCommand _command) {
			Debug.Log("Item Complete" + " " + (_command as ConsoleCommand).index.ToString());
		};
		cc.OnCommandComplete = delegate(AbstractCommand _command) {
			Debug.Log("All Complete");
		};
		int max = 10;
		for (int i = 0; i < max; i++) {
			command = new ConsoleCommand();
			command.index = i;
			cc.AddCommand(command);
		}

		cc.Execute();

	}
		internal void CommitItemFontColor(Brush oldFontColor, Brush newFontColor)
		{
			if (this.owner == null)
			{
				return;
			}

			var compositeCommand = new CompositeCommand("Change Items Font Color");

			foreach (var item in this.SelectedItems)
			{
				var ensureDifferentItem = item;
				var command = new UndoableDelegateCommand("Change Item Font Color",
					p =>
						{
							if (newFontColor != null)
							{
								ensureDifferentItem.Foreground = newFontColor;
							}
						},
					p =>
						{
							if (oldFontColor != null)
							{
								ensureDifferentItem.Foreground = oldFontColor;
							}
						});
				compositeCommand.AddCommand(command);
			}

			this.owner.UndoRedoService.ExecuteCommand(compositeCommand);
		}
		internal void CommitItemFontSize(double? oldFontSize, double? newFontSize)
		{
			if (this.owner == null)
			{
				return;
			}

			var compositeCommand = new CompositeCommand("Change Items Font Size");

			foreach (var item in this.SelectedItems)
			{
				var ensureDifferentItem = item;
				var command = new UndoableDelegateCommand("Change Item Font Size",
					p =>
						{
							if (newFontSize.HasValue)
							{
								ensureDifferentItem.FontSize = newFontSize.Value;
							}
						},
					p =>
						{
							if (oldFontSize.HasValue)
							{
								ensureDifferentItem.FontSize = oldFontSize.Value;
							}
						});
				compositeCommand.AddCommand(command);
			}

			this.owner.UndoRedoService.ExecuteCommand(compositeCommand);
		}
		internal void CommitItemFontFamily(FontFamily oldFontFamily, FontFamily newFontFamily)
		{
			if (this.owner == null)
			{
				return;
			}

			var compositeCommand = new CompositeCommand("Change Items Font Family");

			foreach (var item in this.SelectedItems)
			{
				var ensureDifferentItem = item;
				var command = new UndoableDelegateCommand("Change Item Font Family",
					p => ensureDifferentItem.FontFamily = newFontFamily,
					p => ensureDifferentItem.FontFamily = oldFontFamily);
				compositeCommand.AddCommand(command);
			}

			this.owner.UndoRedoService.ExecuteCommand(compositeCommand);
		}
		internal void CommitItemLabel(string oldLabel, string newLabel)
		{
			if (this.owner == null)
			{
				return;
			}

			var compositeCommand = new CompositeCommand("Change Items Content");

			foreach (var item in this.SelectedItems)
			{
				var ensureDifferentItem = item;
				var command = new UndoableDelegateCommand("Change Item Content",
					p => ensureDifferentItem.Content = newLabel,
					p => ensureDifferentItem.Content = oldLabel);
				compositeCommand.AddCommand(command);
			}

			this.owner.UndoRedoService.ExecuteCommand(compositeCommand);
		}
		internal void CommitItemColorStyle(ColorStyle oldColorStyle, ColorStyle newColorStyle)
		{
			if (this.owner == null)
			{
				return;
			}

			var compositeCommand = new CompositeCommand("Change Items Color Style");

			foreach (var item in this.SelectedItems)
			{
				var ensureDifferentItem = item;
				var command = new UndoableDelegateCommand("Change Item Color Style",
					p =>
						{
							if (newColorStyle != null)
							{
								ensureDifferentItem.Background = newColorStyle.Fill;
								ensureDifferentItem.BorderBrush = newColorStyle.Stroke;
								ensureDifferentItem.Stroke = newColorStyle.Stroke;
							}
						},
					p =>
						{
							if (oldColorStyle != null)
							{
								ensureDifferentItem.Background = oldColorStyle.Fill;
								ensureDifferentItem.BorderBrush = oldColorStyle.Stroke;
								ensureDifferentItem.Stroke = oldColorStyle.Stroke;
							}
						});
				compositeCommand.AddCommand(command);
			}

			this.owner.UndoRedoService.ExecuteCommand(compositeCommand);
		}
        private void RemoveRowModel(RowModel rowModel, CompositeCommand command)
        {
            var container = this.diagram.ContainerGenerator.ContainerFromItem(rowModel) as IShape;
            if (container == null) return;

            foreach (var connection in this.diagram.GetConnectionsForShape(container).ToList())
            {
                var link = this.diagram.ContainerGenerator.ItemFromContainer(connection) as LinkViewModelBase<NodeViewModelBase>;
                command.AddCommand(new UndoableDelegateCommand(
                    "Remove link",
                    new Action<object>((o) => this.dc.RemoveLink(link)),
                    new Action<object>((o) => this.dc.AddLink(link))));
            }
        }
		internal void CommitConnectionTargetCapType(CapType? oldTargetCapType, CapType? newTargetCapType)
		{
			if (this.owner == null)
			{
				return;
			}

			var compositeCommand = new CompositeCommand("Change Connections Target Cap Type");

			foreach (var conn in this.SelectedConnections)
			{
				var ensureDifferentConnection = conn;
				var command = new UndoableDelegateCommand("Change Connection Target Cap Type",
					p => ensureDifferentConnection.TargetCapType = newTargetCapType.HasValue ? newTargetCapType.Value : CapType.None,
					p => ensureDifferentConnection.TargetCapType = oldTargetCapType.HasValue ? oldTargetCapType.Value : CapType.None);
				compositeCommand.AddCommand(command);
			}

			this.owner.UndoRedoService.ExecuteCommand(compositeCommand);
		}
        private CompositeCommand CreateRemoveShapeCommand(RadDiagramShapeBase shape)
        {
            if (shape == null) return null;
            var compositeRemoveShapeCommand = new CompositeCommand(CommandNames.RemoveShapes);
            var removeCommand = new UndoableDelegateCommand(CommandNames.RemoveShape, s => this.Diagram.RemoveShape(shape), s => this.Diagram.AddShape(shape));

            var parentContainer = shape.ParentContainer;
            if (parentContainer != null)
            {
                var execute = new Action<object>((o) => parentContainer.RemoveItem(shape));
                var undo = new Action<object>((o) =>
                {
                    if (!parentContainer.Items.Contains(shape))
                        parentContainer.AddItem(shape);
                });
                compositeRemoveShapeCommand.AddCommand(new UndoableDelegateCommand(CommandNames.RemoveItemFromContainer, execute, undo));
            }

            foreach (var changeSourceCommand in shape.OutgoingLinks.Union(shape.IncomingLinks).ToList().Select(connection => this.CreateRemoveConnectionCommand(connection)))
            {
                compositeRemoveShapeCommand.AddCommand(changeSourceCommand);
            }

            compositeRemoveShapeCommand.AddCommand(removeCommand);

            var container = shape as RadDiagramContainerShape;
            if (container != null)
            {
                for (int i = container.Items.Count - 1; i >= 0; i--)
                {
                    var shapeToRemove = container.Items[i] as RadDiagramShapeBase;
                    if (shapeToRemove != null)
                        compositeRemoveShapeCommand.AddCommand(this.CreateRemoveShapeCommand(shapeToRemove));
                    else
                    {
                        var connection = container.Items[i] as IConnection;
                        if (connection != null && connection.Source == null && connection.Target == null)
                            compositeRemoveShapeCommand.AddCommand(this.CreateRemoveConnectionCommand(container.Items[i] as IConnection));
                    }
                }
            }

            return compositeRemoveShapeCommand;
        }
        public override void OnShapesInserted(List <Shape> affectedShapes)
        {
            base.OnShapesInserted(affectedShapes);

            if (affectedShapes.Count == 1 && affectedShapes.First() is Polyline)
            {
                var p   = affectedShapes.First() as Polyline;
                var cps = p.GetControlPointIds(ControlPointCapabilities.All);
                var p1  = p.GetControlPointPosition(cps.First());
                var p2  = p.GetControlPointPosition(cps.Last());

                Box b1 = null;
                Box b2 = null;

                foreach (var s in p.Diagram.Shapes.Except(p))
                {
                    if (b1 == null && s.ContainsPoint(p1.X, p1.Y))
                    {
                        b1 = s as Box;
                    }
                    else if (b2 == null && s.ContainsPoint(p2.X, p2.Y))
                    {
                        b2 = s as Box;
                    }
                }

                if (b1 != null && b2 != null && b1 != b2)
                {
                    var n1 = DiagramWrapper.GetNodeForShape(b1);
                    var n2 = DiagramWrapper.GetNodeForShape(b2);

                    if (!n2.Quest.IsLinksToEditable())
                    {
                        DeleteShapeOnDeselect(p);
                        var msg = $"Couldn't create link to {n2.Quest.Name} quest - links to this quest are editable only through code.";
                        MessageBox.Show(msg);
                        return;
                    }

                    var link = new Link(n1, n2);

                    if (Context.Flow.Graph.ExistsLink(link))
                    {
                        DeleteShapeOnDeselect(p);
                        var msg = $"Couldn't create link from {n1.Quest.Name} to {n2.Quest.Name} quest - link already exists.";
                        MessageBox.Show(msg);
                        return;
                    }

                    (var loopForms, var loop) = GraphValidation.LoopForms(Context.Flow.Graph, link);
                    if (loopForms)
                    {
                        DeleteShapeOnDeselect(p);
                        var loopStringRepresentation = string.Join(" - ", loop.Select(q => q.Quest.Name));
                        var msg = $"Couldn't create link from {n1.Quest.Name} to {n2.Quest.Name} quest - loop forms: {loopStringRepresentation}.";
                        MessageBox.Show(msg);
                        return;
                    }

                    DiagramWrapper.RegisterShapeForLink(p, link);

                    if (!n1.Quest.IsActive() || !n2.Quest.IsActive())
                    {
                        var command = new CompositeCommand();

                        void InitQuestActivationCommand(Quest quest) =>
                        command.AddCommand(
                            CommandsCreation.ActivateQuest(
                                quest,
                                Context.Flow.GetSectorForQuest(quest),
                                Context,
                                DiagramWrapper
                                )
                            );

                        if (!n1.Quest.IsActive())
                        {
                            InitQuestActivationCommand(n1.Quest);
                        }
                        if (!n2.Quest.IsActive())
                        {
                            InitQuestActivationCommand(n2.Quest);
                        }
                        command.AddCommand(CommandsCreation.AddLink(link, Context, DiagramWrapper));

                        Context.History.Do(command);
                    }
                    else
                    {
                        Context.History.Do(CommandsCreation.AddLink(link, Context, DiagramWrapper));
                    }
                }
                else
                {
                    DeleteShapeOnDeselect(p);
                }
            }
            else
            {
                DeleteShapesOnDeselect(affectedShapes);
            }
        }
Example #30
0
        public void WdgMgrReZOrderSelection(int tarZorder, Guid tarWdgGuid)
        {
            if (_busyIndicator.IsShow == true)
            {
                return;
            }
            // tarWdgGuid = Guid.NewGuid();
            WidgetViewModBase wdg = items.FirstOrDefault(c => c.WidgetID == tarWdgGuid);

            if (wdg == null)
            {
                return;
            }
            int orgZorder = wdg.ZOrder;
            int nOriCount = 1;

            if (wdg.IsGroup == true)
            {
                nOriCount = (wdg as GroupViewModel).WidgetChildren.Count();
            }


            CompositeCommand cmds             = new CompositeCommand();
            bool             bIsZOrderChanged = false;

            //up drag to other widgets
            List <WidgetViewModBase> allothers;
            int nOtherNum = 0;

            if (tarZorder > orgZorder)
            {
                allothers = items.Where(c => c.ZOrder <tarZorder && c.ZOrder> orgZorder && c.IsGroup == false).ToList <WidgetViewModBase>();
                foreach (WidgetViewModBase it in allothers)
                {
                    CreatePropertyChangeUndoCommand(cmds, it, "ZOrder", it.ZOrder, it.ZOrder - nOriCount);
                    it.ZOrder        = it.ZOrder - nOriCount;
                    bIsZOrderChanged = true;
                }
                nOtherNum = allothers.Count();
            }
            else if (tarZorder < orgZorder)//down drag to other widgets
            {
                allothers = items.Where(c => c.ZOrder < (orgZorder - nOriCount + 1) && c.ZOrder >= tarZorder && c.IsGroup == false).ToList <WidgetViewModBase>();
                foreach (WidgetViewModBase it in allothers)
                {
                    CreatePropertyChangeUndoCommand(cmds, it, "ZOrder", it.ZOrder, it.ZOrder + nOriCount);
                    it.ZOrder        = it.ZOrder + nOriCount;
                    bIsZOrderChanged = true;
                }
                nOtherNum = -allothers.Count();
            }


            //adjust the drag item's zorder
            if (wdg.IsGroup == true)
            {
                foreach (WidgetViewModBase it in (wdg as GroupViewModel).WidgetChildren)
                {
                    CreatePropertyChangeUndoCommand(cmds, it, "ZOrder", it.ZOrder, it.ZOrder + nOtherNum);
                    it.ZOrder        = it.ZOrder + nOtherNum;
                    bIsZOrderChanged = true;
                }
            }
            else
            {
                CreatePropertyChangeUndoCommand(cmds, wdg, "ZOrder", wdg.ZOrder, wdg.ZOrder + nOtherNum);
                wdg.ZOrder       = wdg.ZOrder + nOtherNum;
                bIsZOrderChanged = true;
            }
            _ListEventAggregator.GetEvent <ZorderChangedEvent>().Publish(null);

            //Push Command to Undo/Redo stack
            if (bIsZOrderChanged == true)
            {
                NotifyEventCommand notifyCmd = new NotifyEventCommand(CompositeEventType.ZorderChange);
                cmds.AddCommand(notifyCmd);
                PushToUndoStack(cmds);
                _ListEventAggregator.GetEvent <ZorderChangedEvent>().Publish(null);
            }

            //items.Where(c => c.IsSelected == true).ToList<WidgetViewModBase>();
            //List<WidgetViewModBase> AllChildren = ParentGroup.WidgetChildren;
            //List<WidgetViewModBase> targetWidgets = ParentGroup.WidgetChildren.Where(c => c.IsSelected == true).ToList<WidgetViewModBase>();
            //if (targetWidgets.Count() == AllChildren.Count())
            //{
            //    return;
            //}
            //targetWidgets = targetWidgets.OrderByDescending(s => s.ZOrder).ToList<WidgetViewModBase>();
            //int maxZOrder = AllChildren.Max(a => a.ZOrder);
        }
        private void AddContainer(MainContainerShapeBase container, IShape itemToAdd)
        {
            if (container == null || itemToAdd == null) return;
            CompositeCommand command = new CompositeCommand("Add new container");
            if (container.IsCollapsed)
            {
                command.AddCommand(new UndoableDelegateCommand("Update container",
                   new Action<object>((o) =>
                   {
                       container.IsCollapsed = false;
                   }),
                   new Action<object>((o) =>
                   {
                       container.IsCollapsed = true;
                   })));
            }
            command.AddCommand(new UndoableDelegateCommand("Add Container",
                  new Action<object>((o) =>
                  {
                      container.Items.Add(itemToAdd);
                      container.IsCollapsed = false;
                  }),
                  new Action<object>((o) =>
                  {
                      this.Diagram.RemoveShape(itemToAdd);
                      container.IsCollapsed = false;
                  })));

            this.Diagram.UndoRedoService.ExecuteCommand(command);
        }
		internal void CommitItemStrokeThickness(double oldStrokeThickness, double newStrokeThickness)
		{
			if (this.owner == null)
			{
				return;
			}

			var compositeCommand = new CompositeCommand("Change Items Border Thickness");

			foreach (var item in this.SelectedItems)
			{
				var ensureDifferentItem = item;
				var command = new UndoableDelegateCommand("Change Item Border Thikness",
					p => ensureDifferentItem.StrokeThickness = newStrokeThickness,
					p => ensureDifferentItem.StrokeThickness = oldStrokeThickness);
				compositeCommand.AddCommand(command);
			}

			this.owner.UndoRedoService.ExecuteCommand(compositeCommand);
		}
        private UndoableDelegateCommand CreateRemoveConnectionCommand(IConnection connection)
        {
            var compositeRemoveConnectionCommand = new CompositeCommand(CommandNames.RemoveConnections);

            UndoableDelegateCommand removeCommand = new UndoableDelegateCommand(CommandNames.RemoveConnection, s => this.Diagram.RemoveConnection(connection), s => this.Diagram.AddConnection(connection));

            compositeRemoveConnectionCommand.AddCommand(removeCommand);

            return compositeRemoveConnectionCommand;
        }
		internal void CommitItemStrokeDashArray(DoubleCollection oldStrokeDashArray, DoubleCollection newStrokeDashArray)
		{
			if (this.owner == null)
			{
				return;
			}

			var compositeCommand = new CompositeCommand("Change Items Border Dash Style");

			foreach (var item in this.SelectedItems)
			{
				var ensureDifferentItem = item;
				var command = new UndoableDelegateCommand("Change Item Border Dash Style",
					p => ensureDifferentItem.StrokeDashArray = newStrokeDashArray,
					p => ensureDifferentItem.StrokeDashArray = oldStrokeDashArray);
				compositeCommand.AddCommand(command);
			}

			this.owner.UndoRedoService.ExecuteCommand(compositeCommand);
		}
		internal void CommitShapeHeight(double newHeight)
		{
			if (this.owner == null)
			{
				return;
			}

			var compositeCommand = new CompositeCommand(CommandNames.ResizeShapes);

			foreach (var shape in this.SelectedShapes)
			{
				var ensureDifferentShape = shape;
				var ensureOldValue = ensureDifferentShape.Height;
				var command = new UndoableDelegateCommand(CommandNames.ResizeShape,
					p => ensureDifferentShape.Height = newHeight,
					p => ensureDifferentShape.Height = ensureOldValue);
				compositeCommand.AddCommand(command);
			}

			this.owner.UndoRedoService.ExecuteCommand(compositeCommand);

			this.OnBoundsChanged();
		}
Example #36
0
        private void RotateThumb_DragCompleted(object sender, DragCompletedEventArgs e)
        {
            if (_infoItems.Count <= 0)
            {
                return;
            }

            // Undo/Redo
            ISupportUndo    pageVMUndo  = canvas.DataContext as ISupportUndo;
            IGroupOperation pageVMGroup = canvas.DataContext as IGroupOperation;

            if (pageVMUndo == null)
            {
                return;
            }

            CompositeCommand cmds = new CompositeCommand();

            // Create undoable command for widgets
            foreach (WidgetViewModBase item in _infoItems)
            {
                item.PropertyMementos.SetPropertyNewValue("RotateAngle", item.RotateAngle);

                if (this.designerItem.IsGroup)
                {
                    item.PropertyMementos.SetPropertyNewValue("Left", item.Raw_Left);
                    item.PropertyMementos.SetPropertyNewValue("Top", item.Raw_Top);
                }
                PropertyChangeCommand cmd = new PropertyChangeCommand(item, item.PropertyMementos);
                cmds.AddCommand(cmd);
            }

            // Create undoable command for groups
            if (pageVMGroup != null)
            {
                List <Guid> groupGuids = new List <Guid>();

                if (designerItem.ParentID != Guid.Empty)
                {
                    groupGuids.Add(designerItem.ParentID);

                    UpdateGroupCommand cmd = new UpdateGroupCommand(pageVMGroup, groupGuids);
                    cmds.AddCommand(cmd);
                }

                if (this.designerItem.IsGroup)
                {
                    groupGuids.Add((designerItem.DataContext as GroupViewModel).WidgetID);

                    UpdateGroupCommand cmd = new UpdateGroupCommand(pageVMGroup, groupGuids);
                    cmds.AddCommand(cmd);
                }
            }

            // Push to undo stack
            if (cmds.Count > 0)
            {
                List <IWidgetPropertyData> allSelects = _selectionService.GetSelectedWidgets();
                cmds.AddCommand(new SelectCommand(pageVMGroup, allSelects));

                cmds.DeselectAllWidgetsFirst();
                pageVMUndo.UndoManager.Push(cmds);
            }
        }
		internal void CommitShapePositionY(double newPositionY)
		{
			if (this.owner == null)
			{
				return;
			}

			var compositeCommand = new CompositeCommand(CommandNames.MoveItems);

			foreach (var shape in this.SelectedShapes)
			{
				var ensureDifferentShape = shape;
				var ensureOldValue = ensureDifferentShape.Position.Y;
				var command = new UndoableDelegateCommand(CommandNames.MoveItem,
					p => ensureDifferentShape.Position = new Point(ensureDifferentShape.Position.X, newPositionY),
					p => ensureDifferentShape.Position = new Point(ensureDifferentShape.Position.X, ensureOldValue));
				compositeCommand.AddCommand(command);
			}

			this.owner.UndoRedoService.ExecuteCommand(compositeCommand);

			this.OnBoundsChanged();
		}
		internal void CommitShapeRotaionAngle(double newRotaionAngle)
		{
			if (this.owner == null)
			{
				return;
			}

			var compositeCommand = new CompositeCommand(CommandNames.RotateItems);

			foreach (var shape in this.SelectedShapes)
			{
				var ensureDifferentShape = shape;
				var ensureOldValue = ensureDifferentShape.RotationAngle;
				var command = new UndoableDelegateCommand(CommandNames.RotateItem,
					p => ensureDifferentShape.RotationAngle = newRotaionAngle,
					p => ensureDifferentShape.RotationAngle = ensureOldValue);
				compositeCommand.AddCommand(command);
			}

			this.owner.UndoRedoService.ExecuteCommand(compositeCommand);

			this.OnBoundsChanged();
		}
		private static void DetachConnections(RadDiagram diagram)
		{
			if (diagram.SelectedItems.Count() > 1)
			{
				CompositeCommand changeSourcesCompositeCommand = new CompositeCommand("Detach ends");
				foreach (var connection in diagram.SelectedItems.OfType<IConnection>())
				{
					if (!diagram.SelectedItems.Contains(connection.Source))
					{
						changeSourcesCompositeCommand.AddCommand(new ChangeSourceCommand(connection, null, connection.StartPoint));
					}

					if (!diagram.SelectedItems.Contains(connection.Target))
					{
						changeSourcesCompositeCommand.AddCommand(new ChangeTargetCommand(connection, null, connection.EndPoint));
					}
				}
				changeSourcesCompositeCommand.Execute();
				AttachedProperties.SetPendingCommand(diagram, changeSourcesCompositeCommand);
			}
		}
        private void RemoveContainer(MainContainerShapeBase container, RadDiagramShapeBase itemToRemove)
        {
            if (container == null || itemToRemove == null) return;

            CompositeCommand command = new CompositeCommand("Remove horizontal container");
            if (container.IsCollapsed)
            {
                command.AddCommand(new UndoableDelegateCommand("Update container",
                   new Action<object>((o) =>
                   {
                       container.IsCollapsed = false;
                   }),
                   new Action<object>((o) =>
                   {
                       container.IsCollapsed = true;
                   })));
            }
            command.AddCommand(this.CreateRemoveShapeCommand(itemToRemove));
            if (container.IsCollapsed)
            {
                command.AddCommand(new UndoableDelegateCommand("Update container",
                   new Action<object>((o) =>
                   {
                   }),
                   new Action<object>((o) =>
                   {
                   })));
            }

            this.Diagram.UndoRedoService.ExecuteCommand(command);
        }