Re: Best way to hook into the run loop?
Re: Best way to hook into the run loop?
- Subject: Re: Best way to hook into the run loop?
- From: Quincey Morris <email@hidden>
- Date: Fri, 4 Dec 2009 10:02:24 -0800
On Dec 4, 2009, at 07:29, Graham Cox wrote:
> 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.
Weren't you talking about this in the context of writing your own undo manager? In that case, detecting and discarding "empty" groups would be a feature of your implementation.
> 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.
If an exception is caught and handled, it's not clear why Mike's suggestion should not still work perfectly. We don't have any reason, do we, to think that a scheduled 'performSelector' is going to be interfered with by the exception? (And you would, of course, *do* the 'performSelector' immediately after opening the undo group, not later, so that it's always scheduled no matter what happens later.)
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden