Ejemplo n.º 1
0
 protected virtual void OnUndoRedoState()
 {
     if (UndoRedoState != null)
     {
         UndoRedoState.Invoke(this, System.EventArgs.Empty);
     }
 }
Ejemplo n.º 2
0
    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;
    }
Ejemplo n.º 3
0
    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;
    }
Ejemplo n.º 4
0
    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;
    }
Ejemplo n.º 5
0
        /// <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);
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
    private static int GetUnprocessedItemCount <T>(this UndoRedoState <T> undoRedoState)
    {
        ArgumentNullException.ThrowIfNull(undoRedoState);

        return(undoRedoState.Items.Count - undoRedoState.ProcessedItemCount);
    }
Ejemplo n.º 7
0