Ejemplo n.º 1
0
        /// <summary>
        /// Push a new <see cref="IAction"/> onto the <see cref="WUndoStack"/>, or merges it with the most recently executed command.
        /// This function executes the <see cref="IAction.Redo"/> function in either case. Calling this will clear the <see cref="WUndoStack"/>'s
        /// Redo stack, so the command will always end up being the top-most on the stack.
        /// </summary>
        /// <param name="command"></param>
        public void Push(WUndoCommand command)
        {
            // If we have an open macro, we push it to the macro instead of the stack, and when the macro is ended, that is when it is finally pushed to the stack.
            // command.GetType().IsSubclassOf(typeof(WUndoCommand)) will return false if we're pushing a WUndoCommand, ie: the end of a macro.
            if (m_macroParent != null && command.GetType().IsSubclassOf(typeof(WUndoCommand)))
            {
                command.SetParent(m_macroParent);
                return;
            }

            // Clear the redo stack when we add a new item to the undo stack.
            m_redoStack.Clear();

            // Call the Redo function to apply the state change encapsulated by the IAction.
            command.Redo();

            // Attempt to merge with our new action. If this fails, add our new action to the undo stack.
            WUndoCommand latestAction = m_undoStack.Peek();

            if (latestAction == null)
            {
                m_undoStack.Push(command);
            }
            else if (!latestAction.MergeWith(command))
            {
                m_undoStack.Push(command);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Calling this function clears both the undo and redo stack. This should be
 /// used when a map is closed so that we free all references to objects in that
 /// map.
 /// </summary>
 public void Clear()
 {
     m_undoStack.Clear();
     m_redoStack.Clear();
 }