runModalLoop() not modal?

Bringing my applications from Windows to Mac OS X, I noticed that AlertWindow::runModalLoop() does not block neither the global menubar (which Windows does not have) nor the close button of the main window (as instead it does on Windows). Therefore it becomes possible to close the application or use commands that are not pertinent when one would expect a blocking modal dialog.

For example, if you click the close button of the main window while you are responding to the AlertWindow asking to save changes to the current document, you open a new alert (but not if you use the native alerts).

Could I have a clarification?

Yeah, that’s just the way OSX rolls. Try opening a modal dialog box in any app, and the menus will still operate.

You can disable them, of course, using the MenuBarModel, while your dialog’s showing.

…hmm, interesting point about the close button though - I’d never tried that before. I might have to take a look.

Thanks Jules.
I imagine I could use Component::getCurrentlyModalComponent() to tell if a modal loop is running?

The cleanest way to do it would be to create an RAII class that disables the menus while it’s alive, and just declare one on the stack before you run your modal loop.

Unfortunately this won’t work when the Alert is generated inside JUCE, like in FileBasedDocument::saveAs()…

Well, you could just disable the menus before calling FileBasedDocument::saveAs().

This is also problematic if you try to resize a window when another window is modal. You get the OSX alert sound continuously when you’re dragging the resizer, which is pretty annoying. Seems like there should be a better way to handle this than having to manually disable resizing (and menus, etc.) whenever a modal dialog is opened.

I did some work on this a while ago, are you using the latest version?

I tried this on version 2.0, though not the repo head, but unless you’ve done work on it since the stable release, I’m guessing the problem still exists.

Follow these steps:

  • load the demo app
  • enable native title bar
  • choose Widgets demo
  • click for a popup menu
  • choose a Juce file chooser dialog

While the file chooser is open, you can still close, minimize, maximize, and resize the main window underneath. It’s the resizing in particular that generates an unending stream of alert sounds.

Note that, with a native file chooser, none of these problems happen.

Think this was fixed this morning, see this commit.
I haven’t tried if personally but looks like what you’re referring to.

I don’t think so, because it’s not specific to file choosers. It’s for any modal dialog.