コード例 #1
0
        /// <summary>
        /// Performs requested amount of undo operation and places the transactions on the redo stack.
        /// UNDONE: What if there is a currently opened transaction?
        /// </summary>
        /// <param name="count">The number of undo operations to perform. At the end of the operation, requested number of visible
        /// transactions are undone. Hence actual number of transactions undone 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 undone, hidden transactions left on top the stack are undone as well until a
        /// visible or linked transaction is encountered or stack is emptied totally.
        /// </remarks>
        public void Undo(int count)
        {
            if (count <= 0)
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentUICulture, "Strings.RedoAndUndoAcceptOnlyPositiveCounts", "Undo", count), "count");
            }

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

            TextUndoHistoryState originalState = this.state;

            this.state = TextUndoHistoryState.Undoing;
            using (new AutoEnclose(delegate { this.state = originalState; }))
            {
                while (count > 0)
                {
                    if (!this.undoStack.Peek().CanUndo)
                    {
                        throw new InvalidOperationException("Strings.CannotUndoRequestedPrimitiveFromHistoryUndo");
                    }

                    ITextUndoTransaction ut = this.undoStack.Pop();
                    ut.Undo();
                    this.redoStack.Push(ut);

                    RaiseUndoRedoHappened(this.state, ut);

                    --count;
                }
            }
        }
コード例 #2
0
ファイル: MockTextUndoHistory.cs プロジェクト: wasya2009/PTVS
        /// <summary>
        /// Performs requested amount of undo operation and places the transactions on the redo stack.
        /// UNDONE: What if there is a currently opened transaction?
        /// </summary>
        /// <param name="count">The number of undo operations to perform. At the end of the operation, requested number of visible
        /// transactions are undone. Hence actual number of transactions undone 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 undone, hidden transactions left on top the stack are undone as well until a
        /// visible or linked transaction is encountered or stack is emptied totally.
        /// </remarks>
        public void Undo(int count)
        {
            if (count <= 0)
            {
                throw new ArgumentException("count must be > 0", nameof(count));
            }

            if (!IsThereEnoughVisibleTransactions(_undoStack, count))
            {
                throw new InvalidOperationException("Not enough undos/redos on the stack");
            }

            TextUndoHistoryState originalState = _state;

            _state = TextUndoHistoryState.Undoing;
            using (new AutoEnclose(delegate { this._state = originalState; })) {
                while (count > 0)
                {
                    if (!_undoStack.Peek().CanUndo)
                    {
                        throw new InvalidOperationException("Undo cannot request primitives from stack");
                    }

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

                    RaiseUndoRedoHappened(_state, ut);

                    --count;
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Performs requested amount of undo operation and places the transactions on the redo stack.
        /// UNDONE: What if there is a currently opened transaction?
        /// </summary>
        /// <param name="count">The number of undo operations to perform. At the end of the operation, requested number of visible
        /// transactions are undone. Hence actual number of transactions undone 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 undone, hidden transactions left on top the stack are undone as well until a
        /// visible or linked transaction is encountered or stack is emptied totally.
        /// </remarks>
        public void Undo(int count)
        {
            if (count <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(count));
            }

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

            TextUndoHistoryState originalState = this.state;

            this.state = TextUndoHistoryState.Undoing;
            using (new AutoEnclose(delegate { this.state = originalState; }))
            {
                while (count > 0)
                {
                    if (!this.undoStack.Peek().CanUndo)
                    {
                        throw new InvalidOperationException("Strings.CannotUndoRequestedPrimitiveFromHistoryUndo");
                    }

                    ITextUndoTransaction ut = this.undoStack.Pop();
                    ut.Undo();
                    this.redoStack.Push(ut);

                    RaiseUndoRedoHappened(this.state, ut);

                    --count;
                }
            }
        }