예제 #1
0
        protected override void Because()
        {
            _removePartialStabiCommand.RestoreExecutionData(_executionContext);

            _restorePartialStabiCommand = _removePartialStabiCommand.InverseCommand(_executionContext).DowncastTo <IReversibleCommand <IExecutionContext> >();
            _restorePartialStabiCommand.Execute(_executionContext);
        }
 protected override void Context()
 {
     base.Context();
     sut.Execute(_executionContext);
     sut.RestoreExecutionData(_executionContext);
     _inverseCommand = sut.InverseCommand(_executionContext);
 }
예제 #3
0
 protected override void Context()
 {
     base.Context();
     _command1        = new MyReversibleCommand();
     _command1.Loaded = true;
     sut.AddToHistory(_command1);
 }
예제 #4
0
 protected override void Context()
 {
     base.Context();
     _commandToReset = A.Fake <IReversibleCommand <IOSPSuiteExecutionContext> >();
     _inverseCommand = A.Fake <IReversibleCommand <IOSPSuiteExecutionContext> >();
     A.CallTo(() => _commandToReset.InverseCommand(_executionContext)).Returns(_inverseCommand);
 }
예제 #5
0
        //1    2    3         4
        //  C1   C2   C31 C32    roll back to 1
        protected override void Context()
        {
            _context      = new MyContext();
            _historyItems = new List <IHistoryItem>();
            _command0     = new MyReversibleCommand {
                InternalId = "_command0"
            };
            _command1 = new MyReversibleCommand {
                InternalId = "_command1"
            };
            _command2 = new MyReversibleCommand {
                InternalId = "_command2"
            };
            _command31 = new MyReversibleCommand {
                InternalId = "_command31"
            };
            _command32 = new MyReversibleCommand {
                InternalId = "_command32"
            };
            _inverseCommand32 = _command32.InverseCommand(_context);
            _inverseCommand31 = _command31.InverseCommand(_context);
            _inverseCommand2  = _command2.InverseCommand(_context);
            _exceptionManager = A.Fake <IExceptionManager>();
            _eventPublisher   = A.Fake <IEventPublisher>();

            sut = new HistoryManager <MyContext>(_context, _eventPublisher, _exceptionManager, new HistoryItemFactory(), new RollBackCommandFactory(), _historyItems);

            sut.AddToHistory(_command0);
            sut.AddToHistory(_command1);
            sut.AddToHistory(_command2);
            _command3 = new MacroCommand <MyContext>();
            _command3.Add(_command31);
            _command3.Add(_command32);
            sut.AddToHistory(_command3);
        }
        protected override void Because()
        {
            _removePartialStabiCommand.RestoreExecutionData(_executionContext);

            _restorePartialStabiCommand = _removePartialStabiCommand.InverseCommand(_executionContext);
            _restorePartialStabiCommand.Execute(_executionContext);
        }
        protected override void Context()
        {
            base.Context();
            sut.Execute(_executionContext);
            sut.RestoreExecutionData(_executionContext);

            _inverseCommand = sut.InverseCommand(_executionContext).DowncastTo <IReversibleCommand <IExecutionContext> >();
        }
예제 #8
0
        public static IReversibleCommand <IOSPSuiteExecutionContext> InvokeInverse(this IReversibleCommand <IOSPSuiteExecutionContext> command, IOSPSuiteExecutionContext context)
        {
            command.RestoreExecutionData(context);
            var inverse = command.InverseCommand(context);

            inverse.Execute(context);
            return(inverse);
        }
예제 #9
0
 /// <inheritdoc/>
 public void RegisterCommand(IReversibleCommand command, object context)
 {
     undoStack.Push(new StackEntry {
         Command = command, Context = context
     });
     redoStack.Clear();
     OnStateChange();
 }
 protected override void Context()
 {
     base.Context();
     _parameter.IsFixedValue = false;
     sut.Execute(_executionContext);
     sut.RestoreExecutionData(_executionContext);
     _inverseCommand = sut.InverseCommand(_executionContext);
 }
