Command-W and native title bars


#1

I seem to do nothing but post about native title bar support. Anyhow, I added support for command-W and option-command-W to my app; here’s how I handled it if anyone cares. This is from the keyPressed handler for my window class:

[code] ModifierKeys mods;

mods = key.getModifiers();

//
// Look for option-command-w
//
// I have no idea where the magic key code 183 came from, but that's what you get
//
if (key.isKeyCode(183) && mods.isCommandDown() && mods.isAltDown())
{
  // do something to close all your application's windows at once here
	return;
}

//
// Look for command-w
//
if (key.isKeyCode('w') && (mods.isCommandDown()))
{
	closeButtonPressed();
	return;
}

[/code]


#2

ok, I guess I should add something along those lines to the mac windowing code. Not sure if I can easily do the close-all-windows version without making lots of changes, but will add the cmd-w shortcut.


#3

oh - actually it’s already there in DocumentWindow, which adds cmd-w as a shortcut for the close button.

Not sure if it would actually be a good idea to add it as a default ‘close window’ key for other top-level components, because you might not want the user to be able to just close it (e.g. alertwindows, etc)


#4

Right, but that doesn’t work in native title bar mode since the close button isn’t a JUCE button. You can see this easily with the JUCE demo.

However, adding this to my app was no big deal; I figured it was easier just to do it myself rather than delve into the Mac windowing code in JUCE.

As far as cmd-opt-w, I agree with you; I don’t think you’d want to build it into JUCE. Having it in my code is fine.

My original post was meant to be informative; I wasn’t asking you to add something to JUCE. I wanted to spare others the pain of figuring out the magic key code of 183. : )

Matt


#5