Re: Prevent Asynchronous operation of beginSheetModalForWindow
Re: Prevent Asynchronous operation of beginSheetModalForWindow
- Subject: Re: Prevent Asynchronous operation of beginSheetModalForWindow
- From: Graham Cox <email@hidden>
- Date: Tue, 17 Jun 2008 11:47:14 +1000
Hi John,
Did you even read my last email? I hope so because I really spent a
long time writing it. It may not have been clear, but I did my best!
A separate SheetController *is* the right way to do it, but the way
you are partitioning the responsibilities between your various
controllers isn't right. Your FileController should not be caring one
iota about how the SheetController works, or gets its information. If
it's asking the sheet controller to "show window" it's already making
an assumption about the UI, which is none of its business.
Re-read my previous email. I explain at great length how to do this.
Whether your sheet controller is called in one place or many different
ones makes no difference. Get rid of all UI assumptions from the
caller/client code, and make sure that all of the UI-based stuff is
encapsulated in the sheet controller only. The callback to the client
can be as simple as a single integer value if you want, but make sure
that that is all it is, and you're not sneaking implementation details
out and expecting the caller to rely on something that is private to
the sheet controller.
There are also several examples of the architecture I explained in my
demo app which I linked in the previous mail.
hth,
Graham
On 17 Jun 2008, at 3:51 am, John Love wrote:
Hello, Graham ...
Because I have multiple calls to show a sheet, from various parts of
my
FileController, and because I wanted to make my sheet calls as
general as
possible, I really .. really .. wanted to have a distinct
SheetController.
As a result, I made calls from FileController to look like:[theSheet
showSheet:itsWindow], where theSheet was an outlet of FileController.
I could get away with that since all my sheets had just one
button .. except
one, which had 3 buttons .. and for that exception, the asynchronous
nature
of sheets got in the away.
I have not given up on a separate SheetController .. however .. I
finally
reduced my showSheet routine to something very, very short and
placed it in
FileController ..
- (void) showSheet: (NSWindow*)theSheet
forWindow:(NSWindow*)theWindow
withDescription:(NSString*)theDescription {
if (theDescription) {
if (theSheet == calculateSheet) {
if (calculateDescription) // NSTextField outlets of
FileController, 1 per sheet
[calculateDescription setStringValue:theDescription];
}
else if (theSheet == saveSheet) {
if (saveDescription)
[saveDescription setStringValue:theDescription];
}
else if (theSheet == errorSheet) {
if (saveDescription)
[saveDescription setStringValue:theDescription];
}
}
[NSApp beginSheet:theSheet
modalForWindow:theWindow
modalDelegate:nil
didEndSelector:nil //
@selector(sheetDidEnd:returnCode:contextInfo:)
contextInfo:nil];
itsReturnCode = [NSApp runModalForWindow:theSheet]; // (int)
itsReturnCode in FileController.h
[NSApp endSheet:theSheet];
[theSheet orderOut:self];
}
When I called showSheet, it looked like:
[self showSheet:calculateSheet forWindow:itsWindow
withDescription:nil]where calculateSheet, showSheet and errorSheet
were 3
IBOutlets of FileController, all of class = NSWindow.
Every button of each sheet was connected to a specific IBAction of
FileController, e.g.,
- (IBAction) dontSaveIt:(id)sender {
[self closeSheetWithCode:doCloseDoc];
}
with that last message looking like:
- (void) closeSheetWithCode:(int)theCode {
[NSApp stopModalWithCode:theCode];
}
As the docs explain, when you do that, the message [NSApp
runModalForWindow:] returns that identical integer, which can be any
integer
of your choosing. In my case, the integer choices trigger a decision
whether to close the mainWindow after the sheet is closed, or
whether to
keep mainWindow open after the sheet is closed.
I did not even have to mess with sheetDidEnd selectors because
closeSheetWithCode returned gave the needed flag I could use to
quantify the
itsReturnCode instance variable of FileController.
Anyway, I have sheets, not the relatively antequated separate dialogs.
I have no intention of giving up on a separate SheetController ..
but, in
the meantime, I have something that works.
_______________________________________________
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