Contents

Application Menu

This page explains how to configure the macOS application menu with the standard and custom menu items.

Overview

Every macOS application includes a main menu. By default, the Molybden app comes with a pre-defined main menu. However, you have the flexibility to customize your own menu, incorporating both standard and custom menu items.

Setting the application menu

The following code snippet shows how to set the application menu that contains the standard and custom menu items:

// Configure the app main menu.
app->setMainMenu(CustomMenu::create({
    menu::MacApp({
        menu::MacHideApp(),
        menu::MacHideOthers(),
        menu::MacShowAll(),
        menu::Separator(),
        menu::Quit()
    }),
    menu::File({
        menu::SavePageAs(),
        menu::Separator(),
        menu::Print(),
        menu::PrintUsingSystemDialog(),
        menu::Separator(),
        menu::CloseWindow(),
    }),
    menu::Edit({
        menu::Undo(),
        menu::Redo(),
        menu::Separator(),
        menu::Cut(),
        menu::Copy(),
        menu::Paste(),
        menu::Delete(),
        menu::SelectAll(),
        menu::Separator(),
        menu::Find(),
        menu::FindNext(),
        menu::FindPrevious()
    }),
    menu::View({
        menu::GoBack(),
        menu::GoForward(),
        menu::Separator(),
        menu::Stop(),
        menu::Reload(),
        menu::ReloadBypassingCache(),
        menu::Separator(),
        menu::ZoomNormal(),
        menu::ZoomIn(),
        menu::ZoomOut(),
        menu::Separator(),
        menu::FullScreen(),
        menu::Separator(),
        menu::ViewSource(),
        menu::DevTools()
    }),
    menu::Window({
        menu::MinimizeWindow(),
        menu::MaximizeWindow(),
    }),
    menu::Help({})
}));

The title of the application menu will be set to the name of your application.

Here’s how it will look like:

macOS app menu

On macOS the name of the application menu is always your app’s name. You can set the app name in the molybden.conf.json file.

{
  "app": {
    "name": "MyApp",
    "version": {
      "major": "1",
      "minor": "0",
      "patch": "0"
    },
    "author": "",
    "copyright": "",
    "description": "",
    "bundle": {...},
    "configurations": {...}
  }
}

Standard menu items

You can create a standard menu (without menu items) using the following helper functions:

Helper function Description
menu::MacApp() Creates the macOS $APP_NAME menu.
menu::File() Creates the File menu.
menu::Edit() Creates the Edit menu.
menu::View() Creates the View menu.
menu::Window() Creates the Window menu.
menu::Help() Creates the Help menu.

Use the following helper functions to create standard menu items:

Helper function Description
menu::Separator() Creates a menu separator.

The application standard menu items:

Helper function Description
menu::MacHideApp() Creates the Hide $APP_NAME menu item.
menu::MacHideOthers() Creates the Hide Others menu item.
menu::MacShowAll() Creates the Show All menu item.
menu::Quit() Creates the Quit $APP_NAME menu item.

The File standard menu items:

Helper function Description
menu::SavePageAs() Creates the Save Page As… menu item.
menu::Print() Creates the Print… menu item.
menu::PrintUsingSystemDialog() Creates the Print Using System Dialog menu item.
menu::CloseWindow() Creates the Close Window menu item.

The Edit standard menu items:

Helper function Description
menu::Undo() Creates the Undo menu item.
menu::Redo() Creates the Redo menu item.
menu::Cut() Creates the Cut menu item.
menu::Copy() Creates the Copy menu item.
menu::Paste() Creates the Paste menu item.
menu::PasteAndMatchStyle() Creates the Paste and Match Style menu item.
menu::Delete() Creates the Delete menu item.
menu::SelectAll() Creates the Select All menu item.
menu::Find() Creates the Find menu item.
menu::FindNext() Creates the Find Next menu item.
menu::FindPrevious() Creates the Find Previous menu item.

The View standard menu items:

Helper function Description
menu::GoBack() Creates the Back menu item.
menu::GoForward() Creates the Forward menu item.
menu::Stop() Creates the Stop menu item.
menu::Reload() Creates the Reload menu item.
menu::ReloadBypassingCache() Creates the Reload Bypassing Cache menu item.
menu::ZoomNormal() Creates the Actual Size menu item.
menu::ZoomIn() Creates the Zoom In menu item.
menu::ZoomOut() Creates the Zoom Out menu item.
menu::FullScreen() Creates the Enter Full Screen menu item.
menu::DevTools() Creates the Toggle Developer Tools menu item.
menu::ViewSource() Creates the View Source menu item.

The Window standard menu items:

Helper function Description
menu::MinimizeWindow() Creates the Minimise menu item.
menu::MaximizeWindow() Creates the Maximize menu item.

Custom menu items

You can create and add a custom menu and menu items to the application menu. The following code snippet shows how to create a custom menu with a custom item:

// Configure the app main menu.
app->setMainMenu(CustomMenu::create({
    menu::MacApp({
        menu::MacHideApp(),
        menu::MacHideOthers(),
        menu::MacShowAll(),
        menu::Separator(),
        menu::Quit()
    }),
    menu::File({
        menu::SavePageAs(),
        menu::Separator(),
        menu::Print(),
        menu::PrintUsingSystemDialog(),
        menu::Separator(),
        menu::CloseWindow(),
    }),
    menu::Edit({
        menu::Undo(),
        menu::Redo(),
        menu::Separator(),
        menu::Cut(),
        menu::Copy(),
        menu::Paste(),
        menu::Delete(),
        menu::SelectAll(),
        menu::Separator(),
        menu::Find(),
        menu::FindNext(),
        menu::FindPrevious()
    }),
    menu::View({
        menu::GoBack(),
        menu::GoForward(),
        menu::Separator(),
        menu::Stop(),
        menu::Reload(),
        menu::ReloadBypassingCache(),
        menu::Separator(),
        menu::ZoomNormal(),
        menu::ZoomIn(),
        menu::ZoomOut(),
        menu::Separator(),
        menu::FullScreen(),
        menu::Separator(),
        menu::ViewSource(),
        menu::DevTools()
    }),
    menu::Menu("Tools", {
        menu::Item("Clear Cache", [](const CustomMenuItemActionArgs& args) {
          browser->profile()->httpCache()->clear({});
        }),
    }),
    menu::Window({
        menu::MinimizeWindow(),
        menu::MaximizeWindow(),
    }),
    menu::Help({})
}));

Here’s how it will look like:

macOS app custom menu item

On this page
Top