UNDO\ REDO

Blitz3D Forums/Blitz3D Programming/UNDO\ REDO

Mathieu A(Posted 2003) [#1]
If someone know how we can do an UNDO\REDO with blitz. Because I made my own editor and I want to have this feature.

THX


Steve Hill(Posted 2003) [#2]
I don't think that Blitz is any different to any other language when it comes to implementing undo/redo. Typically what you need to do is maintain a list of the information required to undo the commands that the user has issued (e.g. the entity before the user turned it inside-out, or the line of text before they deleted it). This is made easier if you have a central place that processes all undoable actions. You really need to design it in from the outset.

I guess the way I would tackle it would be to use a type to hold the information on how to undo each action. You could then use the type's built-in list to traverse the undos as requested. If you are prepared to use the undocumented Handle and Object keywords than the list can be polymorphic with an id field to tell you how to treat a contained type. However, any aggregate datatype could be used. You could use a bank to hold the info perhaps.

Do you also want a redo? If so then you mustn't throw away the undo steps that have been undone until the user does something other than undo/redo!

Its a lot easier in an OO language.

Steve.


Mathieu A(Posted 2003) [#3]
Ok thanks steve


cyberseth(Posted 2003) [#4]
Types could be helpful here.

Every time you do an event, add a new type to the list that contains the stuff you did to make the event, the UNDO data. Whenever you undo, select the type at the bottom of the list (which is the most recent) and backtrack whatever it is that the type says you did. Then add a copy of this type to the REDO list, and delete the undo type.

Also, whenever you do a new event, clear the redo list.

-- User performs a new action.

 UNDO LIST             REDO LIST
 [ old actions ]       [ CLEARED ]
 [ old actions ]
 [ old actions ]
 [ new action ]


-- User clicks undo.

 UNDO LIST             REDO LIST
 [ old actions ]   --> [ action moved here ]
 [ old actions ]  |
 [ old actions ]  |
 [ DELETED ] -----


-- User clicks redo.

 UNDO LIST              REDO LIST
 [ old actions ]        -- [ PERFORMED and DELETED ]
 [ old actions ]       |
 [ old actions ]       |
 [ moved back here ] <-