Implementing UNDO

Paul Dupuis paul at researchware.com
Fri May 21 11:05:50 EDT 2021


As other have said, the basic mechanism is to have a UNDO LIFO (last in 
first out) queue or stack (no LC stack for a data structure stack). For 
each action you want 'undoable" you need a handler (do[action] ) to 
perform that action that also adds a record (a line) to the queue (a 
property, global variable, or script variable) that puts enough 
information in that record to undo the action. You then you have a 
corresponding undo[action] handler that can take the record from the 
queue and reverse the action.

So records on the queue might look like:

changeFont <oldFont> <newFont> <chunk>  -- which can be undone by 
setting the <chunk> to <oldFont>
resizeImage <oldSize> <newSize>
etc.

The first item tells you action was done and the subsequent items 
provide enough information to undo (or do again or redo) the action.


On 5/21/2021 10:52 AM, Klaus major-k via use-livecode wrote:
> Hi Mark,
>
>> Am 21.05.2021 um 16:42 schrieb Mark Wieder via use-livecode <use-livecode at lists.runrev.com>:
>> On 5/21/21 6:19 AM, Klaus major-k via use-livecode wrote:
>>> OK, something like this, but for graphics, images etc., too. 8-)
>>> Some general hints will be OK.
>>> Except for TEXT I don't have a clue yet.
>>> Maybe store "the properties of xyz" and re-apply them when the user hits CMD-Z?
>> I've got an undo library on livecodeshare. It's designed to handle text, but the filo stack mechanism would probably work if you store something other than text as blobs. Untested, but maybe. My guess is this would use up memory rapidly.
>> ...and from experience, don't try to compress/decompress arrays.
> thank you, will download and check the stack.
>
>> -- 
>> Mark Wieder
>> ahsoftware at gmail.com
> Best
>
> Klaus
>
> --
> Klaus Major
> https://www.major-k.de
> https://www.major-k.de/bass
> klaus at major-k.de
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode





More information about the use-livecode mailing list