/// <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 RedoStack_HasItemsChanged(object sender, EventArgs e) { CanRedoChanged?.Invoke(this, new EventArgs()); }
/// <summary> /// 触发可撤销/重做状态变更事件; /// </summary> protected void RaiseCanUndoRedoChanged() { CanRedoChanged?.Invoke(this, new CanRedoChangedEventArgs(CanRedo)); CanUndoChanged?.Invoke(this, new CanUndoChangedEventArgs(CanUndo)); }
private void UndoService_CanRedoChanged(object sender, EventArgs e) { CanRedoChanged?.Invoke(this, e); }
private void RaiseCanRedo() => CanRedoChanged?.Invoke(this, EventArgs.Empty);
private void UndoRedoHandler_CanRedoChanged(object sender, EventArgs e) { CanRedoChanged?.Invoke(null, EventArgs.Empty); }