示例#1
0
 /// <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;
 }
示例#2
0
        private BaseEvent InternalEndBatch(BatchEvent stack)
        {
            BaseEvent processed = ProcessBatch(_currentBatch);

            if (processed != null)
            {
                stack.Push(processed);
            }
            _currentBatch = null;
            return(processed);
        }
示例#3
0
 private BaseEvent ProcessBatch(BatchEvent batchEvent)
 {
     if (batchEvent.Count == 0)
     {
         return(null);
     }
     if (batchEvent.Count == 1)
     {
         return(batchEvent.Pop());
     }
     return(batchEvent);
 }
示例#4
0
        /// <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();
        }
示例#5
0
        /// <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);
            }
        }
示例#6
0
        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);
        }
示例#7
0
 internal BatchEvent(BatchEvent other = null)
 {
     _events = other == null
                   ? new Stack <BaseEvent>()
                   : new Stack <BaseEvent>(other._events.Reverse());
 }