Class UndoManager

A Transaction holds a list of ChangedEvents collected during a transaction, as the value of the read-only #changes} property.

Index

Constructor methods

Properties

Methods

Constructor methods

constructor(): UndoManager

The constructor produces an empty UndoManager with no transaction history.

Returns

UndoManager

Properties

public currentTransaction: Transaction

Gets the current Transaction for recording additional model change events.

public hisotryIndex: number

Gets the index into #history for the current undoable Transaction.

public history: List

Gets the whole history, a list of all of the Transactions, each representing a transaction with some number of ChangedEvents.

public isEnabled: boolean

Gets or sets whether this UndoManager records any changes.

public isInTransaction: boolean

This property is true after the first call to #startTransaction and before a corresponding call to #commitTransaction or #rollbackTransaction.

public isUndoingRedoing: boolean

This property is true during a call to #undo or #redo.

public maxHistoryLength: number

Gets or sets the maximum number of transactions that this undo manager will remember.

public models: Iterator

Gets an iterator for all of the Models that this UndoManager is handling.

public nestedTransactionNames: List

Gets a stack of ongoing transaction names.

public transactionLevel: number

Gets the current transaction level.

public transactionToRedo: Transaction

Gets the Transaction in the #history to be redone next.

public transactionToUndo: Transaction

Gets the Transaction in the #history to be undone next.

Methods

public addModel(model: Model): any

Make sure this UndoManager knows about a Model for which it may receive ChangedEvents when the given Model is changed.

Parameters

Returns

any

public canRedo(): boolean

This predicate returns true if you can call #redo.

Returns

boolean

public canUndo(): boolean

This predicate returns true if you can call #undo.

Returns

boolean

public clear(): any

Clear all of the Transactions and clear all other state, including any ongoing transaction without rolling back.

Returns

any

public commitTransaction(tname: string): boolean

Commit the current transaction started by a call to #startTransaction. For convenience, this method is called by Model#commitTransaction and Diagram#commitTransaction. 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.

Parameters

  • tname: string

    a short string describing the transaction.

Returns

boolean

public handleChanged(e: ChangedEvent): any

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 method always ignores all changes while performing an #undo or #redo. This method is also a no-op if #isEnabled is false.

Parameters

Returns

any

public redo(): any

Re-perform this object change after an #undo.

Returns

any

public removeModel(model: Model): any

Inform this UndoManager that it will no longer be receiving ChangedEvents when the given Model is changed. The model will no longer receive notifications about transactions and undo or redo operations. You should not call this method during a transaction. If you call this method between transactions when there is a transaction history, you should be careful that there are no ChangedEvents referring to that model in any Transactions.

Parameters

  • model: Model

    A Model that this UndoManager should no longer manage.

Returns

any

public rollbackTransaction(): boolean

Rollback the current transaction started by a call to #startTransaction, undoing any changes.

Returns

boolean

public skipsEvent(e: ChangedEvent): boolean

This predicate is called by #handleChanged to decide if a ChangedEvent is not interesting enough to be remembered. Transactional events (of change type ChangedEvent#Transaction) are always skipped. Changed events for GraphObjects that are in Layer#isTemporary layers are also skipped. Sometimes changed events do not even get to #handleChanged because Model#skipsUndoManager or Diagram#skipsUndoManager is true.

Parameters

  • e: ChangedEvent

    the ChangedEvent received by #handleChanged.

Returns

boolean

public startTransaction(tname?: string): boolean

Begin a transaction, where the changes are held by a Transaction object as the value of #currentTransaction. You must call either #commitTransaction or #rollbackTransaction afterwards. For convenience, this method is called by Model#startTransaction and Diagram#startTransaction. Transactions can be nested. Starting or ending a nested transaction will return false. Nested transactions will share the same Transaction list of ChangedEvents. Starting a transaction will not necessarily cause #currentTransaction to be non-null. A Transaction object is usually only created by #handleChanged when a ChangedEvent first occurs.

Parameters

  • tname?: string optional

    a short string describing the transaction.

Returns

boolean

public undo(): any

Reverse the effects of this object change.

Returns

any