The main class to provide undo and redo functionality.
Remarks
The UndoEngine is in charge of recording, managing and executing single units of work that can be undone and redone, represented by the interface IUndoUnit.
These units are managed in a queue-like structure and can be added manually to the queue by calling the addUnit method.
Executing the units is done by client code or commands by calling undo or redo. The engine automatically manages the queue so that calling these two methods will consistently move the units in the queue.
The beginCompoundEdit method allows to record units by bracketing several changes in an ICompoundEdit. Implementations of the ICompoundEdit interface record all subsequent changes until it is committed and therefore all recorded units are added to the engine. For more information and examples see ICompoundEdit.
Depending on the properties mergeUnits and autoMergeTime, the engine tries to collapse added IUndoUnits if possible. This enhances the performance and reduces the required memory for undo changes. For example, when a node is moved interactively, instead of saving every position that the node had when being dragged the engine will only hold one IUndoUnit at the end to undo the entire movement.
Customizing Undo/Redo
- In general, to be able to undo or redo certain work client code can implement IUndoUnit or subclass UndoUnitBase. The client application needs to encapsulate changes in this implementation and provide the logic to completely undo and redo these changes. Instances of your custom IUndoUnit implementations need to be added to the UndoEngine manually via addUnit.
- In certain cases it is difficult or not efficient to track and save the changes between certain states, and better to save the states themselves and to restore these. For example when there are potentially many intermediate steps between two states of interest and it would be complicated to produce IUndoUnits for each intermediate step and merge them in the end. In such cases client code should implement IMementoSupport instead. See the documentation of IMementoSupport for examples and guidelines on how to implement this memento design pattern concept.
- It is generally not necessary to subclass UndoEngine unless you want to customize the internal handling of the units, which is both complicated and prone to errors. In most use cases it is sufficient to provide custom IUndoUnits or IMementoSupport.
Type Details
- yfiles module
- view-component
- yfiles-umd modules
- All view modules
- Legacy UMD name
- yfiles.graph.UndoEngine
See Also
Constructors
Initializes a new instance of the UndoEngine class.
Properties
Gets or sets the duration during which the engine will try to merge newly added units.
Remarks
See Also
Gets or sets a value that indicates whether or not this instance should try to merge newly added units.
Remarks
true
this instance will try to merge or replace units in the queue. Note that when the autoMergeTime property is set to ZERO and this property is set to true
, the engine will always try to merge incoming units. Otherwise the autoMergeTime dictates whether the engine will try to merge a unit or not.See Also
Methods
Adds a new IUndoUnit to the queue.
Remarks
Parameters
A map of options to pass to the method.
- unit - IUndoUnit
- The unit of work to add.
See Also
Begins a compound edit that will use the provided name.
Remarks
Parameters
A map of options to pass to the method.
- undoName - string
- The undo name to use for the edit.
- redoName - string
- The redo name to use for the edit.
Returns
Determines whether a call to redo can be made.
Determines whether a call to undo can be made.
Clears the internal queue and disposes all units in it.
Returns a token that can be used to store and compare the state of the undo queue.
Remarks
Returns
- ↪any
- An object that can be checked against other tokens via the equals method.
This will trigger the corresponding PropertyChanged event.
Parameters
A map of options to pass to the method.
- name - string
- The name of the property that changed.
Events
Occurs when canUndo, canRedo, undoName, or redoName changed its value.
Overrides
Event Registration
addPropertyChangedListener(function(this, PropertyChangedEventArgs):void)
Event Deregistration
removePropertyChangedListener(function(this, PropertyChangedEventArgs):void)
Signature Details
function(sender: any, args: PropertyChangedEventArgs)
Parameters
- sender - any
- The object which dispatched the event.
- args - PropertyChangedEventArgs
- The arguments which define the change.