예제 #1
0
        public void AddUndoItem(IUndoItem undoEvent)
        {
            if (Working)
            {
                return;
            }

            bool emptyBefore = (_batch?.Count ?? 0) == 0 && !_undoEvents.Any();

            if (_batch != null)
            {
                _batch.Add(undoEvent);
            }
            else
            {
                ClearRedoHistory();
                _undoEvents.Push(undoEvent);
                if (_undoEvents.Count > MAX_UNDO_ITEMS)
                {
                    // XXX: we throw away the current item? this should be a Dequeue so we can pop the front
                    _undoEvents.Pop();
                }
            }

            if (emptyBefore)
            {
                // no longer empty
                NonEmpty?.Invoke(this, EventArgs.Empty);
            }
        }
예제 #2
0
        public void CloseBatch()
        {
            if (_batch == null)
            {
                return;
            }

            if (_batch.Count > 0)
            {
                bool emptyBefore = !_undoEvents.Any();
                _undoEvents.Push(_batch);
                if (emptyBefore)
                {
                    // no longer empty
                    NonEmpty?.Invoke(this, EventArgs.Empty);
                }
            }
            _batch = null;
        }
예제 #3
0
        /// <summary>
        /// Rollback the last undone command.
        /// </summary>
        public void Redo()
        {
            if (!CanRedo)
            {
                return;
            }

            Working = true;
            IUndoItem redo = _redoEvents.Pop();

            redo.Do();
            bool emptyBefore = !_undoEvents.Any();

            _undoEvents.Push(redo);
            Working = false;
            if (emptyBefore)
            {
                NonEmpty?.Invoke(this, EventArgs.Empty);
            }
        }