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.
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.
There are several informational properties:
The constructor produces an empty UndoManager with no transaction history.
Gets or sets the maximum number of transactions that this undo manager will remember. When a transaction is committed and the number exceeds this value, the UndoManager will discard the oldest transaction(s) in order to meet this limit. The initial value is 999. Any new value must be an integer. A negative value is treated as if there were no limit. A zero value will not remember any Transactions in the history, but will allow commits and rollbacks to occur normally, including raising "Transaction" type ChangedEvents.
This property is useful in helping limit the memory consumption of typical applications. But this does not limit the number of ChangedEvents that are recorded, because there may be an unlimited number of those within each Transaction. Decreasing this value will not necessarily remove any existing Transactions if there currently exist more in history than the new value permits.
This read-only property returns an iterator for all of the Models that this UndoManager is handling.
This read-only property returns a stack of ongoing transaction names. The outermost transaction name will be the first item in the list. The last one will be the name of the most recent (nested) call to startTransaction.
You should not modify this List.
This read-only property returns the current transaction level. The value is zero when there is no ongoing transaction. The initial value is zero. startTransaction will increment this value; commitTransaction or rollbackTransaction will decrement it. When this value is greater than zero, canUndo and canRedo will be false, because additional logically related model change events may occur.
Make sure this UndoManager knows about a Model for which it may receive ChangedEvents when the given Model is changed. The model will also receive notifications about transactions and undo or redo operations.
You should not call this method during a transaction.
Commit the current transaction started by a call to startTransaction.
If this call stops a top-level transaction, we mark the currentTransaction as complete (Transaction.isComplete), we add the Transaction to the history list, and we return true. Committing a transaction when there have been some undos without corresponding redos will throw away the Transactions holding changes that happened after the current state, before adding the new Transaction to the history list.
true if ending a top-level transaction.
Maybe record a ChangedEvent in the currentTransaction. This calls skipsEvent to see if this should ignore the change. If skipsEvent returns false, this creates a copy of the ChangedEvent and adds it to the currentTransaction. If there is no currentTransaction, this first creates and remembers it.
This is called by CommandHandler.redo.
This will raise a "StartingRedo" ChangedEvent of type ChangedEvent.Transaction, perform the Transaction.redo on the transactionToRedo, and then raise a "FinishedRedo" ChangedEvent of type ChangedEvent.Transaction. The two ChangedEvents are to let model listeners know that a redo is about to take place and that it just finished. isUndoingRedoing will temporarily be set to true during this operation.
Rollback the current transaction started by a call to startTransaction, undoing any changes.
true if ending a top-level transaction.
a short string describing the transaction, pushed onto the nestedTransactionNames stack.
true if starting a top-level transaction.
This is called by CommandHandler.undo.
This will raise a "StartingUndo" ChangedEvent of type ChangedEvent.Transaction, perform the Transaction.undo on the transactionToUndo, and then raise a "FinishedUndo" ChangedEvent of type ChangedEvent.Transaction. The two ChangedEvents are to let model listeners know that an undo is about to take place and that it just finished. isUndoingRedoing will temporarily be set to true during this operation.