protected virtual void OnUndoRedoState() { if (UndoRedoState != null) { UndoRedoState.Invoke(this, System.EventArgs.Empty); } }
public static void Do <T>(this UndoRedoState <T> undoRedoState, IEnumerable <T> items) { ArgumentNullException.ThrowIfNull(undoRedoState); ArgumentNullException.ThrowIfNull(items); var unprocessedItemCount = undoRedoState.GetUnprocessedItemCount(); if (unprocessedItemCount > 0) { undoRedoState.Items.RemoveRange(undoRedoState.ProcessedItemCount, unprocessedItemCount); } var itemList = items.ToList(); undoRedoState.Items.AddRange(itemList); undoRedoState.ProcessedItemCount += itemList.Count; }
public static void Undo <T>(this UndoRedoState <T> undoRedoState, int itemCount, Action <IReadOnlyList <T> > process) { ArgumentNullException.ThrowIfNull(undoRedoState); Assert.IsInRange(itemCount > 0); ArgumentNullException.ThrowIfNull(process); if (undoRedoState.ProcessedItemCount < itemCount) { throw new InvalidOperationException("Nincs meg a megadott darabszámú visszavonható művelet."); } var processedItemCount = undoRedoState.ProcessedItemCount - itemCount; var items = undoRedoState.Items.Take(processedItemCount).ToList(); process(items); undoRedoState.ProcessedItemCount = processedItemCount; }
public static void Redo <T>(this UndoRedoState <T> undoRedoState, int itemCount, Action <IReadOnlyList <T> > process) { ArgumentNullException.ThrowIfNull(undoRedoState); Assert.IsInRange(itemCount > 0); ArgumentNullException.ThrowIfNull(process); var unprocessedItemCount = undoRedoState.GetUnprocessedItemCount(); if (unprocessedItemCount < itemCount) { throw new InvalidOperationException("Nincs meg a megadott számú ismételhető művelet."); } var items = undoRedoState.Items.GetRange(undoRedoState.ProcessedItemCount, itemCount).ToList(); process(items); undoRedoState.ProcessedItemCount += itemCount; }
/// <summary> /// Commits the provided transaction. /// </summary> /// <param name="transaction">The transaction to commit.</param> /// <exception cref="ArgumentNullException"><paramref name="transaction"/> is a <see langword="null"/> reference.</exception> /// <exception cref="ArgumentException">The <see cref="UndoManager"/> does not contain <paramref name="transaction"/>.</exception> void ITransactionManager.CommitTransaction(IInvokableTransaction transaction) { if (transaction == null) { throw new ArgumentNullException("transaction"); } if (!this.openTransactions.Contains(transaction)) { throw new ArgumentException("Cannot find the transaction to commit", "transaction"); } // only switch the state to committing if the undo manager is not doing another task (e.g. undoing). UndoRedoState currentState = this.state == UndoRedoState.Idle ? UndoRedoState.Committing : this.state; using (new StateSwitcher(this, currentState)) { while (this.openTransactions.Contains(transaction)) { IInvokableTransaction toCommit = this.openTransactions.Pop(); if (toCommit.Any()) { if (toCommit.Equals(transaction)) { Stack <IInvokableTransaction> history = this.IsUndoing ? this.redoHistory : this.undoHistory; history.Push(transaction); } else { IInvokableTransaction topMost = this.openTransactions.Peek(); topMost.RegisterInvokation(toCommit); } } } } }
private static int GetUnprocessedItemCount <T>(this UndoRedoState <T> undoRedoState) { ArgumentNullException.ThrowIfNull(undoRedoState); return(undoRedoState.Items.Count - undoRedoState.ProcessedItemCount); }