Re: Using alerts with Preference Panes
Re: Using alerts with Preference Panes
- Subject: Re: Using alerts with Preference Panes
- From: Pete Gontier <email@hidden>
- Date: Thu, 16 Dec 2004 09:22:38 -0800
circa Thu, 8 May 2003 18:54:23 +0200 (MEST), Andreas Schempp wrote:
>> I'm creating a preference pane, and I need an alert to show up if user
>> information was incorrectly supplied. I tried using the NSBeginAlertSheet
>> with my sample application and it worked fine, but when I moved the code over
>> to my preference pane, the compiler did not seem to recognize my NSWindow
>> (_window or a new outlet for window).
> You can't attach the alert panel to your window, because System
> Preferences.app takes the view from your window and attaches it to it's own.
> Use [NSApp mainWindow]. This works.
Unfortunately, it did not make any difference for me. I too am attempting to
post sheets onto the System Preferences window. I have a view in the window
which I keep track of only so that I can call its window method to get a
value I can pass to sheet-oriented methods. When I pass this value to the
beginSheetForDirectory method of NSSavePanel or NSOpenPanel, everything
works fine. However, when I pass this value to NSBeginAlertSheet, some truly
weird stuff happens. I get a stand-alone alert instead of a sheet, and the
System Preferences window disappears. I think the window is being hidden;
selecting it from the Windows menu shows it again. Below please find an
excerpt from the code. Note the first GOTTEN/USED sequence works but the
second does not.
- (void) onNotificationSavePresetIntoFile : (NSDictionary *) messageEnvelope
{
// blah blah blah
NSWindow * window = [fTabs window]; // ***** GOTTEN
Assert (window);
NSSavePanel * savePanel = [NSSavePanel savePanel];
Assert (savePanel);
// blah blah blah
[savePanel beginSheetForDirectory : nil
file : presetName
modalForWindow : window // ***** USED
modalDelegate : self
didEndSelector :
@selector (savePreset:returnCode:contextInfo:)
contextInfo : [presetData retain] ];
};
- (void) savePreset : (NSSavePanel *) sheet
returnCode : (int) returnCode
contextInfo : (NSData *) contextInfo
{
@try
{
// blah blah blah
}
@catch (NSException * exception)
{
[exception spawnAlertSheetInto : [fTabs window] // ***** GOTTEN
modalDelegate : self];
}
}
- (void) spawnAlertSheetInto : (NSWindow *) parentWindow
modalDelegate : (id) modalDelegate
{
// blah blah blah
SpawnLocalizedAlertSheet
(parentWindow,modalDelegate,name,reason,nil,nil,nil,nil);
}
static void SpawnLocalizedAlertSheet ( NSWindow * window,
id modalDelegate,
NSString * title,
NSString * message,
NSString * defaultButton,
NSString * alternateButton,
NSString * otherButton,
SEL actionSelector )
{
// blah blah blah
NSBeginAlertSheet ( localizedTitle,
localizedButtonDefault,
localizedButtonAlternate,
localizedButtonOther,
window, // ***** USED
modalDelegate,
nil,
actionSelector,
nil,
localizedMessage );
}
--
Pete Gontier
http://www.m-audio.com/
_______________________________________________
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