On 05/12/2009, at 2:19 AM, Mike Abdullah wrote:

> NSUndoManager works something like this:
> 
> 1. The first time an action is registered, an undo group begins.
> 
> 2. The group is scheduled to be closed using -[NSRunLoop 
> performSelector:target:argument:order:modes:]. See the constants section of 
> NSUndoManager for a little more detail.
> 
> As simple as that :)


OK, that would appear to be the most obvious way to implement it.

However, what about the bug where opening and closing a group but doing nothing 
in between creates a bogus empty undo task?  This comes into play when grouping 
things that occur over a series of events, for example mouse drags. It would be 
nice if I could just open a group on mouse down, and close it on mouse up. 
Depending on what the mouse actually does, it might not submit any undoable 
tasks to the undo manager. So this bug means that case has to be detected and 
the undo stack cleaned up. Ultimately this is the problem I'm trying to 
workaround - you would not believe how complicated it can get.

A related issue to the above is that if the mouse operation throws an exception 
(it generally shouldn't, but it can happen), the same group close and clean up 
has to be done. Otherwise Undo simply stops working because of the group 
imbalance.

It's really troublesome because so much of what's going on inside NSUndoManager 
is opaque to the app, debugger and everything else. And what's going on is 
definitely weird - like calling -endUndoGrouping and having the level stuck at 
1 before and after.

I've had so much grief with the UM that I'm basically prepared to write my own 
- in fact I have it 99% working now (passes all its unit tests) just need to 
see if it will work in a real situation.

--Graham


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to