Packagecom.yworks.support
Classpublic class UndoEngine
InheritanceUndoEngine Inheritance flash.events.EventDispatcher
Implements IUndoUnit

A generic support class that can manage IUndoUnit instances to support undoability.



Public Properties
 PropertyDefined By
  autoAddTimeSpan : int
The timespan in milliseconds during which two events will be merged.
UndoEngine
  currentCompoundEdit : ICompoundEdit
[read-only] Gets a possibly open current compound edit.
UndoEngine
  mergeUnits : Boolean
Whether or not this instance should try to merge newly added units.
UndoEngine
  performingRedo : Boolean
[read-only] Indicates whether this instance is currently performing a redo operation.
UndoEngine
  performingUndo : Boolean
[read-only] Indicates whether this instance is currently performing an undo operation.
UndoEngine
  redoName : String
Returns the name of the redo unit.
UndoEngine
  redoText : String
[read-only] The IUndoUnit.redoName of the next redo operation.
UndoEngine
  size : uint
The maximum size of the undo queue this instance is managing.
UndoEngine
  undoName : String
The name of the undo unit.
UndoEngine
  undoText : String
[read-only] The IUndoUnit.undoName of the next undo operation.
UndoEngine
Public Methods
 MethodDefined By
  
Adds a new IUndoUnit to the queue.
UndoEngine
  
addUnit(unit:IUndoUnit):Boolean
This implementation always returns false Allows for collapsing multiple units into one.
UndoEngine
  
beginCompoundEdit(undoName:String, redoName:String):ICompoundEdit
Begins a compound edit that will use the provided name.
UndoEngine
  
canRedo():Boolean
Determines whether this instance can currently redo its work.
UndoEngine
  
canUndo():Boolean
Determines whether this instance can currently undo its work.
UndoEngine
  
clear():void
Clears the internal queue.
UndoEngine
  
dispose():void
Frees all used resources and calls end.
UndoEngine
  
getToken():Object
Returns a token that can be used to store and compare the state of the undo queue.
UndoEngine
  
redo():void
Redoes the change that is represented by this unit.
UndoEngine
  
redoNext():void
Redoes the next IUndoUnit
UndoEngine
  
replaceUnit(unit:IUndoUnit):Boolean
This implementation always returns false Allows for collapsing multiple units into one.
UndoEngine
  
toString():String
[override]
UndoEngine
  
undo():void
Undoes all units in this queue.
UndoEngine
  
undoNext():void
Undoes the next IUndoUnit.
UndoEngine
Protected Methods
 MethodDefined By
  
onPropertyChanged(name:String, oldValue:Object, newValue:Object):void
This will trigger the corresponding PropertyChangedEvent.
UndoEngine
Events
 Event Summary Defined By
  Dispatched when the value of the performingUndo or performingRedo property changes.UndoEngine
Property Detail
autoAddTimeSpanproperty
autoAddTimeSpan:int

The timespan in milliseconds during which two events will be merged.

Setting this to 0 will effectively disable automatic merging.

The default value is 100.

This property can be used as the source for data binding.


Implementation
    public function get autoAddTimeSpan():int
    public function set autoAddTimeSpan(value:int):void
currentCompoundEditproperty 
currentCompoundEdit:ICompoundEdit  [read-only]

Gets a possibly open current compound edit.

Indicates and possibly returns the currently active ICompoundEdit that has been started using beginCompoundEdit.


Implementation
    public function get currentCompoundEdit():ICompoundEdit

See also

mergeUnitsproperty 
mergeUnits:Boolean

Whether or not this instance should try to merge newly added units.

If true this instance will try to merge using IUndoUnit.addUnit or replace using IUndoUnit.replaceUnit units in the queue.

This property can be used as the source for data binding.


Implementation
    public function get mergeUnits():Boolean
    public function set mergeUnits(value:Boolean):void
performingRedoproperty 
performingRedo:Boolean  [read-only]

Indicates whether this instance is currently performing a redo operation.

This property can be used as the source for data binding.


Implementation
    public function get performingRedo():Boolean
performingUndoproperty 
performingUndo:Boolean  [read-only]

Indicates whether this instance is currently performing an undo operation.

This property can be used as the source for data binding.


Implementation
    public function get performingUndo():Boolean
redoNameproperty 
redoName:String

Returns the name of the redo unit.

Depending on the implementation and context this might be a human readable representation of the redo action or a symbolic name that needs localization.

This property can be used as the source for data binding.


Implementation
    public function get redoName():String
    public function set redoName(value:String):void
redoTextproperty 
redoText:String  [read-only]

The IUndoUnit.redoName of the next redo operation.

This property is not bindable. Use redoName if data binding is needed.


