public IAction Redo() { if (redoStack.Count > 0) { IUndoableAction action = null; while (redoStack.Count > 0) { action = redoStack.Pop(); Logger.Log(LOGKEY, "redo action: " + action.ToString()); if (BeforePerformAction != null) { var arg = new ActionEventArgs(action, ActionBehavior.Redo); BeforePerformAction(this, arg); if (arg.Cancel) { break; } } action.Redo(); undoStack.Add(action); AfterPerformAction?.Invoke(this, new ActionEventArgs(action, ActionBehavior.Redo)); if (!(action is ISerialUndoAction)) { break; } } return(action); } else { return(null); } }
public IAction Undo() { if (undoStack.Count() > 0) { IUndoableAction action = null; while (undoStack.Count > 0) { action = undoStack.Last(); Logger.Log(LOGKEY, "undo action: " + action.ToString()); // before event if (BeforePerformAction != null) { var arg = new ActionEventArgs(action, ActionBehavior.Undo); BeforePerformAction(this, new ActionEventArgs(action, ActionBehavior.Undo)); if (arg.Cancel) { break; } } undoStack.Remove(action); action.Undo(); redoStack.Push(action); // after event AfterPerformAction?.Invoke(this, new ActionEventArgs(action, ActionBehavior.Undo)); if (!(action is ISerialUndoAction)) { break; } } return(action); } return(null); }