Menus - Blueprint documentation

Hide navigation sidebar
Hide table of contents sidebar
Skip to content
Back to top
View this page
Toggle table of contents sidebar

# Menus

Menu = ‘menu’ <id:IDENT>? ‘{’ MenuChild* ‘}’ MenuChild = ( MenuSection | MenuSubmenu | MenuItemShorthand | MenuItem ) MenuSection = ‘section’ <id:IDENT>? ‘{’ ( MenuChild | MenuAttribute )* ‘}’ MenuSubmenu = ‘submenu’ <id:IDENT>? ‘{’ ( MenuChild | MenuAttribute )* ‘}’ MenuItem = ‘item’ ‘{’ MenuAttribute* ‘}’ MenuAttribute = <name:IDENT> ‘:’ StringValue ‘;’

Menus, such as the application menu, are defined using the `menu` keyword. Menus have the type Gio.MenuModel and can be referenced by ID. They cannot be defined inline.

### Example

    menu my_menu {
      submenu {
        label: _("File");
        item {
          label: _("New");
          action: "app.new";
          icon: "document-new-symbolic";
        }
      }
    }

    MenuButton {
      menu-model: my_menu;
    }

## Item Shorthand

MenuItemShorthand = ‘item’ ‘(’ StringValue ( ‘,’ ( StringValue ( ‘,’ StringValue? )? )? )? ‘)’

The most common menu attributes are `label`, `action`, and `icon`. Because they’re so common, Blueprint provides a shorter syntax for menu items with just these properties.

### Example

    menu {
      item ("label")
      item ("label", "action")
      item ("label", "action", "icon")
    }