Window's close, miniaturize, and resize controls become disabled after running alert sheet in a modal session
Window's close, miniaturize, and resize controls become disabled after running alert sheet in a modal session
- Subject: Window's close, miniaturize, and resize controls become disabled after running alert sheet in a modal session
- From: David Thorup <email@hidden>
- Date: Thu, 8 May 2003 19:54:45 -0600
I've got a single window application and I'm trying to show a Save
alert when the user quits the application to see if they want to save
their data or not. I've set this up in the applicationShouldTerminate:
method as shown below. Basically what I do is this:
Run the alert sheet.
[NSApp runModalForWindow: theAlertSheet]
In the did-dismiss selector I do [NSApp stopModal]
Everything works, but if I cancel so that the app doesn't quit then for
some reason my main window's (the window the sheet appeared on) close,
miniaturize, and resize controls are all disabled. All the other
controls in the window's view still work, but the close, miniaturize,
and resize controls are all disabled. Is there something I'm doing
wrong? Any suggestions?
I've also tried [NSApp runModalForWindow: myMainWindow], but this
causes a flash because the sheet is already on top of the window and
the window is trying to be "made key and order front."
Thanks for any help!
-
(NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication
*)sender
{
BOOL shouldQuit = YES;
if (_saveNeeded)
{
NSBeginAlertSheet(
@"Do you want to save your changes?",
// sheet message
@"Save", // default button label
@"Don't Save", // alternate button label
@"Cancel", // otherButton label
window, // window sheet is attached to
self, // we'll be our own delegate
NULL, // did-end selector
@selector(sheetDidEndShouldSave:returnCode:contextInfo:),
// did-dismiss selector
&shouldQuit, // context info
@"Your changes will be lost if you don't save.",
// additional text
nil); // no parameters in message
[[NSApplication sharedApplication] runModalForWindow:[window
attachedSheet]];
// I've also tried this --v
// [[NSApplication sharedApplication] runModalForWindow:window];
}
if (shouldQuit)
return NSTerminateNow;
else
return NSTerminateCancel;
}
- (void)sheetDidEndShouldSave:(NSWindow *)sheet
returnCode:(int)returnCode contextInfo:(void *)contextInfo
{
BOOL* shouldQuit = contextInfo;
if (returnCode == NSAlertDefaultReturn) // Save
{
[self synchronizeDefaults:self];
*shouldQuit = YES;
}
else if (returnCode == NSAlertOtherReturn) // Cancel
*shouldQuit = NO;
else if (returnCode == NSAlertAlternateReturn) // Don't Save
*shouldQuit = YES;
[[NSApplication sharedApplication] stopModal];
}
____________________________________
Dave Thorup
Software Engineer
email@hidden
voice: 801-805-9422
www.corda.com
Interactive data driven graphics.
_______________________________________________
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.