Implementation
    public function get redoText():String
sizeproperty 
size:uint

The maximum size of the undo queue this instance is managing.

A size of 0 effectively disables this implementation.

This property can be used as the source for data binding.


Implementation
    public function get size():uint
    public function set size(value:uint):void
undoNameproperty 
undoName:String

The name of the undo unit.

Depending on the implementation and context this might be a human readable representation of the undo action or a symbolic name that needs localization.

This property can be used as the source for data binding.


Implementation
    public function get undoName():String
    public function set undoName(value:String):void
undoTextproperty 
undoText:String  [read-only]

The IUndoUnit.undoName of the next undo operation.

This property is not bindable. Use undoName if data binding is needed.


Implementation
    public function get undoText():String
Method Detail
addToQueue()method
public function addToQueue(unit:IUndoUnit):void

Adds a new IUndoUnit to the queue.

This implementation will automatically group multiple units into a single unit if the time since the last add is less than autoAddTimeSpan.

Parameters

unit:IUndoUnit — The unit of work to add.

addUnit()method 
public function addUnit(unit:IUndoUnit):Boolean

This implementation always returns false Allows for collapsing multiple units into one.

Implementation should try to incorporate the change of unit into this and if successful return true. This method will be called by the UndoEngine to collapse multiple events into single events. Typically this unit has been placed onto an undo stack and unit should be placed on top of it. Both units have been done and might be undone in an upcoming action. If this method yields true, the provided unit will not be placed onto the stack but will be IDisposable.disposed.

Parameters

unit:IUndoUnit — The unit to incorporate that happened after this unit.

Returns
Boolean — Whether the state change of unit has been incorporated into this unit and unit can be disposed of.
beginCompoundEdit()method 
public function beginCompoundEdit(undoName:String, redoName:String):ICompoundEdit

Begins a compound edit that will use the provided name.

This will create a new edit that can independently be canceled or ended. Note that only if the outer-most instance is ended, the corresponding IUndoUnit units will be enqueued into this instance.

Parameters

undoName:String — The undo name to use for the edit.
 
redoName:String — The redo name to use for the edit.

Returns
ICompoundEdit — A compound edit implemenation that needs to be canceled or ended later.
canRedo()method 
public function canRedo():Boolean

Determines whether this instance can currently redo its work.

Returns
Boolean — Whether a call to redo will succeed.
canUndo()method 
public function canUndo():Boolean

Determines whether this instance can currently undo its work.

Returns
Boolean — Whether a call to undo will succeed.
clear()method 
public function clear():void

Clears the internal queue.

dispose()method 
public function dispose():void

Frees all used resources and calls end.

getToken()method 
public function getToken():Object

Returns a token that can be used to store and compare the state of the undo queue.

E.g. an application can retrieve the token once the user has saved his document. Comparing the token returned by this instance with another one retrieved at a later point in time enables the application to determine whether the document is in the same state.

Returns
Object — An object that can be checked against other tokens via the Object.equals(Object) method.
onPropertyChanged()method 
protected function onPropertyChanged(name:String, oldValue:Object, newValue:Object):void

This will trigger the corresponding PropertyChangedEvent.

Parameters

name:String — The name of the property that changed.
 
oldValue:Object
 
newValue:Object

redo()method 
public function redo():void

Redoes the change that is represented by this unit.

This method will only succeed if canRedo yields true.

redoNext()method 
public function redoNext():void

Redoes the next IUndoUnit

replaceUnit()method 
public function replaceUnit(unit:IUndoUnit):Boolean

This implementation always returns false Allows for collapsing multiple units into one.

Implementation should try to incorporate the change of unit into this and if successful return true. This method will be called by the UndoEngine to collapse multiple events into single events. Typically unit has already been placed onto an undo stack and this should be placed on top of it. Both units have been done and might be undone in an upcoming action. If this method yields true, this unit will replace the unit on the top of the stack and unit will be IDisposable.Disposed.

Parameters

unit:IUndoUnit — The unit to incorporate that happened before this unit.

Returns
Boolean — Whether the state change of unit has been incorporated into this unit and unit can be disposed of.
toString()method 
override public function toString():String

Returns
String
undo()method 
public function undo():void

Undoes all units in this queue. Undoes the change that is represented by this unit.

This method will only succeed if canUndo yields true.

undoNext()method 
public function undoNext():void

Undoes the next IUndoUnit.

Event Detail
propertyChange Event
Event Object Type: mx.event.PropertyChangeEvent
PropertyChangeEvent.type property = mx.event.PropertyChangeEvent.PROPERTY_CHANGE

Dispatched when the value of the performingUndo or performingRedo property changes.