Packageorg.robotlegs.utilities.undoablecommand
Classpublic class UndoableCommand
InheritanceUndoableCommand Inheritance UndoableCommandBase Inheritance Object

This command handles adding itself to the provided/injected CommandHistory. UndoableCommands are pushed to the CommandHistory only once the Command has been executed, and are removed once the Command has been undone. Undoable commands can be cancelled by calling cancel() from within their doExecute() function, and they will not be added to the history. All functions assume the CommandHistory dependency has been provided as the public property 'history'.



Public Properties
 PropertyDefined By
 InheritedeventDispatcher : IEventDispatcher
Event bus to dispatch events on.
UndoableCommandBase
  history : CommandHistory
Reference to the CommandHistory being used by this Command
UndoableCommand
Protected Properties
 PropertyDefined By
 InheritedhasExecuted : Boolean
Keeps track of whether this command has been executed, to prevent undoing commands that have not been yet been executed.
UndoableCommandBase
  isCancelled : Boolean = false
UndoableCommand
Public Methods
 MethodDefined By
  
UndoableCommand(doFunction:Function = null, undoFunction:Function = null)
UndoableCommand
  
cancel():void
Call this function in your doExecute method to prevent this item from being added to the history stack.
UndoableCommand
 Inherited
execute():void
Executes the command.
UndoableCommandBase
 Inherited
undo():void
Executes the undo function.
UndoableCommandBase
Protected Methods
 MethodDefined By
  
doExecute():void
[override] Executes the command.
UndoableCommand
  
[override] Override this function in your subclasses to implement the undo of the actions performed in doExecute().
UndoableCommand
Property Detail
historyproperty
public var history:CommandHistory

Reference to the CommandHistory being used by this Command

isCancelledproperty 
protected var isCancelled:Boolean = false

Constructor Detail
UndoableCommand()Constructor
public function UndoableCommand(doFunction:Function = null, undoFunction:Function = null)

Parameters
doFunction:Function (default = null)
 
undoFunction:Function (default = null)
Method Detail
cancel()method
public function cancel():void

Call this function in your doExecute method to prevent this item from being added to the history stack. TODO: Throw an error if cancelling within a redo. Currently assumes if the cancel condition did not fire on the first run, they will pass on subsequent executions. This is faulty.

doExecute()method 
override protected function doExecute():void

Executes the command. Override this function in your subclasses to implement your command's actions. You may call cancel() at any point in this function to prevent it from being added to the history stack, but remember that execution does not stop when you call cancel and you will need to ensure the doExecute method did not actually make any changes. Ensure you call super.doExecute() at the end of your subclassed method. Note command is only automatically pushed to history once we try to execute this command Subclasses MUST override this function with the body of their command.

See also

undoExecute
undoExecute()method 
override protected function undoExecute():void

Override this function in your subclasses to implement the undo of the actions performed in doExecute(). Ensure you call super.undoExecute() at the end of your subclassed method. Subclasses must override this function. This function should undo whatever the doExecute command did.


Throws
Error — Prevents history corruption by throwing error if trying to undo this command and it's not at the top of the history (i.e. next to be undone).

See also

doExecute