Re: NSAlert synchronous sheet?
Re: NSAlert synchronous sheet?
- Subject: Re: NSAlert synchronous sheet?
- From: Hamish Allan <email@hidden>
- Date: Wed, 23 Mar 2005 02:27:28 +0000
In case nobody comes up with a better solution, this one works:
- (BOOL)windowShouldClose:(id)sender
{
if ([[self windowController] moreThanOneTabShowing])
{
NSAlert *alert = [NSAlert
alertWithMessageText:@"You have multiple tabs open"
defaultButton:@"Close All Tabs"
alternateButton:@"Cancel"
otherButton:nil
informativeTextWithFormat:
@"Do you want to close all of the tabs in this window?"];
[alert beginSheetModalForWindow:self
modalDelegate:self
didEndSelector:@selector(multipleTabsAlertDidEnd:returnCode:
contextInfo:)
contextInfo:(void *)sender];
return NO;
}
else
return YES;
}
- (void)multipleTabsAlertDidEnd:(NSAlert *)alert
returnCode:(int)returnCode contextInfo:(void *)sender
{
if (returnCode == NSAlertDefaultReturn)
[self close];
}
I don't like it: I would have used performClose: instead of
shouldWindowClose: except that it isn't called when the close button is
clicked (only when such a click is to be programmatically simulated,
such as from a menu item).
NB all of this might be non-standard behaviour as this is part of a
SIMBL plugin for Safari. If anyone is interested in this functionality
(which is the deal-maker for tabbed browsing as far as I am concerned)
please let me know and I'll make it available.
Best wishes,
Hamish
On Mar 22, 2005, at 23:26, Hamish Allan wrote:
Hi,
NSAlert seems to provide two ways to run:
– runModal, for blocking application-modal dialogs, or
– beginSheetModalForWindow:modalDelegate:didEndSelector:contextInfo:,
for non-blocking document-modal sheets.
I want a blocking document-modal sheet, for an "Are you sure" type of
question in response to a windowShouldClose:, but I can see that this
would tie up the run loop and prevent other document windows from
functioning. However, it's not clear to me how to implement this
asychronously. Can anybody point me in the right direction?
Thanks,
Hamish
_______________________________________________
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