summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid King <amigadave@amigadave.com>2015-05-07 10:38:38 +0700
committerDavid King <amigadave@amigadave.com>2015-05-07 10:38:38 +0700
commit5f1283970c40b4727f51a90784b24cfbd04e5148 (patch)
tree3fdbe307e2933f0d6ef598f9716000c9dcbb7993
parent298308c90defe4e16805b4a38784fcfd22c7e3de (diff)
downloadc-gnome-app-5f1283970c40b4727f51a90784b24cfbd04e5148.tar.gz
c-gnome-app-5f1283970c40b4727f51a90784b24cfbd04e5148.tar.xz
c-gnome-app-5f1283970c40b4727f51a90784b24cfbd04e5148.zip
Add an application menu
Create a menu model, and add menu items into the model. Link the menu items to the "hello-world" and "quit" actions, which were added to the application. Set the menu to be the application menu.
-rw-r--r--c-gnome-app.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/c-gnome-app.c b/c-gnome-app.c
index 6d20243..d03f69b 100644
--- a/c-gnome-app.c
+++ b/c-gnome-app.c
@@ -36,18 +36,36 @@ static void
on_startup (GApplication *app,
gpointer user_data)
{
+ GtkApplication *gtk_app;
const gchar * const hello_world_accel[] = { "<Primary>h", NULL };
const gchar * const quit_accel[] = { "<Primary>q", NULL };
+ GMenu *appmenu;
+ GMenu *section;
+ GMenuItem *item;
+ gtk_app = GTK_APPLICATION (app);
g_action_map_add_action_entries (G_ACTION_MAP (app), actions,
G_N_ELEMENTS (actions), app);
- window = gtk_application_window_new (GTK_APPLICATION (app));
- gtk_application_set_accels_for_action (GTK_APPLICATION (app),
+ window = gtk_application_window_new (gtk_app);
+ gtk_application_set_accels_for_action (gtk_app,
"app.hello-world",
hello_world_accel);
- gtk_application_set_accels_for_action (GTK_APPLICATION (app),
+ gtk_application_set_accels_for_action (gtk_app,
"app.quit",
quit_accel);
+
+ appmenu = g_menu_new ();
+ section = g_menu_new ();
+ item = g_menu_item_new ("Hello world!", "app.hello-world");
+ g_menu_append_section (appmenu, NULL, G_MENU_MODEL (section));
+ g_menu_append_item (section, item);
+ g_object_unref (item);
+ item = g_menu_item_new ("Quit", "app.quit");
+ g_menu_append_item (section, item);
+ g_object_unref (item);
+ gtk_application_set_app_menu (gtk_app, G_MENU_MODEL (appmenu));
+
+ g_object_unref (appmenu);
}
int