Terminate App While NSSheet Is Visible?

  • hi there.  i've noticed on some applications that it's possible to quit an
    app while an NSSheet is present, but i can't seem to correctly add this
    functionality into my own app.  an example:  open Safari > View > Customize
    Toolbar > Quit Safari.  you'll notice that the sheet ends and then safari
    terminates.  the best i can come up with is the following, but while trying
    to quit while the sheet is visible, the program returns NSBeep() instead.
    any help would be appreciated:

    #import "AppController.h"

    @implementation AppController

    - (IBAction)beginSheet:(id)sender

    {

    [NSApp beginSheet:theSheet modalForWindow:theWindow modalDelegate:nil
    didEndSelector:NULL contextInfo:NULL];

    }

    - (IBAction)endSheet:(id)sender

    {

    [NSApp endSheet:theSheet];

    [theSheet orderOut:nil];

    }

    - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)sender

    {

    if ([theSheet isKeyWindow])

    {

    NSLog (@"App Quit With Active Sheet");

    [self endSheetThenQuit];

    return NO;

    }

    else

    {

    NSLog (@"App Quit");

    return YES;

    }

    }

    - (void)endSheetThenQuit

    {

    [NSApp endSheet:theSheet];

    [theSheet orderOut:nil];

    [NSApp terminate];

    }

    @end
previous month august 2008 next month
MTWTFSS
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Go to today