Redo stack stolen
Redo stack stolen
- Subject: Redo stack stolen
- From: Bill Cheeseman <email@hidden>
- Date: Mon, 11 Apr 2005 18:24:47 -0400
I have a Replace button. Its action method calls -replaceItems:inItems:,
shown below, then sets the undo action name to "Replace Items".
- (void) replaceItems:(NSArray *)outItems withItems:(NSArray *)inItems {
[myMutableArray removeObjectsInArray:outItems];
[myMutableArray addObjectsFromArray:inItems];
[[myUndoManager prepareWithInvocationTarget:self] replaceItems:inItems
withItems:outItems];
}
Notice that the last statement records the same method for undo but with its
parameters reversed. This is a standard way to handle undo when replacing.
This code works almost all the time. Monitoring
NSUndoManagerCheckpointNotification, I see that -canUndo is true immediately
after the last statement in the above method. It is also true when I click
the Edit menu (and the Undo menu item is enabled and titled "Undo Replace
Items", and Undo works).
But this code doesn't work when outItems contains certain information. In
that case, -canUndo is true immediately after the last statement in the
above method. However, it has changed to false by the time I click the Edit
menu (and the Undo menu item is dimmed and titled simply "Undo", and of
course it doesn't work since I can't click it). The -canUndo method also
returns false if I press Cmd-Z to Undo.
Who stole my redo stack between recording the undo action and opening the
Edit menu?
More precisely, what does Cocoa do between the time when the undo action is
recorded and the time when I open the Edit menu?
Somehow, Cocoa becomes aware of the contents of outArray during this
interval, and the undo mechanism fails when those contents satisfy certain
failure conditions. I know that -[NSUndoManager forwardInvocation:] gets
called. Could it be doing something that would lead to failure?
(I asked this question over the weekend without getting a response. This
time I've made it simpler.)
--
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