//--------------------// #region Undo /// <inheritdoc/> protected override void OnUndo() { // Remove last command from the undo list, execute it and add it to the redo list IUndoCommand lastCommand = UndoBackups.Pop(); lastCommand.Undo(); RedoBackups.Push(lastCommand); }
/// <summary> /// Mark the content of this tab as changed (needs to be saved) and create a new undo-backup /// </summary> protected override void OnChange() { // Move the last backup to the undo list and then create a new backup UndoBackups.Push(_currentBackup); _currentBackup = (ICloneable)Content.Clone(); buttonUndo.Enabled = true; base.OnChange(); }
/// <summary> /// Called to redo the last undone change /// </summary> protected override void OnRedo() { // Remove the last backup from the redo list, then add the current backup to the undo list ICloneable toRestore = RedoBackups.Pop(); UndoBackups.Push(_currentBackup); // Restore the backup and update the current backup Content = (ICloneable)toRestore.Clone(); _currentBackup = (ICloneable)Content.Clone(); }
//--------------------// #region Command /// <summary> /// Executes a <see cref="IUndoCommand"/> using this tab's undo stack. /// </summary> protected void ExecuteCommand(IUndoCommand command) { #region Sanity checks if (command == null) { throw new ArgumentNullException(nameof(command)); } #endregion command.Execute(); UndoBackups.Push(command); buttonUndo.Enabled = true; OnUpdate(); OnChange(); }