UIManager
| Chapter 11. Menus and Toolbars |

## UIManager

Next you should create a `UIManager` and add the `ActionGroup` to the `UIManager` with `insert_action_group()` At this point is also a good idea to tell the parent window to respond to the specified keyboard shortcuts, by using `add_accel_group()`.

For instance,

    Glib::RefPtr<Gtk::UIManager> m_refUIManager = Gtk::UIManager::create();
    m_refUIManager->insert_action_group(m_refActionGroup);
    add_accel_group(m_refUIManager->get_accel_group());

Then, you can define the actual visible layout of the menus and toolbars, and add the UI layout to the `UIManager`. This "ui string" uses an XML format, in which you should mention the names of the actions that you have already created. For instance:

        Glib::ustring ui_info =
            "<ui>"
            "  <menubar name='MenuBar'>"
            "    <menu action='MenuFile'>"
            "      <menuitem action='New'/>"
            "      <menuitem action='Open'/>"
            "      <separator/>"
            "      <menuitem action='Quit'/>"
            "    </menu>"
            "    <menu action='MenuEdit'>"
            "      <menuitem action='Cut'/>"
            "      <menuitem action='Copy'/>"
            "      <menuitem action='Paste'/>"
            "    </menu>"
            "  </menubar>"
            "  <toolbar  name='ToolBar'>"
            "    <toolitem action='Open'/>"
            "    <toolitem action='Quit'/>"
            "  </toolbar>"
            "</ui>";

        m_refUIManager->add_ui_from_string(ui_info);

Remember that these names are just the identifiers that we used when creating the actions. They are not the text that the user will see in the menus and toolbars. We provided those human-readable names when we created the actions.

To instantiate a `Gtk::MenuBar` or `Gtk::Toolbar` which you can actually show, you should use the `UIManager::get_widget()` method, and then add the widget to a container. For instance:

    Gtk::Widget* pMenubar = m_refUIManager->get_widget("/MenuBar");
    pBox->add(*pMenuBar, Gtk::PACK_SHRINK);

Chapter 11. Menus and Toolbars |  | Popup Menus