예제 #11
0
        public XmlNode Redo()
        {
            XmlNode   affectedNode  = null;
            ArrayList affectedNodes = new ArrayList();

            if (redoCommands.Count > 0)
            {
                DeregisterHandlers();

                IReversibleCommand command = (IReversibleCommand)redoCommands[redoCommands.Count - 1];
                do
                {
                    affectedNodes.Add(command.Redo());

                    redoCommands.Remove(command);
                    undoCommands.Add(command);

                    if (redoCommands.Count > 0)
                    {
                        command = (IReversibleCommand)redoCommands[redoCommands.Count - 1];
                    }
                } while (redoCommands.Count > 0 && command.BeginCommandRange == false);

                RegisterHandlers();
            }

            foreach (XmlNode node in affectedNodes)
            {
                if (node is XmlText)
                {
                    if (node.ParentNode is XmlAttribute)
                    {
                        XmlAttribute att = node.ParentNode as XmlAttribute;
                        if (att.OwnerElement != null)
                        {
                            affectedNode = att.OwnerElement;
                            break;
                        }
                    }
                }
                else if (node.ParentNode != null)
                {
                    affectedNode = node;
                    break;
                }
                else if (node is XmlAttribute)
                {
                    XmlAttribute att = node as XmlAttribute;
                    if (att.OwnerElement != null)
                    {
                        affectedNode = att.OwnerElement;
                        break;
                    }
                }
            }

            return(affectedNode);
        }
예제 #12
0
 protected override void Context()
 {
     base.Context();
     _command1 = new MyReversibleCommand();
     _command2 = new MyReversibleCommand();
     sut.AddToHistory(_command1);
     sut.AddToHistory(_command2);
     _command2.Loaded = false;
 }
        public void AddExecute(IReversibleCommand command)
        {
            command.Execute();

            this.UndoCommands.Push(command);

            // Too simple?
            this.RedoCommands.Clear();
        }
예제 #14
0
        protected override void Context()
        {
            base.Context();
            A.CallTo(() => _executionContext.Get <IEntity>(_entity.Id)).Returns(_entity);
            sut.Execute(_executionContext);
            sut.RestoreExecutionData(_executionContext);

            _inverseCommand = sut.InverseCommand(_executionContext);
        }
예제 #15
0
        protected override void Context()
        {
            base.Context();
            _reversibleCommand1 = new MyReversibleCommand();
            _reversibleCommand2 = new MyReversibleCommand();
            _reversibleCommand3 = new MyReversibleCommand();

            MacroCommandExtensions.Add(sut, _reversibleCommand1, _reversibleCommand2, _reversibleCommand3);
        }
예제 #16
0
        protected override void Context()
        {
            base.Context();
            _reversibleCommand1 = new MyReversibleCommand();
            _reversibleCommand2 = new MyReversibleCommand();
            _reversibleCommand3 = new MyReversibleCommand();

            sut.Add(_reversibleCommand1, _reversibleCommand2, _reversibleCommand3);
        }
예제 #17
0
 protected override void Context()
 {
     base.Context();
     _command1 = new MyReversibleCommand();
     _command2 = new MyReversibleCommand();
     sut.AddToHistory(_command1);
     sut.AddToHistory(_command2);
     sut.AddLabel(A.Fake <ILabelCommand>());
     sut.AddLabel(A.Fake <ILabelCommand>());
 }
예제 #18
0
 //1  2  1   3  1
 //C1 C2 C-2 C3 C-3  roll back to 3
 protected override void Context()
 {
     base.Context();
     _command3 = new MyReversibleCommand();
     sut.AddToHistory(_command1);
     sut.AddToHistory(_command2);
     sut.RollBackTo(1);
     sut.AddToHistory(_command3);
     sut.RollBackTo(1);
 }
 protected override void Context()
 {
     base.Context();
     //Add
     sut.Execute(_executionContext);
     //Remove
     sut.RestoreExecutionData(_executionContext);
     _removePartialStabiCommand = sut.InverseCommand(_executionContext);
     _removePartialStabiCommand.Execute(_executionContext);
 }
        public void UndoPreviousCommand()
        {
            IReversibleCommand cmd = null;

            if (this.undoCommandStack.TryPeek(out cmd))
            {
                cmd.Undo();

                this.undoCommandStack.TryPop(out cmd);
            }
        }
        public void ExecuteCommand(IReversibleCommand command)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            command.Execute();

            this.undoCommandStack.Push(command);
        }
