Yahoo! UI Library

gallery-undo  1.01

Yahoo! UI Library > gallery-undo > UndoManager
Search:
 
Filters

Class UndoManager - extends Base

Create a UndoManager to manage list of undoable actions.

Constructor

UndoManager ( config )
Parameters:
config <Object> Configuration object

Properties

_actionHandle - protected Object

The handle of the currently executed asynchronous action

_actions - protected Array

Collection of actions.

_processing - protected Boolean

Boolean, indicates if UndoManager is currently processing an action

_undoIndex - protected Number

If undo() has been not invoked, _undoIndex is the size of the current list of actions. Otherwise, it is the index of the last action that was undone.

UndoManager.ATTRS - protected static Object

Static property used to define the default attribute configuration of UndoManager.

UndoManager.NAME - static String

The identity of UndoManager.

Methods

_afterLimit

protected void _afterLimit ( params )
Invokes _limitActions in order to keep the number of actions in the list according to the limit.
Parameters:
params <Event> limitChange custom event

_initEvents

protected void _initEvents ( )
Publishes UndoManager's events

_limitActions

protected void _limitActions ( limit )
Removes actions from the list if their number exceedes the limit
Parameters:
limit <Number> The max number of actions in the list

_onAsyncRedoFinished

protected void _onAsyncRedoFinished ( action , newIndex )
Handles the completion of redo method of asynchronous action. Fires actionRedone event. Checks if newIndex is bigger than current index. If true, invokes _redoTo again, or fires redoFinished event otherwise.
Parameters:
action <Y.UndoableAction> The asynchronous action which redo method has been completed.
newIndex <Number> The new value of undoIndex

_onAsyncUndoFinished

protected void _onAsyncUndoFinished ( action , newIndex )
Handles the completion of undo method of asynchronous action. Fires actionUndone event. Checks if newIndex is less than current index. If true, invokes _undoTo again, or fires undoFinished event otherwise.
Parameters:
action <Y.UndoableAction> The asynchronous action which undo method has been completed.
newIndex <Number> The new value of undoIndex

_redoTo

protected void _redoTo ( newIndex )
Redoes all actions from current index to newIndex. In case of asynchronous action, waits until action fires redoFinished event.
Parameters:
newIndex <object> The new value of undoIndex

_undoTo

protected void _undoTo ( newIndex )
Undoes all actions from current index to newIndex. In case of asynchronous action, waits until action fires undoFinished event.
Parameters:
newIndex <object> The new value of undoIndex

add

Boolean add ( newAction )
Adds an UndoableAction to UndoManager.
Removes and cancels all actions from the current action index till the end of the list. Tries to merge the current action with the newAction, passed as parameter. If currentAction.merge(newAction) returns false, UndoManager places the newAction at the end of the list.
Fires actionAdded event if action has been added to the list, or actionMerged if newAction has been merged.
Parameters:
newAction <Y.UndoableAction> The action to be added
Returns: Boolean
True if action was added to the list. The result might be False if UndoManager was processing another (asynchronous) action.

canRedo

Boolean canRedo ( )
Checks if redo can be done. The function will return false if there are no actions in the list, current index is equal to the length of the list or UndoManager is waiting for another asynchronous action to complete.
Returns: Boolean
true if redo is possible, false otherwise

canUndo

Boolean canUndo ( )
Checks if undo can be done. The function will return false if there are no actions in the list, the current index is 0 or UndoManager is waiting for another asynchronous action to complete.
Returns: Boolean
true if undo is possible, false otherwise

destructor

protected void destructor ( )
Destructor lifecycle implementation for UndoManager class. Removes and cancels the added actions.

getRedoLabel

String getRedoLabel ( )
If redo is posible, returns the value of label property of the action to be redone.
Returns: String
The value of label property

getUndoLabel

String getUndoLabel ( )
If undo is posible, returns the value of label property of the action to be undone.
Returns: String
The value of label property

initializer

protected void initializer ( )
Publishes events and subscribes to after event for limit.

processTo

void processTo ( newIndex )
Calls undo or redo methods of the actions registered while current index is less or greater than the newIndex passed.
Parameters:
newIndex <object> The new value of undoIndex

purgeAll

void purgeAll ( )
Cancels and removes all actions from the list

purgeTo

void purgeTo ( index )
Cancels and removes actions from the end of the list (the most recent actions) to the index, passed as parameter.
Parameters:
index <Number> The index in the list to which actions should be be removed

