/// <summary> /// Executes command, pushes it into the undo stack /// and clears the redo stack /// </summary> public void Execute(ICommand command) { command.Execute(); UndoStack.Push(command); RedoStack.Clear(); if (UndoStack.Count == 1) { CanUndoChanged?.Invoke(true, null); } CanRedoChanged?.Invoke(false, null); }
/// <summary> /// Redoes command /// </summary> public void Redo() { if (!CanRedo) { return; } var command = RedoStack.Pop(); command.Execute(); UndoStack.Push(command); if (!CanRedo) { CanRedoChanged?.Invoke(false, null); } if (UndoStack.Count == 1) { CanUndoChanged?.Invoke(true, null); } }
private void UndoStack_HasItemsChanged(object sender, EventArgs e) { CanUndoChanged?.Invoke(this, new EventArgs()); }
/// <summary> /// 触发可撤销/重做状态变更事件; /// </summary> protected void RaiseCanUndoRedoChanged() { CanRedoChanged?.Invoke(this, new CanRedoChangedEventArgs(CanRedo)); CanUndoChanged?.Invoke(this, new CanUndoChangedEventArgs(CanUndo)); }
private void UndoService_CanUndoChanged(object sender, EventArgs e) { CanUndoChanged?.Invoke(this, e); }
} // proc Redo private void RaiseCanUndo() => CanUndoChanged?.Invoke(this, EventArgs.Empty);
private void UndoRedoHandler_CanUndoChanged(object sender, EventArgs e) { CanUndoChanged?.Invoke(null, EventArgs.Empty); }