Documentation Language: Swift

Class

CommandStack

Actor managing the execution and undo/redo history of EMF commands.

@MainActor final class CommandStack

Overview

The CommandStack provides centralised command execution with full undo/redo capabilities. It maintains separate stacks for undo and redo operations, ensuring thread-safe access to command history and execution state.

Overview

The CommandStack follows a traditional undo/redo model:

Concurrency Model

The CommandStack is implemented as an actor to ensure thread-safe access to command stacks and execution state. All command operations are serialised through the actor’s message queue, preventing race conditions and ensuring consistent state transitions.

Example Usage

let commandStack = CommandStack(maxHistorySize: 100)

let result = try await commandStack.execute(setCommand)
try await commandStack.undo()  // Reverses the set command
try await commandStack.redo()  // Re-applies the set command

Topics

Initializers

?
init(maxHistorySize:)

Creates a new command stack with the specified history size.

Instance Properties

V
canRedo

Check if redo operation is possible.

V
canUndo

Check if undo operation is possible.

V
maxHistorySize

Maximum number of commands to retain in history.

V
nextRedoDescription

Get the description of the next command that would be redone.

V
nextUndoDescription

Get the description of the next command that would be undone.

V
redoStackSize

Get the current number of commands in the redo stack.

V
statistics

Current execution statistics for performance monitoring.

V
undoStackSize

Get the current number of commands in the undo stack.

Instance Methods

F
execute(_:)

Execute a command and add it to the undo stack.

F
flush()

Clear all command history.

F
getStatistics()

Get execution statistics for performance monitoring.

F
redo()

Redo the most recent undone command.

F
resetStatistics()

Reset execution statistics.

F
undo()

Undo the most recent command.

Relationships

Conforms To

See Also

Commands and Editing

C
EMFCommand

Protocol defining a command that can be executed, undone, and redone.

C
BasicEditingDomain

Actor providing basic editing domain functionality for model modification coordination.