Short cut keys for Preference and About

Hi All,
I have added code to juce demo to display about and preferences menu items in the apple menu. It shows up and I am able to handle mouse clicks, but I couldn’t display short cut keys

This is my code.

PopupMenu *pop = new PopupMenu();
pop->addItem (111, T("Juce Demo"));
pop->addSeparator();
pop->addItem (112, T("Preferences"));
pop->addSeparator();
MenuBarModel::setMacMainMenu ((ContentComp*) mainWindow->getContentComponent(),pop);

What do I have to do to display the short cut keys.

You have to use menu items that are mapped to commands with a command manager - it uses that to look up the shortcut keys it should display.

I needed another clarification.

PopupMenu *pop = new PopupMenu();
pop->addItem (111, T("Juce Demo"));
pop->addSeparator();
pop->addItem (112, T("Preferences"));
pop->addSeparator();
MenuBarModel::setMacMainMenu ((ContentComp*) mainWindow->getContentComponent(),pop); 

will MenuBarModel delete the PopupMenu object given to it, or I would have to do it.

Secondly

In that case should I have to use this method and set shotcut keys in commandManager.

Thanks for the prompt reply. :slight_smile:

Hi Jules,
Thanks for bailing me out yet again. I got the short cut keys to work.

I deleted the PopupMenu given to MenuBarModel after the call.

MenuBarModel::setMacMainMenu ((ContentComp*) mainWindow->getContentComponent(),pop);
                mainWindow->setMenuBar (0);
delete pop;
pop = 0L;

Applications seems to work fine. :slight_smile:

Hi Jules,
I had a question, where does juce menu pick up “Hide application_name” and “Quit application_name” menu items of application name menu. Is there any way to change the names of these two menu items?

I think they’re hard-coded. You could have a trawl through the native mac menuing code if you want to see exactly how it’s done.

Thanks Jules. I will give it a try. The reason I asked for this was because we have release every other month and we change our application version, but the menu item had the older version name. So I need to get into native code to change the code to show my application name without version.

Doesn’t it pick up the name from the JUCEApplication class?

You are right. It picked it from “const juce::String JUCEApplication::getApplicationName ()”. I got the issue resolved. Thanks.

I made this change to juce demo.

void getCommandInfo (const CommandID commandID, ApplicationCommandInfo& result)
{
     ...
     case showFontsAndText:
            result.setInfo (T("Fonts and Text"), T("Shows the fonts & text demo"), demosCategory, 0);
            result.setTicked (currentDemoId == showFontsAndText);
            result.addDefaultKeypress (T('G'), ModifierKeys::commandModifier); // used G instead of g
            break;
}

This was the result.

If I replace lower case letters with upper case letter the menu add shift key to the short cut key. Should it be working like this?

You really shouldn’t use upper case in defining a keypress - if the keypress had no shift modifier, but had an upper case letter, that’s self-contradictory. Stick to lower-case for keypresses, to avoid any confusion.

I was pretty dumb there and you have got a valid point there. It’s just that the guys before me had used upper case letters for shortcut keys and it all worked fine till we moved to juce 1.50. Anyway got the issues resolved. Pleased to inform you finally for first time we are not using main.nib file for the menu.

I have another question, is there anyway to hide a menu item in menu bar.

I’ve actually put an assertion in the KeyPress class now to catch anyone doing the same thing.

not sure I understand… To hide it, you just don’t add it to the menu, right?

[quote=“jules”]I’ve actually put an assertion in the KeyPress class now to catch anyone doing the same thing.

not sure I understand… To hide it, you just don’t add it to the menu, right?[/quote]

Am responsible for a assertion now. That makes me really proud :oops: . I should have put the query more clearly. Well I got it to work.

Just to explain what I meant , Suppose I have a menu item called plugins which shows up only if plugins are installed and is hidden when all the plugins are uninstalled. I wanted to know how to handle that(hiding and unhiding the menu item).

I should be reading the documentation.

Well, somewhere in your code, you’re calling menu.addItem(“plugins”)… so if you don’t have any plugins, don’t do that… ?? Or maybe I’m still missing the point!

It’s just my requirement that is a little off-beat.

The menu I was speaking about was one of the main menu like File, Edit etc. which is returned by “const StringArray getMenuBarNames ()”.

Right… But the same answer applies - just don’t add the menu if you don’t want it!

I realized, every time my application gains focus this method is called “const StringArray getMenuBarNames ()”. I used it to code for the feature. Thanks for all the help.

I disagree with this and so does Microsoft and Apple. Microsoft and Apple both user uppercase. Juce applications may actually confuse users because they are use to seeing uppercase. You see the short cuts are displaying the characters on the computer keyboard, which are upper case and the user doesn’t have to think about upper/lower case except in special exceptions. More importantly the keypress character should be [color=#FF0000]what ever the developer wants it to be[/color]. PLEASE don’t make assumptions that restrict everybody. Juce is a [color=#FF0000]beautiful [/color] environment, except for these decisions that make it very difficult to get what you want. I found this old post because I want upper case for the short cuts. How can I do this? The Look and Feel doesn’t allow this. Also can we make the letters normal size, instead of the very small letters. Mnay of my users are over the age of 50 and don’t have perfect vision.

Huh? I think you’re massively missing the point.

I was talking about the char code that you pass to in the KeyPress constructor, not the way the letter that gets displayed on the screen. The code that prints a shortcut can do whatever it wants, that’s a different thing altogether.