Re: Sheets to dialogs
Re: Sheets to dialogs
- Subject: Re: Sheets to dialogs
- From: John Stiles <email@hidden>
- Date: Thu, 5 Jan 2006 10:36:21 -0800
On Jan 4, 2006, at 7:32 PM, Adam Leonard wrote:
Sheets run in a "modal mode" specifically, a document-modal. The
main function of this mode is to ensure that all the events in the
application continue running except events relating to the window
it is attached to. This is different from a normal alert that
*stops* all events in the application except events relating to the
alert itself. Search the docs to learn about the specifics, but
really, thats about it.
After a bit of reflection, I think I understand what's going on now.
The problem is that calling beginModalForWindow stops the app in its
tracks. Here's what I had originally:
- (void) mySheetShowMethod // this is happening in a thread
{
[self performSelectorOnMainThread:@selector(sheetShow:)
withObject:foo waitUntilDone:YES];
}
- (void) sheetShow:(NSData*)foo
{
[parentWindow makeKeyAndOrderFront:NULL];
[NSApp beginSheet:sheet
modalForWindow:parentWindow
modalDelegate:NULL
didEndSelector:NULL
contextInfo:NULL];
}
And now I'm trying to change "sheetShow" to show a window instead (of
course, in the real code I change its name too):
- (void) sheetShow:(NSData*)foo
{
[myWindow center];
[myWindow makeKeyAndOrderFront:NULL];
[NSApp runModalForWindow:myWindow];
}
But this code doesn't work, because runModalForWindow blocks, and so
performSelectorInMainThread inside "mySheetShowMethod" blocks, and
my thread (which is supposed to be crunching numbers) is stuck
waiting for runModalForWindow to return. So basically the app hangs.
Hmm. Now that I've hashed all that out, maybe the problem was that I
needed to set "waitUntilDone" to NO in my main sheet-showing method?
That would prevent the blocking problem. (I could find another way to
block until makeKeyAndOrderFront completes, e.g. an NSLock.) Or maybe
I just won't worry about it; if I don't enter "modal" state, it's not
a big deal, since I already figured out how to disable Quit and there
are no other windows anyway.
My real concern is that beginSheet enters some sort of
(undocumented?) semi-modal state without blocking, but there's no way
to emulate that with regular window code AFAICS. I didn't want to
redesign a bunch of event processing code just to change a sheet to a
dialog, since this has always been a single-window (non-document) app.
I guess sheets also disable the "quit" menu item, but you probably
shouldn't rely on this anyway.
I didn't really realize I was relying on it until I switched to a
window and suddenly hitting Quit in the middle of an operation was
causing a crash. :)
If you want everything in the application to continue running, just
open the window like you would normally. Then to disable quit, you
probably should implement applicationShouldTerminate: and either
bring the window to the front or show an alert informing the user
that the window needs attention. Otherwise, there is really nothing
special about this.
I did this and it does seem to work, so I think that might be enough.
_______________________________________________
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