Re: sheets
Re: sheets
- Subject: Re: sheets
- From: Emma Whan <email@hidden>
- Date: Tue, 3 Jun 2003 11:40:49 +1000
Although you are probably not meant to do this, if you want to prevent
your app from executing while the sheet is on screen and continue
execution exactly where you left off when the user dismisses the sheet,
you can do so.
You simply call [NSApp runModalForWindow:yourSheet] right after you
display the sheet. In your sheetDidEnd method you then call [NSApp
stopModal]. You should not use this approach with a document-based app
though as it would prevent the user from doing anything in other
document windows. Another downside to doing this is that your main
window's close and miniaturize buttons will be disabled after the sheet
is dismissed (a Cocoa bug?), so you have to manually re-enable them.
So when you want to display the sheet, you can use code like this:
[NSApp beginSheet:mySheet modalForWindow:myWindow modalDelegate:self
didEndSelector:@selector(mySheetDidEnd:returnCode:contextInfo:)
contextInfo:nil];
[NSApp runModalForWindow:mySheet];
Your sheetDidEnd method could look like this:
- (void)mySheetDidEnd: (NSWindow *)sheet returnCode: (int)returnCode
contextInfo: (void *)contextInfo
{
[NSApp stopModal];
//re-enable close and miniaturize buttons as these are disabled
after the sheet disappears
NSButton *closeButton = [myWindow
standardWindowButton:NSWindowCloseButton];
NSButton *miniaturizeButton = [myWindow
standardWindowButton:NSWindowMiniaturizeButton];
[closeButton setEnabled:YES];
[miniaturizeButton setEnabled:YES];
}
You will still, of course, have to order out the sheet when the user
clicks the OK button or whatever in your sheet
[mySheet orderOut: sender];
[NSApp endSheet:mySheet];
On Tuesday, June 3, 2003, at 06:32 AM,
email@hidden wrote:
>
On Monday, Jun 2, 2003, at 13:37 US/Eastern, Brent Gulanowski wrote:
>
>
> Not a specific question, more one of strategies. I have been playing a
>
> bit with sheets, and have become confused by how to cope with their
>
> asynchronous nature. I feel that I am losing the thread of my workflow
>
> when I post a sheet and the method returns immediately. I know that it
>
> calls another method when it ends, but I am confused in that it seems
>
> like I suddenly have two threads of execution when I only want one.
>
> The method that called the sheet cannot do anything else, at least not
>
> related to the sheet's purpose, so when it returns, where does
>
> execution continue from? When the onEnd method returns, where does it
>
> go?
>
>
There are no threads involved, when the method that begins the sheet
>
returns, you simply return to the normal event processing (this is what
>
allows you to put a sheet on one window, but still accept events in
>
other windows.
>
>
>
> Or should I just continue going about my business from there? But it
>
> seems that the sheet does not completely get dismissed until the onEnd
>
> method returns, which means the sheet hangs there, waiting. That looks
>
> stupid and annoys the user, so I want to return from the onEnd method
>
> ASAP.
>
>
Call orderOut: on the sheet in your method to remove it from the screen
>
before you return.
>
>
> But how do I get back to doing whatever process I needed to do? Where
>
> does execution go? I guess normally it goes back to the event loop,
>
> and waits for a user event. The only solution I have come up with is
>
> that I can post a notification in the onEnd method and pick it up
>
> somewhere else in my document object. Seems awkward, seeing as how I
>
> already had the execution thread before I called the sheet.
>
>
--
>
http://homepage.mac.com/clarkcox3/
>
email@hidden
>
Clark S. Cox, III
_______________________________________________
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.