UndoManager class

An UndoManager observes and records model and diagram changes in transactions and supports undo/redo operations. You will need to set the #isEnabled property to true in order for the UndoManager to record changes and for users to perform an undo or a redo.

Typically an operation will call #startTransaction, make some changes to the Model and/or Diagram, and then call #commitTransaction. Any ChangedEvents that occur will be recorded in a Transaction object. If for some reason you do not wish to complete the transaction successfully, you can call #rollbackTransaction instead of #commitTransaction.

For convenience the Diagram#commit and Model#commit methods execute a function within a transaction and then perform a commit, or else a rollback upon an error.

The #history property is a list of Transactions. #commitTransaction will add the #currentTransaction to the #history list. #rollbackTransaction will undo the changes remembered in the #currentTransaction and then discard it, without changing the #history. You can limit how many transactions are remembered in the history by setting #maxHistoryLength.

Transactions may be nested. Be sure to call either #commitTransaction or #rollbackTransaction for each call to #startTransaction. Avoid repeated start-commit-start-commit calls as a result of a user's actions. Instead, start, make all changes, and then commit.

If you want to restore the diagram to the state before the latest complete transaction, call #undo. Call #redo to change the diagram to a later state. If after some number of undo's you start a transaction, all of the history after the current state is discarded, and a new transaction may be recorded. You cannot undo or redo during a transaction.

Initially each Model has its own UndoManager. UndoManagers may be shared by multiple Models by replacing the standard Model#undoManager created by the model constructor.

There are several informational properties:

  • #isInTransaction is true when a top-level transaction has been started that has not yet been committed or rolled-back.
  • #currentTransaction holds the flattened list of all ChangedEvents that have happened within the current transaction.
  • #transactionLevel indicates the current depth of nesting.
  • #nestedTransactionNames holds the stack of transaction names supplied to #startTransaction calls.
  • #history holds only complete top-level transactions.
  • #isUndoingRedoing is true during a call to #undo or #redo.
  • #historyIndex indicates which Transaction in the #history is the next to be "undone"; this is decremented by each undo and incremented by each redo.
  • #transactionToUndo and #transactionToRedo indicate which Transaction may be undone or redone next, if any.
  • #models returns an iterator over all of the Models that this UndoManager is handling.

A transaction may not be ongoing when replacing a Diagram#model, because it would not make sense to be replacing the UndoManager (the Model#undoManager) while changes are being recorded.

Replacing a Diagram#model copies certain properties from the old UndoManager to the new one, including #isEnabled and #maxHistoryLength.

Available extensions
Annotations
  • @JS()
  • @staticInterop

Constructors

UndoManager()
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited