For Correct Redo Action Name: Undo Method must be Dedicated?
For Correct Redo Action Name: Undo Method must be Dedicated?
- Subject: For Correct Redo Action Name: Undo Method must be Dedicated?
- From: Jerry Krinock <email@hidden>
- Date: Wed, 09 Aug 2006 21:35:27 -0700
- Thread-topic: For Correct Redo Action Name: Undo Method must be Dedicated?
Apple's Undo and Redo examples only cover the trivial case where the Undo
method is the same as the Do method, with different arguments. The
nontrivial case, where the Undo method do fundamentally different things, is
explained by Bill Cheeseman in this "classic" post:
http://www.cocoabuilder.com/archive/message/cocoa/2002/7/12/61349
However, that post does not deal with getting the correctthe Action
Names....
I have two methods: add: and remove:. These methods act on an item as
their names imply.
Method Sets Undo Method Sets Undo Action Name
------ ---------------- ---------------------
add: remove: "Add"
remove: add: "Remove"
Here's what happens:
1. Run method add: Item appears. Menu says "Undo Add", Redo is disabled.
All good.
2. Click "Undo Add". Method remove: runs. Item disappears. Menu Undo is
disabled, good; but under that is "Redo Remove". ARGGHHH!! It should say
"Redo Add".
3. Click "Redo Remove" (which means "Redo Add"). Method add: runs. Item
appears. Menu now says "Undo Add", Redo is disabled. All good.
4. Click "Undo Add". Method remove: runs. Item disappears. Menu now says
"Redo Remove". ARGGHHH!! We're back at step 2.
So, everything works fine except for the Redo Action Name. The obvious
solution is to set the Undo Action Name of remove: to "Add"! This works,
but, duh, does not make sense. A better solution, which works without
writing nonsense code, is to simply not set any action name in remove:.
However, both of these solutions mean that my remove: method now give an
incorrect or empty Undo Action Name if I use it on it's own; that is, in
response to a "Remove" command.
I think that the problem is, as Bill says "each method serves as its own
redo action".
So, I'm beginning to think that, in the nontrivial case discussed by
Cheeseman, when Method A's undo selector is not Method A itself with
different arguments, but must be a different Method B, if you want to get
the correct Redo Action Names, Method B must be dedicated solely to undoing
Method A. Although, I suppose one could factor out the guts of Method B and
set (or not set) appropriate Undo Action Names in wrappers.
Is this the way "everybody" does it, or have I been staring at this problem
for too long?
Jerry Krinock
P.S. In my actual code, the Undo Method for remove: is actually a third
method, restore:. I think this may be necessary for memory management, but
it only made the above more confusing, so I omitted mention of it.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden