public void SaveAndExecute(UndoRedoAction a_action) { if (IsInUndoRedo) { throw new Exception(); } if (m_action_index < m_actions.Count - 1) { m_actions.RemoveRange(m_action_index + 1, m_actions.Count - (m_action_index + 1)); } a_action.UndoState.Save(); m_actions.Add(a_action); m_action_index++; if (m_actions.Count > UndoRedoConfiguration.UndoRedo_MaxDeep) { m_actions = m_actions.Skip(m_actions.Count - UndoRedoConfiguration.UndoRedo_MaxDeep). Take(UndoRedoConfiguration.UndoRedo_MaxDeep).ToList(); } OnChanged(); CurrentAction.Redo(); }
public void Redo(UndoRedoAction a_action = null) { if (!CanRedo) { throw new InvalidOperationException(); } if (IsInUndoRedo) { throw new InvalidOperationException(); } if (a_action == null) { a_action = RedoActions.First(); } if (!RedoActions.Contains(a_action)) { throw new ArgumentException(); } m_undo_redo = true; try { var todo = RedoActions.Reverse().SkipWhile(a => a != a_action).Reverse(); todo.First().UndoState.Save(); foreach (var action in todo) { if (UndoRedoConfiguration.Logging) { System.Console.WriteLine("redo: " + action.RedoDescription); } action.Redo(); m_action_index++; } todo.Last().RedoState.Restore(); } finally { m_undo_redo = false; } OnChanged(); }