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; }
/// <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; } } }
/// <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; } } }
/// <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; } } }
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; } }
public UndoHistoryImpl(UndoHistoryRegistryImpl undoHistoryRegistry) { _currentTransaction = null; UndoHistoryRegistry = undoHistoryRegistry; _undoStack = new Stack<ITextUndoTransaction>(); _redoStack = new Stack<ITextUndoTransaction>(); _activeUndoOperationPrimitive = null; _state = TextUndoHistoryState.Idle; }
private void RaiseUndoRedoHappened(TextUndoHistoryState state, ITextUndoTransaction transaction) { EventHandler <TextUndoRedoEventArgs> undoRedoHappened = UndoRedoHappened; if (undoRedoHappened != null) { undoRedoHappened(this, new TextUndoRedoEventArgs(state, transaction)); } }
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; }
public MockTextUndoHistory(MockTextUndoHistoryRegistry undoHistoryRegistry) { _currentTransaction = null; UndoHistoryRegistry = undoHistoryRegistry; _undoStack = new Stack <ITextUndoTransaction>(); _redoStack = new Stack <ITextUndoTransaction>(); _activeUndoOperationPrimitive = null; _state = TextUndoHistoryState.Idle; }
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); }
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); }
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; } }
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; } }
/// <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; } } } }
/// <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; } } } }
/// <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; } } } }
/// <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; }
private void RaiseUndoRedoHappened(TextUndoHistoryState state, ITextUndoTransaction transaction) { EventHandler<TextUndoRedoEventArgs> undoRedoHappened = UndoRedoHappened; undoRedoHappened?.Invoke(this, new TextUndoRedoEventArgs(state, transaction)); }
/// <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; } } } }
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; }
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; } }
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; } }