[gtk+/wip/gmenu] bloatpad: use GtkBuilder for constructing menus
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/gmenu] bloatpad: use GtkBuilder for constructing menus
- Date: Fri, 2 Dec 2011 03:45:10 +0000 (UTC)
commit 1bb9b081c641f8c7a81e617eb9725dbf5c7344d2
Author: Ryan Lortie <desrt desrt ca>
Date: Thu Dec 1 22:43:54 2011 -0500
bloatpad: use GtkBuilder for constructing menus
This is closer to what a real application would want to do.
examples/bloatpad.c | 63 +++++++++++++++++----------------------------------
1 files changed, 21 insertions(+), 42 deletions(-)
---
diff --git a/examples/bloatpad.c b/examples/bloatpad.c
index 279e993..f107a07 100644
--- a/examples/bloatpad.c
+++ b/examples/bloatpad.c
@@ -190,57 +190,36 @@ create_app_actions (void)
return G_ACTION_GROUP (actions);
}
-static GMenuModel *
-create_app_menu (void)
-{
- GMenu *menu = g_menu_new ();
- g_menu_append (menu, "_About Bloatpad", "app.about");
- g_menu_append (menu, "_Quit", "app.quit");
-
- return G_MENU_MODEL (menu);
-}
-
-static GMenuModel *
-create_window_menu (void)
-{
- GMenu *menu;
- GMenu *submenu;
-
- submenu = g_menu_new ();
- g_menu_append (submenu, "_Copy", "win.copy");
- g_menu_append (submenu, "_Paste", "win.paste");
-
- menu = g_menu_new ();
- g_menu_append_submenu (menu, "_Edit", (GMenuModel*)submenu);
- g_object_unref (submenu);
-
- submenu = g_menu_new ();
- g_menu_append (submenu, "_Fullscreen", "win.fullscreen");
-
- g_menu_append_submenu (menu, "_View", (GMenuModel*)submenu);
- g_object_unref (submenu);
-
- return G_MENU_MODEL (menu);
-}
-
static void
bloat_pad_init (BloatPad *app)
{
GActionGroup *actions;
- GMenuModel *app_menu;
- GMenuModel *window_menu;
+ GtkBuilder *builder;
actions = create_app_actions ();
g_application_set_action_group (G_APPLICATION (app), actions);
g_object_unref (actions);
- app_menu = create_app_menu ();
- g_application_set_app_menu (G_APPLICATION (app), app_menu);
- g_object_unref (app_menu);
-
- window_menu = create_window_menu ();
- g_application_set_menubar (G_APPLICATION (app), window_menu);
- g_object_unref (window_menu);
+ builder = gtk_builder_new ();
+ gtk_builder_add_from_string (builder,
+ "<interface>"
+ " <menu id='app-menu'>"
+ " <item label='_About Bloatpad' action='app.about'/>"
+ " <item label='_Quit' action='app.quit'/>"
+ " </menu>"
+ " <menu id='menubar'>"
+ " <submenu label='_Edit'>"
+ " <item label='_Copy' action='win.copy'/>"
+ " <item label='_Paste' action='win.paste'/>"
+ " </submenu>"
+ " <submenu label='_View'>"
+ " <item label='_Fullscreen' action='win.fullscreen'/>"
+ " </submenu>"
+ " </menu>"
+ "</interface>", -1, NULL);
+ g_application_set_app_menu (G_APPLICATION (app), G_MENU_MODEL (gtk_builder_get_object (builder, "app-menu")));
+ g_application_set_menubar (G_APPLICATION (app), G_MENU_MODEL (gtk_builder_get_object (builder, "menubar")));
+ g_object_unref (builder);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]