예제 #22
0
 /// <summary>
 /// Executes a command on this document.
 /// The command will be stored and not applied immediately, use Apply()
 /// to apply all pending commands.
 /// </summary>
 /// <param name="reversibleCommand">The command to apply.</param>
 /// <returns>This document, for chaining.</returns>
 public ReversibleDocument <TDocument> Do(IReversibleCommand <TDocument> reversibleCommand)
 {
     if (_canRedo)
     {
         _canRedo = false;
         _pending.Clear();
     }
     _pending.Add(reversibleCommand);
     OnPropertyChanged("CanRedo");
     OnPropertyChanged("CanUndo");
     return(this);
 }
예제 #23
0
        protected override void Context()
        {
            base.Context();
            _commandToExecute1 = A.Fake <IReversibleCommand <MyContext> >();
            _commandToExecute2 = A.Fake <IReversibleCommand <MyContext> >();
            _commandToExecute3 = A.Fake <IReversibleCommand <MyContext> >();

            MacroCommandExtensions.Add(sut, _commandToExecute1, _commandToExecute2, _commandToExecute3);
            A.CallTo(() => _commandToExecute1.Id).Returns(new CommandId());
            A.CallTo(() => _commandToExecute2.Id).Returns(new CommandId());
            A.CallTo(() => _commandToExecute3.Id).Returns(new CommandId());
        }
예제 #24
0
        public void Redo()
        {
            if (redoList.Count == 0)
            {
                return;
            }

            IReversibleCommand reversibleCommand = redoList.First.Value;

            redoList.RemoveFirst();
            reversibleCommand.Execute();
            undoList.AddFirst(reversibleCommand);
        }
예제 #25
0
 protected override void Context()
 {
     base.Context();
     _command1 = new MyReversibleCommand {
         Loaded = true
     };
     _command2 = new MyReversibleCommand {
         Loaded = true
     };
     _labelCommand = new LabelCommand();
     sut.AddToHistory(_command1);
     sut.AddToHistory(_command2);
 }
예제 #26
0
        public void Undo()
        {
            if (undoList.Count == 0)
            {
                return;
            }

            IReversibleCommand reversibleCommand = undoList.First.Value;

            undoList.RemoveFirst();
            reversibleCommand.Undo();
            redoList.AddFirst(reversibleCommand);
        }
예제 #27
0
 protected override void Context()
 {
     _state           = 2;
     _inverseCommand1 = A.Fake <IReversibleCommand <MyContext> >();
     _inverseCommand2 = A.Fake <IReversibleCommand <MyContext> >();
     _command1        = A.Fake <IReversibleCommand <MyContext> >();
     _command2        = A.Fake <IReversibleCommand <MyContext> >();
     _commandList     = new List <IReversibleCommand <MyContext> > {
         _command1, _command2
     };
     sut      = new RollBackCommand <MyContext>(_state, _commandList);
     _context = new MyContext();
     A.CallTo(() => _command1.InverseCommand(_context)).Returns(_inverseCommand1);
     A.CallTo(() => _command2.InverseCommand(_context)).Returns(_inverseCommand2);
 }
