Hi,
I’m using a simple main menu (File, Edit, View, About, etc…) in my JUCE app with a mainmenubar model that contains all my menu entries and sub-entries.
I have an undo/redo system and it also keeps track of if the user has made any changes since the last save to file.
If changes were made, the user can select File → Save to save it to the file saved to before or opened from before. If the user tries to exit the app, the app will ask if you want to save changes or not before exiting.
If no changes have been made, there’s no need to do a File → Save, so I would like to have the File → Save menu entry disabled. (eg I’ll make it a darker colour and it should’nt be selectable). This is what many commercial windows applications do. They also won’t ask to do a save on exitting the app.
So, how can I easily change one of my existing menubarmodel items (in this case File → Save) to look disabled and it being unselectable ?
Here’s a snippet of code for my menubarmodel:
juce::StringArray MainMenuBarComponent::getMenuBarNames()
{
return juce::StringArray(“File”,“Edit”, “View”, “About”);
}
juce::PopupMenu MainMenuBarComponent::getMenuForIndex(int n, const juce::String& menuName)
{
PopupMenu menu;
if (menuName == "File")
{
menu.addItem(1, "New...");
menu.addItem(2, "Open...");
menu.addItem(3, "Save");
menu.addItem(4, "Save as...");
menu.addItem(5, "Exit");
}
else if (menuName == "Edit")
{
menu.addItem(6, "Undo");
menu.addItem(7, "Redo");
menu.addItem(8, "Project Preferences...");
}
else if (menuName == "View")
{
menu.addItem(9, "Zoom In");
menu.addItem(10, "Zoom Out");
}
else if (menuName == "About")
{
menu.addItem(11, "About Hummingbird...");
}
return menu;
}
void MainMenuBarComponent::menuItemSelected(int menuItemID, int topLevelMenuIndex)
{
switch (menuItemID)
{
case 1: // New…
rootManager->NewProject(true);
break;
case 2: // Open…
rootManager->LoadProjectFromFile();
break;
case 3: // Save
rootManager->SaveProjectToFile();
break;
case 4: // Save as…
rootManager->SaveAsProjectToFile();
break;
…
That’s it…
Thanks for your time, it’s much appreciated…
Cheers,
Terrence