The problem in the title is exactly what happens with me. One I select the desired file, the open panel dialog becomes unselectable, but keeps above all the other windows. I will explains further:
With a menu item in my app, I launch a configuration window in that way:
-(void)launchConfigurationWindow
{
[self loadInfo];
[self makeKeyAndOrderFront:nil];
[NSApp runModalForWindow:self];
if (abortConfigurationOperation) return;
[self saveInfo];
}
And that window may be closed with a Finish or a Cancel button:
-(IBAction)finishButtonPressed:(id)sender
{
abortConfigurationOperation = false;
[self orderOut:self];
[NSApp stopModal];
}
-(IBAction)cancel:(id)sender
{
abortConfigurationOperation = true;
[self orderOut:self];
[NSApp stopModal];
}
In that window, I have an Advanced button, to show an Advanced window. That's how I call it:
-(void)launchAdvancedWindow
{
[self loadAdvancedInfo];
[self makeKeyAndOrderFront:nil];
[NSApp runModalForWindow:self];
if (!abortAdvancedConfigurationOperation)
{
[self saveInfo];
}
}
-(IBAction)finishButtonPressed:(id)sender
{
abortAdvancedConfigurationOperation = false;
[self orderOut:self];
[NSApp stopModal];
}
-(IBAction)cancelButtonPressed:(id)sender
{
abortAdvancedConfigurationOperation = true;
[self orderOut:self];
[NSApp stopModal];
}
And in the Advanced window, I have a button that calls a NSOpenPanel to select a file, and that's where the problem is:
-(IBAction)selectNewFile:(id)sender
{
NSOpenPanel* openDlg = [NSOpenPanel openPanel];
[openDlg setCanChooseFiles:YES];
[openDlg setTreatsFilePackagesAsDirectories:YES];
[openDlg setAllowsMultipleSelection:NO];
[openDlg setTitle:NSLocalizedString(@"Select file",nil)];
[openDlg setCanChooseDirectories:NO];
if ([openDlg runModal] == NSOKButton)
{
NSString* newFile = [(NSURL*)[[openDlg URLs] firstObject] path];
[self.filePathField setStringValue:newFile];
}
}
While self.filePathField
is filled with newFile
, the panel doesn't go away; it just keeps there, above all the other windows, unselectable. The only way to close it is pressing the Cancel/Finish button of the Advanced window and the Cancel/Finish button of the Configuration window, or closing the app.
I suppose it's related with modals, but I have no idea of how to solve it, nor I know the exact cause.
EDIT: I just need a solution for that problem, even if that means not using modals for the Configuration and Advanced windows, but I would need something with an equivalent effect.
Which means that: when my app is the one in focus and the Advanced window is opened, it should be above the other windows, and the main window of my app should be unselectable; the same applies to the Configuration window when the Advanced window isn't opened. Also, the NSOpenPanel dialog (which is called in the Advanced window) should work normally.
EDIT 2: One more detail: If a open the Advanced window, open another program and then go back to my app, the Configuration window keeps itself in the front, keeping the Advanced window behind it.
EDIT 3: Another detail: If I close the Advanced window (Cancel or Finish button), the 'Advanced' button keeps looking pressed.