Пример #1
0
        /// <summary>
        /// Performs requested amount of redo operation and places the transactions on the undo stack.
        /// UNDONE: What if there is a currently opened transaction?
        /// </summary>
        /// <param name="count">The number of redo operations to perform. At the end of the operation, requested number of visible
        /// transactions are redone. Hence actual number of transactions redone might be more than this number if there are some
        /// hidden transactions adjacent to (on top of or at the bottom of) the visible ones.
        /// </param>
        /// <remarks>
        /// After the last visible transaction is redone, hidden transactions left on top the stack are redone as well until a
        /// visible or linked transaction is encountered or stack is emptied totally.
        /// </remarks>
        public void Redo(int count)
        {
            if (count <= 0)
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentUICulture, "Strings.RedoAndUndoAcceptOnlyPositiveCounts", "Redo", count), "count");
            }

            if (!IsThereEnoughVisibleTransactions(this.redoStack, count))
            {
                throw new InvalidOperationException(String.Format(CultureInfo.CurrentUICulture, "Strings.CannotUndoMoreTransactionsThanExist", "redo", count));
            }

            TextUndoHistoryState originalState = this.state;

            this.state = TextUndoHistoryState.Redoing;
            using (new AutoEnclose(delegate { this.state = originalState; }))
            {
                while (count > 0)
                {
                    if (!this.redoStack.Peek().CanRedo)
                    {
                        throw new InvalidOperationException("Strings.CannotRedoRequestedPrimitiveFromHistoryRedo");
                    }
                    ITextUndoTransaction ut = this.redoStack.Pop();
                    ut.Do();
                    this.undoStack.Push(ut);

                    RaiseUndoRedoHappened(this.state, ut);

                    --count;
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Performs requested amount of redo operation and places the transactions on the undo stack.
        /// UNDONE: What if there is a currently opened transaction?
        /// </summary>
        /// <param name="count">The number of redo operations to perform. At the end of the operation, requested number of visible
        /// transactions are redone. Hence actual number of transactions redone might be more than this number if there are some
        /// hidden transactions adjacent to (on top of or at the bottom of) the visible ones.
        /// </param>
        /// <remarks>
        /// After the last visible transaction is redone, hidden transactions left on top the stack are redone as well until a
        /// visible or linked transaction is encountered or stack is emptied totally.
        /// </remarks>
        public void Redo(int count)
        {
            if (count <= 0)
            {
                throw new ArgumentException("count must be > 0", nameof(count));
            }

            if (!IsThereEnoughVisibleTransactions(_redoStack, count))
            {
                throw new InvalidOperationException("No more undos/redos on the stack");
            }

            TextUndoHistoryState originalState = _state;

            _state = TextUndoHistoryState.Redoing;
            using (new AutoEnclose(delegate { this._state = originalState; })) {
                while (count > 0)
                {
                    if (!_redoStack.Peek().CanRedo)
                    {
                        throw new InvalidOperationException("Cannot redo/ask primitive from stack");
                    }

                    ITextUndoTransaction ut = _redoStack.Pop();
                    ut.Do();
                    _undoStack.Push(ut);

                    RaiseUndoRedoHappened(_state, ut);

                    --count;
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Performs requested amount of redo operation and places the transactions on the undo stack.
        /// UNDONE: What if there is a currently opened transaction?
        /// </summary>
        /// <param name="count">The number of redo operations to perform. At the end of the operation, requested number of visible
        /// transactions are redone. Hence actual number of transactions redone might be more than this number if there are some
        /// hidden transactions adjacent to (on top of or at the bottom of) the visible ones.
        /// </param>
        /// <remarks>
        /// After the last visible transaction is redone, hidden transactions left on top the stack are redone as well until a
        /// visible or linked transaction is encountered or stack is emptied totally.
        /// </remarks>
        public void Redo(int count)
        {
            if (count <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(count));
            }

            if (!IsThereEnoughVisibleTransactions(this.redoStack, count))
            {
                throw new InvalidOperationException("Cannot redo more transactions than exist");
            }

            TextUndoHistoryState originalState = this.state;

            this.state = TextUndoHistoryState.Redoing;
            using (new AutoEnclose(delegate { this.state = originalState; }))
            {
                while (count > 0)
                {
                    if (!this.redoStack.Peek().CanRedo)
                    {
                        throw new InvalidOperationException("Strings.CannotRedoRequestedPrimitiveFromHistoryRedo");
                    }
                    ITextUndoTransaction ut = this.redoStack.Pop();
                    ut.Do();
                    this.undoStack.Push(ut);

                    RaiseUndoRedoHappened(this.state, ut);

                    --count;
                }
            }
        }