[devhelp] amtk: create app menu with Amtk



commit 53f587a2065358cdd98aecd59fe68563f0a3f950
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Thu Apr 12 21:20:55 2018 +0200

    amtk: create app menu with Amtk

 po/POTFILES.in       |    1 -
 src/dh-app.c         |   37 +++++++++++++++++++++++++-------
 src/dh.gresource.xml |    1 -
 src/menus.ui         |   58 --------------------------------------------------
 4 files changed, 29 insertions(+), 68 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 233d865..364d4b8 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -37,5 +37,4 @@ src/dh-web-view.c
 src/dh-window.c
 src/dh-window.ui
 src/help-overlay.ui
-src/menus.ui
 src/tepl-info-bar.c
diff --git a/src/dh-app.c b/src/dh-app.c
index d1fb8b8..a2aa99c 100644
--- a/src/dh-app.c
+++ b/src/dh-app.c
@@ -398,17 +398,38 @@ setup_accelerators (GtkApplication *app)
 }
 
 static void
-set_app_menu_if_needed (GtkApplication *app)
+create_app_menu_if_needed (GtkApplication *app)
 {
-        GMenu *manual_app_menu;
+        GMenu *app_menu;
+        GMenu *section;
+        AmtkFactory *factory;
 
-        manual_app_menu = gtk_application_get_menu_by_id (app, "manual-app-menu");
+        if (!gtk_application_prefers_app_menu (app))
+                return;
+
+        app_menu = g_menu_new ();
+        factory = amtk_factory_new (app);
+
+        section = g_menu_new ();
+        amtk_gmenu_append_item (section, amtk_factory_create_gmenu_item (factory, "app.new-window"));
+        amtk_gmenu_append_section (app_menu, NULL, section);
+
+        section = g_menu_new ();
+        amtk_gmenu_append_item (section, amtk_factory_create_gmenu_item (factory, "app.preferences"));
+        amtk_gmenu_append_section (app_menu, NULL, section);
+
+        section = g_menu_new ();
+        amtk_gmenu_append_item (section, amtk_factory_create_gmenu_item (factory, "win.show-help-overlay"));
+        amtk_gmenu_append_item (section, amtk_factory_create_gmenu_item (factory, "app.help"));
+        amtk_gmenu_append_item (section, amtk_factory_create_gmenu_item (factory, "app.about"));
+        amtk_gmenu_append_item (section, amtk_factory_create_gmenu_item (factory, "app.quit"));
+        amtk_gmenu_append_section (app_menu, NULL, section);
 
-        /* Have the g_return in all cases, to catch problems in all cases. */
-        g_return_if_fail (manual_app_menu != NULL);
+        g_object_unref (factory);
+        g_menu_freeze (app_menu);
 
-        if (gtk_application_prefers_app_menu (app))
-                gtk_application_set_app_menu (app, G_MENU_MODEL (manual_app_menu));
+        gtk_application_set_app_menu (app, G_MENU_MODEL (app_menu));
+        g_object_unref (app_menu);
 }
 
 static void
@@ -424,7 +445,7 @@ dh_app_startup (GApplication *application)
         add_action_infos (app);
         add_action_entries (app);
         setup_accelerators (GTK_APPLICATION (app));
-        set_app_menu_if_needed (GTK_APPLICATION (app));
+        create_app_menu_if_needed (GTK_APPLICATION (app));
 }
 
 static void
diff --git a/src/dh.gresource.xml b/src/dh.gresource.xml
index 6f58d06..293d13a 100644
--- a/src/dh.gresource.xml
+++ b/src/dh.gresource.xml
@@ -7,6 +7,5 @@
   </gresource>
   <gresource prefix="/org/gnome/devhelp/gtk">
     <file preprocess="xml-stripblanks">help-overlay.ui</file>
-    <file preprocess="xml-stripblanks">menus.ui</file>
   </gresource>
 </gresources>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]