[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: NSPanel and modal run loop
From: |
Ivan Vučica |
Subject: |
Re: NSPanel and modal run loop |
Date: |
Thu, 13 Jun 2013 00:33:59 +0200 |
I'd explicitly bind escape to the Cancel button; I think Apple's Interface Builder does that when you type string "Cancel" as the title.
Also, doesn't the NSPanel already have performClose:? Shouldn't your -cancelPressed: look like this?
- (IBAction)cancelPressed:(id)sender
{
[panel performClose:sender];
[NSApp stopModalWithCode:NSAlertAlternateReturn];
}
I think I read somewhere in Apple docs that they discourage direct calls upon -close, because -performClose: theoretically allows additional checks to be done, while -close closes the window immediately.
It may also be notable that NSSavePanel.m from GNUstep contains this function -- is the order of the calls the key thing here?
- (void) cancel: (id)sender
{
ASSIGN(_directory, pathToColumn(_browser, [_browser lastColumn]));
[self _updateDefaultDirectory];
[NSApp stopModalWithCode: NSCancelButton];
[_okButton setEnabled: NO];
[self close];
}
In a Mac app, I'd look into window-modal sheets instead of application-modal windows. Also, most of the time, one can and should avoid application-modal windows of any kind, as Wolfgang already mentioned. What does this particular panel do?
On Wed, Jun 12, 2013 at 9:39 AM, Riccardo Mottola
<riccardo.mottola@libero.it> wrote:
Hi,
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.
Thus I think my code is somehow incorrect, however on GNUstep I notice
1) it works? I can close the panel without problems
2) esc doesn't close the panel, even if the Apple doc says it should.
"If a panel is the key window and has a close button, it closes itself when the user presses the Escape key."
Riccardo
_______________________________________________
Discuss-gnustep mailing list
Discuss-gnustep@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnustep
--