-prepareWithInvocationTarget: only fails sometimes
-prepareWithInvocationTarget: only fails sometimes
- Subject: -prepareWithInvocationTarget: only fails sometimes
- From: Bill Cheeseman <email@hidden>
- Date: Sat, 09 Apr 2005 11:09:05 -0400
I'm stuck on a perplexing undo/redo problem and could use some debugging
suggestions.
I have a pair of methods that perform inverse operations on an array of
dictionaries. Call them -deleteItems: and -undeleteItems:. Each command does
its thing to the array (deleting or undeleting some dictionary objects from
the array), then calls -prepareWithInvocationTarget: to freeze-dry the
inverse command on the undo stack or the redo stack with the same array.
Undo and Redo work as expected almost all of the time. However, if the array
happens to contain more than one dictionary and a certain entry in two of
the dictionaries is identical, the Redo menu item never gets enabled and its
Redo action name is never set. In these circumstances, I can successfully
perform the initial -deleteItems: command from the Delete button's action
method (which also sets the Undo action name), and I can successfully choose
Edit >Undo Delete Items and get the deleted items back. But the Redo Delete
Items menu item never becomes available in the Edit menu.
Debugging shows me that, after choosing Edit > Undo Delete Items and
stepping through most of the -undeleteItems: method, -isUndoing and -canRedo
both return true immediately after the -prepareWithInvocationTarget: is
called to freeze-dry the next invocation of -deleteItems:. I therefore
conclude that the redo stack has been set up correctly. But upon exit from
the -undeleteItems method, the Redo menu item doesn't get enabled and
renamed if the suspect dictionary entries are identical. (If the suspect
dictionary entries are NOT identical, then at this point the Redo menu item
does get set up correctly. The stack trace looks identical in both cases.)
I have tried wrapping the operative code within the Delete button's action
method in -beginUndoGrouping and -endUndoGrouping calls, but this makes no
difference.
What makes this especially puzzling is that I have two other cases that
exhibit the same misbehavior, one involving a differently-implemented pair
of inverse methods and one involving a single two-parameter method where I
reverse the two parameter values on Undo and Redo. In the other inverse-pair
case, instead of passing an array of dictionaries into the inverse methods
as a single parameter value, I pass in the individual dictionary entries as
separate parameter values. If one particular parameter value happens to be
identical in successive calls to these methods, the Redo menu item never
gets set up even though -isUndoing and -canRedo return true. (If the
parameters are NOT identical, successive calls properly coalesce the
commands and Redo works correctly.)
Eyeballing my code yields no clues, and I don't know where to turn next to
debug this. I can't think of any reason why identical dictionary entries or
identical parameters would prevent the Redo menu item from lighting up, when
the same code works correctly if they are not identical.
--
Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
http://www.quecheesoftware.com
PreFab Software - http://www.prefab.com/scripting.html
The AppleScript Sourcebook - http://www.AppleScriptSourcebook.com
Vermont Recipes - http://www.stepwise.com/Articles/VermontRecipes
_______________________________________________
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