/// <summary> /// Disposes the this mementor and clears redo and undo stacks. /// This method won't fire <see cref="Changed"/> event. /// </summary> public void Dispose() { Changed = null; _undoStack.Clear(); _redoStack.Clear(); _currentBatch = null; }
private BaseEvent InternalEndBatch(BatchEvent stack) { BaseEvent processed = ProcessBatch(_currentBatch); if (processed != null) { stack.Push(processed); } _currentBatch = null; return(processed); }
private BaseEvent ProcessBatch(BatchEvent batchEvent) { if (batchEvent.Count == 0) { return(null); } if (batchEvent.Count == 1) { return(batchEvent.Pop()); } return(batchEvent); }
/// <summary> /// Explicitly marks the beginning of a batch. Use this instead of <see cref="Batch"/> /// changes can be made in different places instead of inside one certain block of code. /// When finish, end the batch by invoking <see cref="EndBatch"/>. /// </summary> public void BeginBatch() { if (!IsTrackingEnabled) { return; } if (IsInBatch) { throw new InvalidOperationException("Re-entrant batch is not supported"); } _currentBatch = new BatchEvent(); }
/// <summary> /// Resets the state of this <see cref="Mementor"/> object to its initial state. /// This effectively clears the redo stack, undo stack and current batch (if one is active). /// </summary> public void Reset() { bool shouldNotify = UndoCount > 0 || RedoCount > 0; _undoStack.Clear(); _redoStack.Clear(); _currentBatch = null; IsTrackingEnabled = true; if (shouldNotify) { NotifyChange(null); } }
protected internal override BaseEvent Rollback() { var batch = new BatchEvent(); while (Count > 0) { var reverse = Pop().Rollback(); if (reverse == null) { continue; } if (reverse is BatchEvent) { throw new InvalidOperationException("Must not return BatchEvent in Rollback()"); } batch.Push(reverse); } return(batch); }
internal BatchEvent(BatchEvent other = null) { _events = other == null ? new Stack <BaseEvent>() : new Stack <BaseEvent>(other._events.Reverse()); }