Igor- Saturday, May 26, 2012, 7:42:31 PM, you wrote:
> How do you do it? How do you implement UNDO in your applications? > Is there a generic mechanism or technique that you use, or do you > re-invent the wheel with every project? Depends on what you want to undo. Here's what I do in an upcoming change to the glx2 script editor. Here what I'm interested in saving for later undos is the contents of the script editor field. I'm not concerned about changes to other objects. This creates a LIFO stack by setting up a new array element in the undo stack every time I save a change. The state of the script field is recovered by popping the last saved off the top of the stack. Note that not deleting the top element after popping it off the stack allows a redo as well as an undo. local sUndoPointArray /** * UndoPointer * * Return the index of the last-saved state */ private function UndoPointer local tCount put sUndoPointArray["count"] into tCount if tCount is empty then put 0 into tCount end if return tCount end UndoPointer /** * InsertUndoScript * * Save the current script for undoing later on */ private command InsertUndoScript local tCount put UndoPointer()+1 into tCount put the htmltext of field kCodeField into sUndoPointArray[tCount] put tCount into sUndoPointArray["count"] end InsertUndoScript /** * UndoRefactor * * undo the last-saved state of the text */ command UndoChange local tCount lock screen put UndoPointer() into tCount if tCount > 0 then set the htmltext of field kCodeField to sUndoPointArray[tCount] -- decrement the stack pointer put tCount-1 into sUndoPointArray["count"] end if unlock screen end UndoChange Hope this helps. -- -Mark Wieder mwie...@ahsoftware.net _______________________________________________ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode