From 5f1283970c40b4727f51a90784b24cfbd04e5148 Mon Sep 17 00:00:00 2001 From: David King Date: Thu, 7 May 2015 10:38:38 +0700 Subject: 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. --- c-gnome-app.c | 24 +++++++++++++++++++++--- 1 file 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[] = { "h", NULL }; const gchar * const quit_accel[] = { "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 -- cgit