Lägga till en sidopanel
As another piece of functionality, we are adding a sidebar, which demonstrates Gtk::Revealer and Gtk::ListBox. The new widgets are added in the window.ui file.
The code to populate the sidebar with buttons for the words found in each file is a little too involved to go into here. But we'll look at the code to add a checkbutton for the new feature to the menu. A menu item is added to the ui file gears_menu.ui.
To connect the menu item to the new show-words setting, we use a Gio::Action corresponding to the given Gio::Settings key. In ExampleAppWindow's constructor:
// Connect the menu to the MenuButton m_gears, and bind the show-words setting
// to the win.show-words action and the "Words" menu item.
// (The connection between action and menu item is specified in gears_menu.ui.)
auto menu_builder = Gtk::Builder::create_from_resource("/org/gtkmm/exampleapp/gears_menu.ui");
auto menu = menu_builder->get_object<Gio::MenuModel>("menu");
m_gears->set_menu_model(menu);
add_action(m_settings->create_action("show-words"));
Hur vårt program ser ut nu: