Exemplo n.º 1
0
        protected bool ExecuteActionInternal(IUndoableAction action, bool clearRedoStack)
        {
            OnBeforeStateChanged();

            if (!action.Execute())
            {
                return(false);
            }

            if (clearRedoStack)
            {
                redoStack.Clear();
            }

            var undoGroup = action.GetUndoGroup();

            // Should we group together this undo step with more of the same kind?
            if (undoGroup != 0)
            {
                if (currentGroup == null || currentGroup.CaughtGroup != undoGroup)
                {
                    currentGroup = new UndoableActionGroup(undoGroup);
                    AddToUndoStack(currentGroup);
                }

                currentGroup.Actions.Add(action);
            }
            else
            {
                AddToUndoStack(action);
            }

            OnAfterStateChanged();
            return(true);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Force the current undo group to stop. For example, if you're painting some tiles and
 /// stop for a moment, you might want to split the undo group at that point in order
 /// to separate undo steps by stroke. Call this function to do so.
 /// </summary>
 /// <param name="group">Id of the group we want to end.</param>
 public void EndUndoGroup(int group)
 {
     if (currentGroup != null && currentGroup.CaughtGroup == group)
     {
         currentGroup = null;
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Clear entire undo state.
 /// </summary>
 public void Clear()
 {
     OnBeforeStateChanged();
     currentGroup = null;
     undoStack.Clear();
     redoStack.Clear();
     OnAfterStateChanged();
 }
Exemplo n.º 4
0
        /// <summary>
        /// Redo a single action.
        /// </summary>
        public void Redo()
        {
            currentGroup = null;

            if (redoStack.Count > 0)
            {
                var action = redoStack[redoStack.Count - 1];
                redoStack.RemoveAt(redoStack.Count - 1);

                ExecuteActionInternal(action, false);
                OnRedoEvent(action);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Undo a single action.
        /// </summary>
        public void Undo()
        {
            currentGroup = null;

            if (undoStack.Count > 0)
            {
                OnBeforeStateChanged();

                var action = undoStack[undoStack.Count - 1];
                undoStack.RemoveAt(undoStack.Count - 1);

                action.Undo();
                redoStack.Add(action);

                OnUndoEvent(action);
                OnAfterStateChanged();
            }
        }