dismissing sheets.
dismissing sheets.
- Subject: dismissing sheets.
- From: Tobias Sargeant <email@hidden>
- Date: Sat, 8 Feb 2003 02:02:14 +1100
I'm having some trouble with a sheet running in a modal loop.
If I call [sheet orderOut: self] and [NSApp stopModal], then everything
works,
but the sheet is lowered underneath its owner window by the stopModal
message,
which is decidedly ugly.
If I delay sending the stopModal message until inside a handler for
NSWindowDidEndSheetNotification, the sheet rolls up properly, the modal
loop
ends, but the parent window doesn't regain focus properly (close button
stays
dimmed).
If I register as a delegate for the window with the sheet, calling
exactly the
same code as inside the notification handler, the sheet rolls up
properly,
the modal loop ends, and the close button is reactivated.
Everything is good, except that I've just wasted the delegate for no
good
reason, and I'll have to use a separate member to cache the exit code
from
the sheet, because I don't think it's accessible from inside the
windowDidEndSheet: delegate method (or the notification for that
matter).
Is there any way I can have my cake and eat it too?
Toby.
For completeness sake, here's the code I'm using:
(the panels call [NSApp endSheet: self returnCode: x] when they're done)
#import "PlayerSetupPanel.h"
#import "HumanPlayerSelectionData.h"
#import "ComputerPlayerSelectionData.h"
@implementation PlayerSetupPanel
- (void)
windowDidEndSheet:(NSNotification *)notification
{
[NSApp stopModal];
}
- (void)
sheetEnded: (NSWindow *)sheet
returnCode: (int)returnCode
context: (void *)contextInfo
{
[sheet orderOut: self];
}
- (void)
awakeFromNib
{
#if 1
[self setDelegate: self];
#else
[[NSNotificationCenter defaultCenter]
addObserver: self
selector: @selector(windowDidEndSheet:)
name: NSWindowDidEndSheetNotification
Object: self
];
#endif
}
- (BOOL)
editPlayerOptions: (PlayerSelectionData *)player
{
id sheet;
if ([player isKindOfClass: [HumanPlayerSelectionData class]]) {
sheet = human_options;
} else if ([player isKindOfClass: [ComputerPlayerSelectionData
class]]) {
sheet = computer_options;
} else {
return NO;
}
[self setDelegate: self];
[NSApp beginSheet: sheet
modalForWindow: self
modalDelegate: self
didEndSelector: @selector(sheetEnded:returnCode:context:)
contextInfo: nil
];
[NSApp runModalForWindow: sheet];
return YES;
}
@end
_______________________________________________
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.