Undo is a required feature in modern applications. Gaphor is no exception. Having an undo function in place means you can change the model and easily revert to an older state.
Overview of Transactions#
The recording and playback of changes in Gaphor is handled by the the Undo
Manager. The Undo Manager works transactionally.
A transaction must succeed or fail as a complete unit. If
the transaction fails in the middle, it is rolled back. In Gaphor this is
achieved by the
transaction module, which provides a context manager
a decorator called
When transactions take place, they emit event notifications on the key transaction milestones so that other services can make use of the events. The event notifications are for the begin of the transaction, and the commit of the transaction if it is successful or the rollback of the transaction if it fails.
Start of a Transaction#
Transactionobject is created.
TransactionBeginevent is emitted.
UndoManagerinstantiates a new
ActionStackwhich is the transaction object, and adds the undo action to the stack.
Nested transactions are supported to allow a transaction to be added inside of another transaction that is already in progress.
TransactionCommitevent is emitted
UndoManagercloses and stores the transaction.
TransactionRollbackevent is emitted.
UndoManagerplays back all the recorded actions, but does not store it.