[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: NSPanel and modal run loop
From: |
Wolfgang Lux |
Subject: |
Re: NSPanel and modal run loop |
Date: |
Wed, 12 Jun 2013 10:00:36 +0200 |
Am 12.06.2013 um 09:39 schrieb Riccardo Mottola:
> I have a simple controller which should display a modal panel, decoded from a
> nib/gorm interface file (for reference GetNameController.m in FTP in GAP).
>
> the controller has this method:
> -(NSInteger)runAsModal
> {
> NSInteger result;
>
> [panel makeFirstResponder: textField];
> result = [NSApp runModalForWindow: panel];
> return result;
> }
>
> and each ok/cancel button does:
> -(IBAction)cancelPressed:(id)sender
> {
> [panel close];
> [NSApp stopModalWithCode: NSAlertAlternateReturn];
> }
>
> looks simple and it should work, doesn't it? Well, Almost.
>
> On the mac, the following may happen: the user hits the "close" button of the
> window or hits "esc". In that case, the panel disappears, but the app is
> still in the modal run loop (all interfaces disabled). The only thing I can
> do is terminate the application.
> I guess instead that I should be able to trap that closure and return either
> NSAlertAlternateReturn or NSAlertErrorReturn. What do you think? and how? I
> tried to implement "performClose" but it doesn't get called in the delegate.
If possible, you should not be using an application modal dialog at all.
If that's not possible, you probably should remove the close button from the
modal dialog and set Esc as key equivalent of the Cancel button.
Wolfgang