예제 #28
0
        private void HandleChangedInclude(IReversibleCommand cmd)
        {
            if (WixEditSettings.Instance.AllowIncludeChanges == IncludeChangesHandling.Disallow)
            {
                // Stop people from making more changes to this file,
                // and undo this command.
                if (isPropertyGridEdit)
                {
                    this.Undo(false);

                    MessageBox.Show(String.Format("You cannot change include file \"{0}\".", cmd.AffectedInclude), "Cannot modify include file.", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    throw new ApplicationException("Not allowed to change include file.", new IncludeFileChangedException(this, cmd, true));
                }
            }
            else if (WixEditSettings.Instance.AllowIncludeChanges == IncludeChangesHandling.Allow)
            {
                // Do nothing...
                if (allowChangIncludeFiles.Count == 0 || allowChangIncludeFiles.Contains(cmd.AffectedInclude) == false)
                {
                    allowChangIncludeFiles.Add(cmd.AffectedInclude);
                }
            }
            else if (WixEditSettings.Instance.AllowIncludeChanges == IncludeChangesHandling.AskForEachFile)
            {
                if (allowChangIncludeFiles.Count == 0 || allowChangIncludeFiles.Contains(cmd.AffectedInclude) == false)
                {
                    DialogResult result = MessageBox.Show(String.Format("You are changing \"{0}\", do you wish to continue?", cmd.AffectedInclude), "Modify include file?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        allowChangIncludeFiles.Add(cmd.AffectedInclude);
                    }
                    else
                    {
                        if (isPropertyGridEdit)
                        {
                            this.Undo(false);
                        }
                        else
                        {
                            throw new ApplicationException("Not allowed to change include file.", new IncludeFileChangedException(this, cmd, false));
                        }
                    }
                }
            }
        }
예제 #29
0
        public void AddToStack(IReversibleCommand reversibleCommand)
        {
            undoList.AddFirst(reversibleCommand);
            foreach (IReversibleCommand command in redoList)
            {
                command.DisposeRedo();
            }
            redoList.Clear();

            if (undoList.Count > MaxUndoCount)
            {
                IReversibleCommand removedCommand = undoList.Last.Value;
                undoList.RemoveLast();
                removedCommand.DisposeUndo();
            }
        }
        protected override void Context()
        {
            base.Context();
            _parameter.IsFixedValue = false;
            sut.Execute(_executionContext); //=> IsFixedValue = true, command did set the value for the first time

            //Inverse Command_should reset the parameter value to the formula
            sut.RestoreExecutionData(_executionContext);
            var command = sut.InverseCommand(_executionContext);

            command.Execute(_executionContext);

            //Inverse of Inverse command = first command
            command.RestoreExecutionData(_executionContext);
            _reverseCommand = command.InverseCommand(_executionContext);
        }
예제 #31
0
        public void Push(IReversibleCommand command)
        {
            command.Run();
            if (HasUndoneItems())
            {
                RemoveUndoneItems();
                _commands.Add(command);
                _commandIndex = _commands.Count - 1;
                return;
            }

            if (_commandIndex == null)
                _commandIndex = 0;
            else
                _commandIndex++;
            _commands.Add(command);
        }
예제 #32
0
        public string GetNextUndoActionString()
        {
            if (undoCommands.Count == 0)
            {
                return(String.Empty);
            }

            for (int i = undoCommands.Count - 1; i >= 0; i--)
            {
                IReversibleCommand cmd = (IReversibleCommand)undoCommands[i];
                if (cmd.BeginCommandRange)
                {
                    return(cmd.GetDisplayActionString());
                }
            }

            // If the command starting the CommandRange is not found, return the first...
            return(((IReversibleCommand)undoCommands[undoCommands.Count - 1]).GetDisplayActionString());
        }
예제 #33
0
파일: UndoManager.cs 프로젝트: xwiz/WixEdit
        private void HandleChangedInclude(IReversibleCommand cmd)
        {
            if (WixEditSettings.Instance.AllowIncludeChanges == IncludeChangesHandling.Disallow)
            {
                // Stop people from making more changes to this file,
                // and undo this command.
                if (isPropertyGridEdit)
                {
                    this.Undo(false);

                    MessageBox.Show(String.Format("You cannot change include file \"{0}\".", cmd.AffectedInclude), "Cannot modify include file.", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    throw new ApplicationException("Not allowed to change include file.", new IncludeFileChangedException(this, cmd, true));
                }
            }
            else if (WixEditSettings.Instance.AllowIncludeChanges == IncludeChangesHandling.Allow)
            {
                // Do nothing...
                if (allowChangIncludeFiles.Count == 0 || allowChangIncludeFiles.Contains(cmd.AffectedInclude) == false)
                {
                    allowChangIncludeFiles.Add(cmd.AffectedInclude);
                }
            }
            else if (WixEditSettings.Instance.AllowIncludeChanges == IncludeChangesHandling.AskForEachFile)
            {
                if (allowChangIncludeFiles.Count == 0 || allowChangIncludeFiles.Contains(cmd.AffectedInclude) == false)
                {
                    DialogResult result = MessageBox.Show(String.Format("You are changing \"{0}\", do you wish to continue?", cmd.AffectedInclude), "Modify include file?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        allowChangIncludeFiles.Add(cmd.AffectedInclude);
                    }
                    else
                    {
                        if (isPropertyGridEdit)
                        {
                            this.Undo(false);
                        }
                        else
                        {
                            throw new ApplicationException("Not allowed to change include file.", new IncludeFileChangedException(this, cmd, false));
                        }
                    }
                }
            }
        }