Exemple #1
0
        /// <summary>
        /// Performs the 'Redo' action of the most recently undone command. This command will
        /// then be moved back to the undo stack so it can later be undone again.
        /// </summary>
        public void RedoCommand()
        {
            if (mRedoStack.Count == 0)
            {
                throw new InvalidOperationException("There are no commands to be redone");
            }

            IVEFCommand cmd = mRedoStack.Pop();

            cmd.Redo();

            mUndoStack.Push(cmd);

            FireStateChanged();
        }
Exemple #2
0
        /// <summary>
        /// Undoes the top most command on the undo stack and removes it from the system. The command
        /// does not transfer to the redo stack.
        /// </summary>
        public void UndoAndPopCommand()
        {
            if (mUndoStack.Count == 0)
            {
                throw new InvalidOperationException("There are no commands to be undone");
            }

            IVEFCommand cmd = mUndoStack.Pop();

            cmd.Undo();

            cmd.Dispose();

            // NOTE: We do not push the command onto the redo stack. It just vanishes

            FireStateChanged();
        }
Exemple #3
0
        /// <summary>
        /// Adds the given command onto the undo/redo stacks. This will clear any redo commands
        /// since the state path has been altered before these commands were originally executed.
        /// This may potentially remove elements from the bottom of the undo stack if adding this
        /// command will exceed the maximum capacity of the system
        /// </summary>
        /// <param name="cmd">The command to add to the system</param>
        public void AddCommand(IVEFCommand cmd)
        {
            mRedoStack.Clear();

            if (mUndoStack.Count == mMaxCommands)
            {
                ReduceStackFromBottom(mUndoStack, 1);
            }

            mUndoStack.Push(cmd);

            //if(cmd.CanExecute(null))
            //{
            //    cmd.Execute(null);
            //}

            // TODO: Handle the case of a non-undoable command being added

            FireStateChanged();
        }