general undo methods?

Richard Gaskin ambassador at fourthworld.com
Sun Feb 20 20:33:35 EST 2005


Chipp Walters wrote:
> 
> 
> Richard Gaskin wrote:
> 
>> That's prettyt much where I'm headed now, but there's one aspect 
>> that's still problematic:  Rev's built-in undo for text editing 
>> operations is something I don't want to replicate.  For a single-level 
>> Undo it's easy enough to put a flag in the undo string to tell it to 
>> use the built-in undo command rather than any custom routine.  But how 
>> would one handle this for multi-level undo?
> 
> 
> Richard, I'm sure you've already thought of this, but why not create a 
> number of customProps in a customPropSet:
> 
> fwUndo["fred",1]
> fwUndo["fred",2]
> etc..
> 
> where 'fred' refers to a field name and the number refers to the last 
> change made.
> 
> Then each time a close field is sent to the "fred" fld, store the 
> htmlText of the field in the appropriate customProp. Then it's a simple 
> matter to find the highest number and 'undo' to the htmlText of it.
> 
> StripAndShip will kill the whole property set.
> 
> I'm sure you already thought of this, but thought I'd mention it anyway.

In general I like it, but I've gone the route of stashing undo commands 
instead of properties.  That way the undo script doesn't need to parse 
the properties to figure out what action to take, making the undo script 
smaller and opening up more flexibility fort someone as lazy as myself. :)

Another tricky aspect is one that Ken reminded me of on the phone the 
other day:  undo needs to be window-aware.  So if you do something in 
one window and move another to the front, choosing Edit-Undo shouldn't 
undo the thing in the window that no longer has focus.

Currently I'm only doing one-level undo, using an array with the stack 
name as the key.  That way I can clear the entire array at once when 
Undo is used, and until then I maintain undo code for each stack's last 
action.

-- 
  Richard Gaskin
  Fourth World Media Corporation
  ___________________________________________________________
  Ambassador at FourthWorld.com       http://www.FourthWorld.com


More information about the use-livecode mailing list