Re: unresponsive button in panel
Re: unresponsive button in panel
- Subject: Re: unresponsive button in panel
- From: publiclook <email@hidden>
- Date: Sun, 20 Jul 2003 16:37:33 -0400
On Sunday, July 20, 2003, at 03:19 PM, M. Uli Kusterer wrote:
At 18:37 Uhr +0000 20.07.2003, Brad Peterson wrote:
My problem is that the cancel button is entirely unresponsive -- no
matter how often I click it, as long as the app is in the middle of
copying a set of files, I'm stuck waiting.
I suspect this has to do with the fact that I'm doing this all in the
same thread, but I don't have a lot of choice there... I need
everything to happen synchronously (that is, in a specific order with
each piece waiting until the other is done) so that's intentional.
You have to give the OS an opportunity to process events. Several
options come to mind:
1) Somehow call an NSApplication method that checks for new user
events and processes them. I don't know whether there is such a
method, though.
2) Do the copying in a separate thread (all of it). And check a global
"cancel" variable at regular intervals, and if it is set, abort and
kill the thread. Then, in your main thread, have the "Cancel" button
set this variable to TRUE.
The choices are the following:
1)
Write your own modal loop to do the file copying as well as check for
events. See
nextEventMatchingMask:untilDate:inMode:dequeue:
- (NSEvent *)nextEventMatchingMask:(unsigned int)mask untilDate:(NSDate
*)expiration inMode:(NSString *)mode dequeue:(BOOL)flag
Returns the next event matching mask, or nil if no such event is found
before the expiration date specified by expiration. A value of nil for
expiration is equivalent to distantPast. If flag is YES, the event is
removed from the queue. See the method description for
discardEventsMatchingMask:beforeEvent: for a list of the possible
values for mask.
NSLeftMouseDownMask
NSLeftMouseUpMask
NSRightMouseDownMask
NSRightMouseUpMask
NSMouseMovedMask
NSLeftMouseDraggedMask
NSRightMouseDraggedMask
NSMouseEnteredMask
NSMouseExitedMask
NSKeyDownMask
NSKeyUpMask
NSFlagsChangedMask
NSPeriodicMask
NSCursorUpdateMask
NSAnyEventMask
The mode argument names an NSRunLoop mode that determines what other
ports are listened to and what timers may fire while NSApp is waiting
for the event. The possible modes available in the Application Kit are:
NSDefaultRunLoopMode
NSEventTrackingRunLoopMode
NSModalPanelRunLoopMode
NSConnectionReplyMode
Events that are skipped are left in the queue.
You can use this method to short circuit normal event dispatching and
get your own events. For example, you may want to do this in response
to a mouse-down event in order to track the mouse while its button is
down. In this case, you would set mask to accept mouse-dragged or
mouse-up events and use the NSEventTrackingRunLoopMode.
See Also: postEvent:atStart:, run, runModalForWindow:
See the many samples that use -nextEventMatchingMask:
untilDate:inMode:dequeue:
particularly
http://developer.apple.com/documentation/Cocoa/Conceptual/
BasicEventHandling/Tasks/HandlingMouseEvents.html
2)
write method that calls itself via
-performSelector:withObject:afterDelay: until the job is done:
- (void)runStep:(id)someArg
{
if(!done)
{
// do something like copy one file
[self performSelector:@selector(runStep:) withObject: someArg
afterDelay:0.0f];
}
}
This gives Cocoa a chance to process pending events between calls to
-runStep:.
3)
Perform the long running operation in another thread.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.