redo

void redo ( )
Redoes the action at current index by calling its redo method. If asyncProcessing property of the action is true, UndoManager waits until action fires redoFinished event. During this time undoing/redoing and adding new actions will be suspended.

undo

void undo ( )
Undoes the action before current index by calling its undo method. If asyncProcessing property of the action is true, UndoManager waits until action fires undoFinished event. During this time undoing/redoing and adding new actions will be suspended.

Events

actionAdded

actionAdded ( event )
Signals an Y.UndoableAction has been added to list
Parameters:
event <Event.Facade> An Event Facade object with the following attribute specific properties added:
action
An Y.UndoableAction added to the list

actionCanceled

actionCanceled ( event )
Signals an action has been canceled.
Parameters:
event <Event.Facade> An Event Facade object with the following attribute specific properties added:
action
An Y.UndoableAction canceled
index
The index of the action in the list

actionMerged

actionMerged ( event )
Signals an Y.UndoableAction has been merged with another one
Parameters:
event <Event.Facade> An Event Facade object with the following attribute specific properties added:
Y.UndoableAction action
The action, accepted merge
Y.UndoableAction mergedAction
The merged action

actionRedone

actionRedone ( event )
Signals an action has been redone.
Parameters:
event <Event.Facade> An Event Facade object with the following attribute specific properties added:
action
An Y.UndoableAction redone
index
The index of the action in the list

actionUndone

actionUndone ( event )
Signals an action has been undone.
Parameters:
event <Event.Facade> An Event Facade object with the following attribute specific properties added:
action
An Y.UndoableAction undone
index
The index of the action in the list

beforeCanceling

beforeCanceling ( event )
Signals the beginning of a process in which one or more actions will be canceled.
Parameters:
event <Event.Facade> An Event Facade object

beforePurge

beforePurge ( event )
Signals the beginning of a process in which one or more actions will be purged from the list.
Parameters:
event <Event.Facade> An Event Facade object

beforeRedo

beforeRedo ( event )
Signals the beginning of a process in which one or more actions will be redone.
Parameters:
event <Event.Facade> An Event Facade object

beforeUndo

beforeUndo ( event )
Signals the beginning of a process in which one or more actions will be undone.
Parameters:
event <Event.Facade> An Event Facade object

cancelingFinished

cancelingFinished ( event )
Signals a canceling actions process has been finished.
Parameters:
event <Event.Facade> An Event Facade object

limitChange

limitChange ( event )
Fires when the value for the configuration attribute 'limit' is changed. You can listen for the event using the on method if you wish to be notified before the attribute's value has changed, or using the after method if you wish to be notified after the attribute's value has changed.
Parameters:
event <Event.Facade> An Event Facade object with the following attribute specific properties added:
prevVal
The value of the attribute, prior to it being set
newVal
The value the attribute is to be set to
attrName
The name of the attribute being set
subAttrName
If setting a property within the attribute's value, the name of the sub-attribute property being set

purgeFinished

purgeFinished ( event )
Signals the end of purge process. UndoManager cancels each action before its removing.
Parameters:
event <Event.Facade> An Event Facade object

redoFinished

redoFinished ( event )
Signals the end of redo process.
Parameters:
event <Event.Facade> An Event Facade object

undoFinished

undoFinished ( event )
Signals the end of undo process.
Parameters:
event <Event.Facade> An Event Facade object

undoIndexChange

undoIndexChange ( event )
Fires when the value for the configuration attribute 'undoIndex' is changed. You can listen for the event using the on method if you wish to be notified before the attribute's value has changed, or using the after method if you wish to be notified after the attribute's value has changed.
Parameters:
event <Event.Facade> An Event Facade object with the following attribute specific properties added:
prevVal
The value of the attribute, prior to it being set
newVal
The value the attribute is to be set to
attrName
The name of the attribute being set
subAttrName
If setting a property within the attribute's value, the name of the sub-attribute property being set

Configuration Attributes

limit - Number

Holds the maximum number of actions in UndoManager. By default the number of actions is not limited.
Default Value: 0 (unlimited)

undoIndex - Number

The index of command, that will be executed on the next call to redo(). If undo() has been not invoked, the value is the size of the current list of actions. Otherwise, it is the index of the last action that was undone.


Copyright © 2010 Yahoo! Inc. All rights reserved.