On 19/09/2008, at 2:41 AM, brodhage wrote:

I allready do. And then I call this function (within subclass of NSWindowController):

- (void)showModalDialog
{
        NSApplication *_app;
        NSWindow *_window;
        
        [self showWindow:nil];
        _app = [NSApplication sharedApplication];
        _window = [self window];
        [_app runModalForWindow:_window];
}

The modal dialog (displayed this way) blocks everything - it is not possible to close the modal dialog, hit any button or something else.

For me it seems that the NSApplication:: runModalForWindow blocks all.
So what I am searching for is to display the modal dialog without NSApplication.


I am successfully using modal Cocoa windows in a plugin inside a Carbon application.

Others have already spoken about the need for NSApplicationLoad() and setting up an autorelease pool, you definitely have to do both these things.

To display the window I do this:

//show the window
[window makeKeyAndOrderFront:nil];

//start a modal session and wait for a response
NSModalSession session = [NSApp beginModalSessionForWindow:window];
NSInteger response;
for (;;) {
        response=[NSApp runModalSession:session];
        if (response != NSRunContinuesResponse)
                break;
        //
}

//when the user exits the window, hide the window
[NSApp endModalSession:session];
[window close];

You can hook up your OK/cancel buttons something like this:

-(IBAction) ok: (id)sender
{
        [NSApp stopModal];
}
-(IBAction) cancel: (id)sender
{
        [NSApp abortModal];
}

You can then test for the return value of the NSModalSession and do whatever you want with the results.

--
Rob Keniger



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to