Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implement an Undo Redo in flex

How to implement Undo Redo operation in flex 4 for maintain history? I'm working with flex UIComponent and DisplayObjects for creating and editing diagrams,but in flex there is no way to handle user operation history directly. there is any idea to achieve this?

like image 726
Devendra Avatar asked Jan 31 '13 09:01

Devendra


1 Answers

You could implement the Command Pattern for all actions with execute and undo methods, and queue them up.

so when the user wants to do some thing - lets say create an AddFiveToTotal class and executes:

public method execute():void{
     totalModel.add( 5 );
}

This class would then be stored on a FIFO queue.

if the user needs to undo the command would be popped and the undo function called:

public method undo():void{
     totalModel.subtract( 5 );
}

for redoability, don't pop, just iterate the queue

also take a look at the Memento Pattern

If you are using any of the currently popular MVC(S) frameworks you will undoubtably find a util that some one has already created

like image 194
neil manuell Avatar answered Oct 19 '22 02:10

neil manuell