5

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.

VitorMM
  • 1,060
  • 8
  • 33
  • Does adding `[openDlg orderOut:self];` to the bottom of your `-selectNewFile:` method fix it? Also, does the compiler really let you get away with `return nil;` from `-launchConfigurationWindow`, which returns `void`? – Ken Thomases May 27 '17 at 03:34
  • 1
    Is this in a sandboxed environment? – Ssswift May 27 '17 at 17:34
  • @KenThomases adding that doesn't work. The `return nil;` was a typo of my part. I've removed the logic of my code which wasn't involved with the UI or with modals from the question since it was unrelated. @Ssswift no it isn't. – VitorMM May 28 '17 at 17:56
  • three modal dialogs in a stacked row has probably not the best user experience for your advanced settings. https://en.m.wikipedia.org/wiki/Mode_(computer_interface)#Mode_errors and https://en.wikipedia.org/wiki/Modal_window#Problems – mahal tertin May 29 '17 at 18:02
  • There aren't all modal dialogs. The first two are modal windows and the last one is a modal dialog, and each one of them only shows up with an user click in the correct button, not surprising the user nor using hotkeys. It doesn't match with any of the "Mode errors" cases, nor "Modal window problems". – VitorMM May 30 '17 at 14:32

0 Answers0