UndoRedoActionBase Class

Base class for IUndoRedoAction implementations. It tracks whether the action is currently applied so it cannot be executed or reverted twice in a row, and delegates the actual work to UndoRedoActionBase.ExecuteCoreAsync and UndoRedoActionBase.UnExecuteCoreAsync.

public abstract class UndoRedoActionBase : IUndoRedoAction
Implements

Constructors

NameDescription
UndoRedoActionBase()

UndoRedoActionBase()

protected UndoRedoActionBase()

No documentation is available.

Properties

NameDescription
AllowToMergeWithPreviousGets a value indicating whether this action may be merged with the previous action in the undo buffer.
DescriptionGets a human-readable description of the action, for display in an undo history. Defaults to null.
IsAppliedGets a value indicating whether the action is currently applied.

AllowToMergeWithPrevious

UndoRedoActionBase.cs

Gets a value indicating whether this action may be merged with the previous action in the undo buffer.

public bool AllowToMergeWithPrevious { get; set; }

Property value

bool

Gets a human-readable description of the action, for display in an undo history. Defaults to null.

public virtual string? Description { get; set; }

Property value

string?

Gets a value indicating whether the action is currently applied.

protected bool IsApplied { get; }

Property value

bool

Methods

NameDescription
ExecuteAsync(CancellationToken)Applies the change encapsulated by this action.
ExecuteCoreAsync(CancellationToken)Contains the logic that applies the change. Called by UndoRedoActionBase.ExecuteAsync.
TryToMergeAsync(IUndoRedoAction, CancellationToken)Attempts to merge a following action into this one instead of recording it as a separate step. Useful for long chains of consecutive operations of the same kind (e.g. dragging or typing).
UnExecuteAsync(CancellationToken)Reverts the change previously applied by IUndoRedoAction.ExecuteAsync.
UnExecuteCoreAsync(CancellationToken)Contains the logic that reverts the change. Called by UndoRedoActionBase.UnExecuteAsync.

ExecuteAsync(CancellationToken)

UndoRedoActionBase.cs

Applies the change encapsulated by this action.

net10.0

public ValueTask ExecuteAsync(CancellationToken cancellationToken = default)

net11.0

public ValueTask ExecuteAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Returns

ValueTask

Exceptions

InvalidOperationException
The action is already applied. Recording the same instance twice would add an undo step that reverts nothing.

ExecuteCoreAsync(CancellationToken)

Contains the logic that applies the change. Called by UndoRedoActionBase.ExecuteAsync.

protected abstract ValueTask ExecuteCoreAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Returns

ValueTask

TryToMergeAsync(IUndoRedoAction, CancellationToken)

UndoRedoActionBase.cs

Attempts to merge a following action into this one instead of recording it as a separate step. Useful for long chains of consecutive operations of the same kind (e.g. dragging or typing).

public virtual ValueTask<bool> TryToMergeAsync(IUndoRedoAction followingAction, CancellationToken cancellationToken = default)

Parameters

followingAction IUndoRedoAction
The action recorded right after this one.
cancellationToken CancellationToken
A token to cancel the operation.

Returns

ValueTask<bool> true if followingAction was merged into this action; otherwise false.

Remarks

followingAction is in the same applied state as this action: both are already applied at the top level and inside an TransactionExecutionMode.Immediate transaction, and neither is applied inside a TransactionExecutionMode.Deferred one. An implementation must therefore absorb followingAction's effect without applying it.

Returning true discards followingAction: it is never executed nor reverted by the manager again, so this action becomes responsible for applying and reverting both effects from its own IUndoRedoAction.ExecuteAsync and IUndoRedoAction.UnExecuteAsync.

UnExecuteAsync(CancellationToken)

UndoRedoActionBase.cs

Reverts the change previously applied by IUndoRedoAction.ExecuteAsync.

net10.0

public ValueTask UnExecuteAsync(CancellationToken cancellationToken = default)

net11.0

public ValueTask UnExecuteAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Returns

ValueTask

Exceptions

InvalidOperationException
The action is not currently applied.

UnExecuteCoreAsync(CancellationToken)

Contains the logic that reverts the change. Called by UndoRedoActionBase.UnExecuteAsync.

protected abstract ValueTask UnExecuteCoreAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Returns

ValueTask