Undoable Commands and History Controller for the Robotlegs Framework
Undoable Commands aims to provide the most useful functions you’d need for undo/redo functionality in a gui app. I’ve successfully used in on a number of private projects.
- Keeps a linear history of executed Commands
- Rewind/Fast Forward history
- Rewrite history
- Cancellable commands
- Gets the ladies and/or gents
Fairly barebones undoable command. You can use this with your own history controller or use the classes below to gain access to history control.
The history controller that provides the interface to move forward and backward through your command history.
This command handles adding itself to a provided/injected CommandHistory object.
See the generated asdocs provided in the repository for more information
- Download the latest release swc or feel free to download the source and compile for yourself, the test cases depend on FlexUnit4.
- Include downloaded swc in your project
- Create your command which extends UndoableCommand
- Override the protected methods doExecute and undoExecute. doExecute should contain the code you want to execute when the command is fired. undoExecute should contain whatever code is needed to manually undo the actions performed by doExecute. The last line in both of these methods should be the call to super.doExecute()/undoExecute().
- Put the following lines (+ necessary imports) into your Robotlegs context:
// Create a CommandHistory to manages undo/redo history
// Events to trigger undo and redo
commandMap.mapEvent(HistoryEvent.STEP_FORWARD, StepForwardCommand, HistoryEvent);
commandMap.mapEvent(HistoryEvent.STEP_BACKWARD, StepBackwardCommand, HistoryEvent);
- Map some event to the Command you created (just like you would with any normal robotlegs command)
- Set a Button/Mediator to actually fire the HistoryEvent.STEP_FORWARD/BACKWARD events on the robotlegs event bus and you’re done! :)
Cancelling a Command
If you want to cancel a command you can call cancel() in your doExecute method and the command will not be added to the history stack (though you will have to ensure you don’t actually make any changes to your data after you do this)