Exemplo n.º 1
0
 public void Undo(int count)
 {
     if (count < 0)
     {
         throw new ArgumentOutOfRangeException(nameof(count));
     }
     if (!(currentTransaction is null))
     {
         throw new InvalidOperationException();
     }
     if (State != TextUndoHistoryState.Idle)
     {
         throw new InvalidOperationException();
     }
     if (count > undoList.Count)
     {
         throw new ArgumentOutOfRangeException(nameof(count));
     }
     State = TextUndoHistoryState.Undoing;
     for (int i = 0; i < count; i++)
     {
         var transaction = undoList[undoList.Count - 1];
         undoList.RemoveAt(undoList.Count - 1);
         redoList.Add(transaction);
         transaction.Undo();
         UndoRedoHappened?.Invoke(this, new TextUndoRedoEventArgs(TextUndoHistoryState.Undoing, transaction));
     }
     State = TextUndoHistoryState.Idle;
 }
Exemplo n.º 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;
                }
            }
        }
Exemplo n.º 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 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;
                }
            }
        }
Exemplo n.º 4
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;
                }
            }
        }
Exemplo n.º 5
0
        internal void Undo(int count)
        {
            try
            {
                count  = Math.Min(_undoStack.Count, count);
                _state = TextUndoHistoryState.Undoing;
                for (var i = 0; i < count; i++)
                {
                    var current = _undoStack.Peek();
                    if (!current.CanUndo)
                    {
                        throw new InvalidOperationException();
                    }
                    _undoStack.Pop();
                    current.Undo();
                    _redoStack.Push(current);

                    RaiseUndoRedoHappened();
                }
            }
            finally
            {
                _state = TextUndoHistoryState.Idle;
            }
        }
Exemplo n.º 6
0
 public UndoHistoryImpl(UndoHistoryRegistryImpl undoHistoryRegistry) {
     _currentTransaction = null;
     UndoHistoryRegistry = undoHistoryRegistry;
     _undoStack = new Stack<ITextUndoTransaction>();
     _redoStack = new Stack<ITextUndoTransaction>();
     _activeUndoOperationPrimitive = null;
     _state = TextUndoHistoryState.Idle;
 }
Exemplo n.º 7
0
        private void RaiseUndoRedoHappened(TextUndoHistoryState state, ITextUndoTransaction transaction)
        {
            EventHandler <TextUndoRedoEventArgs> undoRedoHappened = UndoRedoHappened;

            if (undoRedoHappened != null)
            {
                undoRedoHappened(this, new TextUndoRedoEventArgs(state, transaction));
            }
        }
Exemplo n.º 8
0
 public UndoHistoryImpl(UndoHistoryRegistryImpl undoHistoryRegistry)
 {
     this.currentTransaction           = null;
     this.UndoHistoryRegistry          = undoHistoryRegistry;
     this.undoStack                    = new Stack <ITextUndoTransaction>();
     this.redoStack                    = new Stack <ITextUndoTransaction>();
     this.activeUndoOperationPrimitive = null;
     this.state = TextUndoHistoryState.Idle;
 }
Exemplo n.º 9
0
 public MockTextUndoHistory(MockTextUndoHistoryRegistry undoHistoryRegistry)
 {
     _currentTransaction           = null;
     UndoHistoryRegistry           = undoHistoryRegistry;
     _undoStack                    = new Stack <ITextUndoTransaction>();
     _redoStack                    = new Stack <ITextUndoTransaction>();
     _activeUndoOperationPrimitive = null;
     _state = TextUndoHistoryState.Idle;
 }
Exemplo n.º 10
0
 public TextUndoHistory(IPropertyOwner propertyOwner)
 {
     State            = TextUndoHistoryState.Idle;
     PropertyOwner    = propertyOwner ?? throw new ArgumentNullException(nameof(propertyOwner));
     Properties       = new PropertyCollection();
     redoList         = new List <TextUndoTransaction>();
     undoList         = new List <TextUndoTransaction>();
     readOnlyRedoList = new ReadOnlyCollection <TextUndoTransaction>(redoList);
     readOnlyUndoList = new ReadOnlyCollection <TextUndoTransaction>(undoList);
 }
