Class
EMFCommand
Protocol defining a command that can be executed, undone, and redone.
@MainActor class EMFCommand
Overview
EMF commands encapsulate model modifications in a reversible manner, enabling undo/redo functionality and transactional operations. Commands follow the Command pattern, providing a uniform interface for all model modifications.
Overview
Commands represent atomic operations on model elements that can be:
-
Executed: Applied to modify the model state
-
Undone: Reversed to restore previous model state
-
Redone: Re-applied after being undone
All commands must be thread-safe and work correctly in concurrent environments. The execution model ensures that command operations are serialised through actors to maintain model consistency.
Command Lifecycle
-
Creation: Command is created with necessary context
-
Execution:
execute()is called to apply changes -
Undo:
undo()reverses the changes (optional) -
Redo:
redo()re-applies the changes after undo (optional)
Example Usage
let command = SetCommand(
object: person,
feature: nameAttribute,
value: "John Doe"
)
let result = try await command.execute()
try await command.undo() // Reverses the change
try await command.redo() // Re-applies the change
Subclassing
Concrete commands should inherit from this base class and override the necessary methods. The base class provides default implementations that can be overridden as needed.
Topics
Initializers
Initialise a new command.
Instance Properties
Indicates whether the command can be redone after being undone.
Indicates whether the command can be undone.
A human-readable description of the command.
Instance Methods
Relationships
Inherited By
Conforms To
See Also
Commands and Editing
Actor managing the execution and undo/redo history of EMF commands.
Actor providing basic editing domain functionality for model modification coordination.