Re: Undo - Redo?
Re: Undo - Redo?
- Subject: Re: Undo - Redo?
- From: Bill Cheeseman <email@hidden>
- Date: Fri, 26 Apr 2002 06:44:52 -0400
on 02-04-25 5:10 PM, Manfred Lippert at email@hidden wrote:
>
I do not understand how "Redo" in the UndoManager works.
>
I registered an Undo Operation like the Cocoa docs say. I can do undo in my
>
application without problems. But after that, the "redo" menu item is
>
enabled. But it does nothing! And I don't know how I can implement it. I
>
could not find anything about how Redo works in the Cocoa docs.
In a standard implementation of undo/redo, choosing undo invokes the undo
action you registered, applying the original values that you registered it
with, and then automatically moves the action from the undo stack to the
redo stack. Then, when you choose redo, the action is invoked again to reset
the value to the changed setting and then moves the action from the redo
stack back to the undo stack.
Often, the only thing you have to do to make all this happen is to register
the undo action with the current value, before changing the value. When I
say "with the current value," I mean with some code that acquires the
current value actively. That way, at redo time, it will again acquire the
current value actively instead of using some stored value that doesn't
change between undo time and redo time.
The hard part is correctly identifying the method and values that should be
placed on the undo stack in the first place. Sometimes it makes sense to
register the very action in which registration occurs, so that it is invoked
repeatedly with reversed values. Other times it makes sense to register some
other action for undo, which in turn registers the first action for redo.
Still other times, it makes sense to register a second action for undo,
which can register yet a third action for redo (and the third action
registers the second action for undo, leaving the first action out of the
picture). In all these cases, the "current" parameters at the time of each
registration are what should be registered for undo or redo, respectively.
It sounds like your problem may result from incorrectly setting the value to
be undone/redone when you register the action for undo. I have found that
you can run into trouble if you use a hard-coded variable, because then redo
may in fact be invoked but reset the value to its current setting instead of
the last setting. You wouldn't see a change in this case, even though the
redo action is invoked. You could set breakpoints in the debugger to see if
this is what is happening to you. Normally, undo/redo works best if you grab
the current value "actively" when registering your undo action, instead of
getting it from some stored value that won't have changed when redo time
arrives.
--
Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
http://www.quecheesoftware.com
The AppleScript Sourcebook -
http://www.AppleScriptSourcebook.com
Vermont Recipes -
http://www.stepwise.com/Articles/VermontRecipes
Croquet Club of Vermont -
http://members.valley.net/croquetvermont
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
References: | |
| >Undo - Redo? (From: Manfred Lippert <email@hidden>) |