예제 #1
0
        private void OrnamentButton_Click(object sender, EventArgs e)
        {
            DecoratorForm decoratorForm = new DecoratorForm();
            Shape         selectedShape = shapeList.FirstOrDefault(s => s.selected);

            if (selectedShape == null)
            {
                return;
            }

            decoratorForm.ShowDialog();

            if (decoratorForm.DialogResult == DialogResult.OK)
            {
                string ornamentText = decoratorForm.Ornament;

                ShapeDecorator ornament = new ShapeDecorator(selectedShape.x + 50, selectedShape.y, 50, 50, selectedShape, ornamentText, decoratorForm.position);

                MacroCommand macroCommand = new MacroCommand();
                macroCommand.Add(new CustomCommand(
                                     () => shapeList.Remove(selectedShape),
                                     () => shapeList.Add(selectedShape)));
                macroCommand.Add(new AddShapeCommand(shapeList, ornament));

                history.Add(macroCommand);

                Invalidate();
            }
        }
예제 #2
0
        private void button1_Click(object sender, EventArgs e)//edit to data struct
        {
            if (nodeSelected == null)
            {
                return;
            }
            var macro = new MacroCommand();

            if (nodeSelected is ScalarNode)
            {
                ScalarNode tempScalar = (ScalarNode)nodeSelected;
                TreeNode   node       = searchTreeEdit(root, tempScalar.id);

                var key   = dataGridView1.Rows[0].Cells[0].EditedFormattedValue.ToString();
                var value = dataGridView1.Rows[0].Cells[1].EditedFormattedValue.ToString();
                vl = new ValueCommand(mapNode, node, tempScalar, key, this, value);
                macro.Add(vl);
                Manager.Execute(macro);
            }
            else
            {
                vl = new ValueCommand(this, dataGridView1, nodeSelected);
                macro.Add(vl);
                Manager.Execute(macro);

                RefreshAll();

                expandAllNodes(nodeSelected);
            }
        }
예제 #3
0
        public void Add_ItemsAdded()
        {
            MacroCommand macro = new MacroCommand();
            ICommand command1 = Substitute.For<ICommand>();

            macro.Add(command1);
            Assert.AreEqual(macro.Commands.Count, 1);
            Assert.AreSame(command1, macro.Commands[0]);

            ICommand command2 = Substitute.For<ICommand>();
            macro.Add(command2);
            Assert.AreEqual(macro.Commands.Count, 2);
            Assert.AreSame(command2, macro.Commands[1]);
        }
예제 #4
0
        private void btnRemove_Click(object sender, EventArgs e)//button remove
        {
            if (root == null)
            {
                return;
            }
            if (nodeSelected == null)
            {
                return;
            }
            if (nodeSelected.getID() == 0)
            {
                return;
            }
            TreeNode[] nodeTreeviewEdit = root.Nodes.Find(nodeSelected.getID().ToString(), true);
            var        macro            = new MacroCommand();

            remove = new RemoveCommand(ref mapNode, nodeSelected, ref root, nodeTreeviewEdit[0], this);
            macro.Add(remove);
            Manager.Execute(macro);



            mainTreeView.Nodes.Clear();
            mainTreeView.Nodes.Add(root);
            root.Expand();

            mainTreeView.SelectedNode = root;
        }
예제 #5
0
        private void updateButton_Click(object sender, EventArgs e)
        {
            Logger.Instance.WriteLine("updateButton_Click");
            if (selectedScalarNode == null)
            {
                return;
            }
            MacroCommand macroCommand = new MacroCommand();

            if (selectedScalarNode.name != "")
            {
                macroCommand.Add(new SetNameCommand(selectedScalarNode, nameTextBox.Text));
            }
            macroCommand.Add(new SetTagCommand(selectedScalarNode, tagTextBox.Text));
            macroCommand.Add(new SetValueCommand(selectedScalarNode, valueTextBox.Text));
            Manager.Execute(macroCommand);
        }
예제 #6
0
        protected override void Context()
        {
            var macrocommand1 = new MacroCommand <MyContext>();

            macrocommand1.Add(A.Fake <ICommand <MyContext> >());
            _command1 = macrocommand1;
            _command2 = A.Fake <ICommand>();
            _command3 = new MacroCommand <MyContext>();
        }
예제 #7
0
        private void Form1_MouseUp(object sender, MouseEventArgs e)
        {
            bool hasMoved = mouseDownLocation.X != e.X || mouseDownLocation.Y != e.Y;

            if (hasSelected)
            {
                if (hasSecondSelected)
                {
                    ShapeComposite newGroup = new ShapeComposite();
                    newGroup.AddChild(SelectedShape);
                    newGroup.AddChild(SecondSelectedShape);

                    MacroCommand macroCommandSelectedShape = new MacroCommand();
                    macroCommandSelectedShape.Add(new CustomCommand(
                                                      () =>
                    {
                        shapeList.Remove(SelectedShape);
                        shapeList.Remove(SecondSelectedShape);
                    },
                                                      () =>
                    {
                        shapeList.Add(newGroup.groupMembers[0]);
                        shapeList.Add(newGroup.groupMembers[1]);
                    }
                                                      ));

                    SecondSelectedShape.selected = false;
                    SecondSelectedShape          = null;

                    macroCommandSelectedShape.Add(new AddShapeCommand(shapeList, newGroup));
                    history.Add(macroCommandSelectedShape);
                }

                if (hasMoved)
                {
                    Point   velocity  = new Point(e.Location.X - mouseDownLocation.X, e.Location.Y - mouseDownLocation.Y);
                    Command moveShape = new MoveShapeCommand(SelectedShape, velocity, shapeStartPosition);
                    history.Add(moveShape);
                }
                Invalidate();
            }
        }
예제 #8
0
        protected override void Context()
        {
            base.Context();
            //Create 3 commands. The second one is a macrocommand that contains 2 commands. The 2 commands is also a macro comamnd with 2 simple comamnd
            _containerCommand = new MacroCommand <MyContext>();

            _containerCommand.Add(_simpleCommand1);

            _macroCommand1 = new MacroCommand <MyContext>();
            _macroCommand1.Add(_simpleCommand2);

            _macroCommand2 = new MacroCommand <MyContext>();
            _macroCommand2.Add(_simpleCommand3, _simpleCommand4);

            _macroCommand1.Add(_macroCommand2);

            _containerCommand.Add(_macroCommand1);

            _containerCommand.Add(_simpleCommand5);
        }
예제 #9
0
 public void Add_NullCommand_Exception()
 {
     MacroCommand macro = new MacroCommand();
     Assert.Catch<ArgumentException>(() => macro.Add(null));
 }