/// <summary> /// Executes the next undo operation. /// </summary> /// <returns><c>true</c> if an undo was executed; otherwise <c>false</c>.</returns> public bool Undo() { if (!CanUndo) { Log.Info("Cannot undo action"); return(false); } Log.Debug("Undoing action"); IMementoBatch undo = null; lock (_lock) { if (_undoBatches.Count > 0) { undo = _undoBatches.First(); _undoBatches.RemoveFirst(); } } if (undo is null) { Log.Info("Cannot undo because there is no undo batch for this action"); return(false); } _isUndoingOperation = true; try { undo.Undo(); if (undo.CanRedo) { lock (_lock) { _redoBatches.Insert(0, undo); while (_redoBatches.Count > _maximumSupportedOperations) { _redoBatches.RemoveLast(); } } } Updated?.Invoke(this, new MementoEventArgs(MementoAction.Undo, undo)); Log.Debug("Action is successfully undone"); return(true); } finally { lock (_lock) { _isUndoingOperation = false; } } }
/// <summary> /// Executes the next undo operation. /// </summary> /// <returns><c>true</c> if an undo was executed; otherwise <c>false</c>.</returns> public bool Undo() { if (CanUndo) { IMementoBatch undo = null; lock (_lock) { if (_undoBatches.Count > 0) { _isUndoingOperation = true; undo = _undoBatches.First(); _undoBatches.RemoveFirst(); } } if (undo != null) { try { undo.Undo(); if (undo.CanRedo) { lock (_lock) { _redoBatches.Insert(0, undo); while (_redoBatches.Count > _maximumSupportedOperations) { _redoBatches.RemoveLast(); } } } return(true); } finally { lock (_lock) { _isUndoingOperation = false; } } } } return(false); }