Example #1
0
        public bool CanExecute(CopyPasteCommand command)
        {
            switch (command)
            {
            case CopyPasteCommand.Cut:
            case CopyPasteCommand.Copy:
            case CopyPasteCommand.Duplicate:
            case CopyPasteCommand.Delete:
                return(true);

            case CopyPasteCommand.Paste:
                return(worldCopyPaste.Node != null);

            case CopyPasteCommand.MoveTop:
            case CopyPasteCommand.MoveUp:
                return(Siblings?.IndexOf(Node) > 0);

            case CopyPasteCommand.MoveDown:
            case CopyPasteCommand.MoveBottom:
                var index = Siblings?.IndexOf(Node);
                return(0 <= index && index < Siblings.Count - 1);

            default:
                throw new ArgumentOutOfRangeException(nameof(command), command, null);
            }
        }
Example #2
0
        public void WhenCopyParamsWithinValue_ThenPaste(int copyPosition, int copyLength, int pastePosition, string expected)
        {
            var sut = new CopyPasteCommand(copyPosition, copyLength, pastePosition).SetValue(Value);

            sut.Execute();

            Assert.That(sut.Result, Is.EqualTo(expected));
        }
Example #3
0
        public void WhenPastePositionGreaterThanLength_ThenPasteAtEnd()
        {
            var sut = new CopyPasteCommand(0, 4, Value.Length + 1).SetValue(Value);

            sut.Execute();

            Assert.That(sut.Result, Is.EqualTo(Value + "John"));
        }
Example #4
0
        public void WhenCopyLengthWouldGoOutOfRange_ThenCopyTillEnd(int copyPosition, int copyLength, int pastePosition, string expected)
        {
            var sut = new CopyPasteCommand(copyPosition, copyLength, pastePosition).SetValue(Value);

            sut.Execute();

            Assert.That(sut.Result, Is.EqualTo(expected));
        }
Example #5
0
        public void WhenCopyPositionEqualsOrGreaterThanValueLength_ThenSetToSame(int copyPosition, int copyLength, int pastePosition)
        {
            var sut = new CopyPasteCommand(copyPosition, copyLength, pastePosition).SetValue(Value);

            sut.Execute();

            Assert.That(sut.Result, Is.EqualTo(Value));
        }
Example #6
0
        public void WhenCopyLengthIsLessThanOne_ThenSetToSame()
        {
            var sut = new CopyPasteCommand(0, 0, 5).SetValue(Value);

            sut.Execute();

            Assert.That(sut.Result, Is.EqualTo(Value));
        }
Example #7
0
        public void WhenValueIsNull_ThenSetToNull()
        {
            var sut = new CopyPasteCommand(0, 2, 5);

            sut.Execute();

            Assert.That(sut.Result, Is.Null);
        }
Example #8
0
        private void ExecuteCopyPaste(CopyPasteCommand command)
        {
            var cCopyPaste = GetCopyPasteComponents().FirstOrDefault(x => x.Overrides(command));

            if (cCopyPaste == null || !cCopyPaste.CanExecute(command))
            {
                return;
            }
            cCopyPaste.Execute(command);
            undoRedoService.OnChange();
        }
Example #9
0
            public void WhenCommandsSet_ThenExecuteCommands()
            {
                var c1 = new CaseToLowerCommand().SetValue("John Smith");
                var c2 = new CopyPasteCommand(0, 4, 0).SetValue("John Smith");

                _sut.SetCommands(c1, c2);
                _sut.Invoke();

                Assert.That(c1.Result, Is.EqualTo("john smith"));
                Assert.That(c2.Result, Is.EqualTo("JohnJohn Smith"));
            }
Example #10
0
 // CopyPaste
 public bool Overrides(CopyPasteCommand command)
 {
     return(true);
 }
Example #11
0
        public void Execute(CopyPasteCommand command)
        {
            var siblings = Siblings;

            switch (command)
            {
            case CopyPasteCommand.Cut:
                worldCopyPaste.Node = Node;
                Node.Deparent();
                break;

            case CopyPasteCommand.Copy:
                worldCopyPaste.Node = Node;
                break;

            case CopyPasteCommand.Duplicate:
                var nodeCopy = Node.CloneTyped();
                foreach (var copyNode in nodeCopy.EnumerateSceneNodesDeep())
                {
                    copyNode.Id = 0;
                }
                Siblings.Insert(Siblings.IndexOf(Node), nodeCopy);
                break;

            case CopyPasteCommand.Paste:
                if (worldCopyPaste.Node == null)
                {
                    return;
                }
                var focusNode = Node.PresentationInfra().ClosestFocusNode;
                if (focusNode == null)
                {
                    return;
                }
                var copy = worldCopyPaste.Node.CloneTyped();
                foreach (var copyNode in copy.EnumerateSceneNodesDeep())
                {
                    copyNode.Id = 0;
                }
                focusNode.ChildNodes.Add(copy);
                break;

            case CopyPasteCommand.Delete:
                Node.Deparent();
                break;

            case CopyPasteCommand.MoveTop:
            {
                Node.Deparent();
                siblings.Insert(0, Node);
                break;
            }

            case CopyPasteCommand.MoveUp:
            {
                var index = siblings.IndexOf(Node);
                Node.Deparent();
                siblings.Insert(index - 1, Node);
                break;
            }

            case CopyPasteCommand.MoveDown:
            {
                var index = siblings.IndexOf(Node);
                Node.Deparent();
                siblings.Insert(index + 1, Node);
                break;
            }

            case CopyPasteCommand.MoveBottom:
            {
                Node.Deparent();
                siblings.Add(Node);
                break;
            }

            default:
                throw new ArgumentOutOfRangeException(nameof(command), command, null);
            }
        }