Exemplo n.º 11
0
		public TextUndoHistory(IPropertyOwner propertyOwner) {
			if (propertyOwner == null)
				throw new ArgumentNullException(nameof(propertyOwner));
			State = TextUndoHistoryState.Idle;
			PropertyOwner = propertyOwner;
			Properties = new PropertyCollection();
			redoList = new List<TextUndoTransaction>();
			undoList = new List<TextUndoTransaction>();
			readOnlyRedoList = new ReadOnlyCollection<TextUndoTransaction>(redoList);
			readOnlyUndoList = new ReadOnlyCollection<TextUndoTransaction>(undoList);
		}
Exemplo n.º 12
0
        internal void Undo(int count)
        {
            try {
                count  = Math.Min(_undoStack.Count, count);
                _state = TextUndoHistoryState.Undoing;
                for (var i = 0; i < count; i++)
                {
                    var current = _undoStack.Peek();
                    current.Undo();
                    _undoStack.Pop();
                    _redoStack.Push(current);
                }

                RaiseUndoRedoHappened();
            } finally {
                _state = TextUndoHistoryState.Idle;
            }
        }
Exemplo n.º 13
0
        public void Redo(int count)
        {
            try
            {
                _state = TextUndoHistoryState.Redoing;
                for (var i = 0; i < count; i++)
                {
                    var current = _redoStack.Peek();
                    current.Do();
                    _redoStack.Pop();
                    _undoStack.Push(current);
                }

                RaiseUndoRedoHappened();
            }
            finally
            {
                _state = TextUndoHistoryState.Idle;
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Performs a redo operation and places the primitives on the redo stack, up until (and
        /// including) the transaction indicated. This is called by the linked undo transaction that
        /// is aware of the linking relationship between transactions, and it does not call back into
        /// the transactions' public Redo().
        /// </summary>
        /// <param name="transaction"></param>
        public void RedoInIsolation(MockTextUndoTransaction transaction)
        {
            TextUndoHistoryState originalState = _state;

            _state = TextUndoHistoryState.Redoing;
            using (new AutoEnclose(delegate { this._state = originalState; })) {
                if (_redoStack.Contains(transaction))
                {
                    MockTextUndoTransaction redone = null;
                    while (redone != transaction)
                    {
                        MockTextUndoTransaction ut = _redoStack.Pop() as MockTextUndoTransaction;
                        ut.Do();
                        _undoStack.Push(ut);

                        RaiseUndoRedoHappened(_state, ut);

                        redone = ut;
                    }
                }
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Performs an undo operation and places the primitives on the redo stack, up until (and
        /// including) the transaction indicated. This is called by the linked undo transaction that
        /// is aware of the linking relationship between transactions, and it does not call back into
        /// the transactions' public Undo().
        /// </summary>
        /// <param name="transaction"></param>
        public void UndoInIsolation(UndoTransactionImpl transaction)
        {
            TextUndoHistoryState originalState = _state;

            _state = TextUndoHistoryState.Undoing;
            using (new AutoEnclose(delegate { this._state = originalState; })) {
                if (_undoStack.Contains(transaction))
                {
                    UndoTransactionImpl undone = null;
                    while (undone != transaction)
                    {
                        UndoTransactionImpl ut = _undoStack.Pop() as UndoTransactionImpl;
                        ut.Undo();
                        _redoStack.Push(ut);

                        RaiseUndoRedoHappened(_state, ut);

                        undone = ut;
                    }
                }
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Performs a redo operation and places the primitives on the redo stack, up until (and
        /// including) the transaction indicated. This is called by the linked undo transaction that
        /// is aware of the linking relationship between transactions, and it does not call back into
        /// the transactions' public Redo().
        /// </summary>
        /// <param name="transaction"></param>
        public void RedoInIsolation(UndoTransactionImpl transaction)
        {
            TextUndoHistoryState originalState = this.state;

            this.state = TextUndoHistoryState.Redoing;
            using (new AutoEnclose(delegate { this.state = originalState; }))
            {
                if (this.redoStack.Contains(transaction))
                {
                    UndoTransactionImpl redone = null;
                    while (redone != transaction)
                    {
                        UndoTransactionImpl ut = this.redoStack.Pop() as UndoTransactionImpl;
                        ut.Do();
                        this.undoStack.Push(ut);

                        RaiseUndoRedoHappened(this.state, ut);

                        redone = ut;
                    }
                }
            }
        }
Exemplo n.º 17
0
 /// <summary>
 /// Initializes a new instance of <see cref="TextUndoRedoEventArgs"/>.
 /// </summary>
 /// <param name="state">The <see cref="TextUndoHistoryState"/>.</param>
 /// <param name="transaction">The <see cref="ITextUndoTransaction"/>.</param>
 public TextUndoRedoEventArgs(TextUndoHistoryState state, ITextUndoTransaction transaction)
 {
     this.state       = state;
     this.transaction = transaction;
 }
Exemplo n.º 18
0
 private void RaiseUndoRedoHappened(TextUndoHistoryState state, ITextUndoTransaction transaction) {
     EventHandler<TextUndoRedoEventArgs> undoRedoHappened = UndoRedoHappened;
     undoRedoHappened?.Invoke(this, new TextUndoRedoEventArgs(state, transaction));
 }
Exemplo n.º 19
0
        /// <summary>
        /// Performs a redo operation and places the primitives on the redo stack, up until (and 
        /// including) the transaction indicated. This is called by the linked undo transaction that
        /// is aware of the linking relationship between transactions, and it does not call back into
        /// the transactions' public Redo().
        /// </summary>
        /// <param name="transaction"></param>
        public void RedoInIsolation(UndoTransactionImpl transaction) {
            TextUndoHistoryState originalState = _state;
            _state = TextUndoHistoryState.Redoing;
            using (new AutoEnclose(delegate { this._state = originalState; })) {
                if (_redoStack.Contains(transaction)) {
                    UndoTransactionImpl redone = null;
                    while (redone != transaction) {
                        UndoTransactionImpl ut = _redoStack.Pop() as UndoTransactionImpl;
                        ut.Do();
                        _undoStack.Push(ut);

                        RaiseUndoRedoHappened(_state, ut);

                        redone = ut;
                    }
                }
            }
        }
Exemplo n.º 20
0
		public void Redo(int count) {
			if (count < 0)
				throw new ArgumentOutOfRangeException(nameof(count));
			if (currentTransaction != null)
				throw new InvalidOperationException();
			if (State != TextUndoHistoryState.Idle)
				throw new InvalidOperationException();
			if (count > redoList.Count)
				throw new ArgumentOutOfRangeException(nameof(count));
			State = TextUndoHistoryState.Redoing;
			for (int i = 0; i < count; i++) {
				var transaction = redoList[redoList.Count - 1];
				redoList.RemoveAt(redoList.Count - 1);
				undoList.Add(transaction);
				transaction.Do();
				UndoRedoHappened?.Invoke(this, new TextUndoRedoEventArgs(TextUndoHistoryState.Redoing, transaction));
			}
			State = TextUndoHistoryState.Idle;
		}
Exemplo n.º 21
0
		internal void Redo(int count) {
			try {
				count = Math.Min(_redoStack.Count, count);
				_state = TextUndoHistoryState.Redoing;
				for (var i = 0; i < count; i++) {
					var current = _redoStack.Peek();
					current.Do();
					_redoStack.Pop();
					_undoStack.Push(current);
				}

				RaiseUndoRedoHappened();
			} finally {
				_state = TextUndoHistoryState.Idle;
			}
		}
Exemplo n.º 22
0
        public void Undo(int count)
        {
            try
            {
                _state = TextUndoHistoryState.Undoing;
                for (var i = 0; i < count; i++)
                {
                    var current = _undoStack.Peek();
                    current.Undo();
                    _undoStack.Pop();
                    _redoStack.Push(current);
                }

                RaiseUndoRedoHappened();
            }
            finally
            {
                _state = TextUndoHistoryState.Idle;
            }
        }
Exemplo n.º 23
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;
                }
            }
        }