/// <summary> /// Execute a new action and add/merge it in the Undo stack /// </summary> /// <param name="action"></param> public void ExecAction(UndoRedoAction action) { if (action.Cancel) { return; } // Execute the redo action action.Redo(); // Retrieve the last action in the list, and check if we can merge actions if (m_undoActions.Count > 0 && m_undoActions.Peek().CanMerge(action)) { m_undoActions.Peek().Merge(action); } else { m_undoActions.Push(action); } if (CanRedo) { m_redoActions.Clear(); } OnUndoRedo?.Invoke(this, UndoManager.Action.Exec); }
/// <summary> /// If possible, perform a redo action /// </summary> public void Redo() { if (CanRedo) { m_redoActions.Peek().Redo(); m_undoActions.Push(m_redoActions.Pop()); OnUndoRedo?.Invoke(this, UndoManager.Action.Redo); } }