[gnome-todo] window: Let primary menu be managed by GTK



commit f1a4d0b23ffb620dc2495b26e03120f3b5ac6cb2
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Fri Jul 2 11:59:02 2021 -0300

    window: Let primary menu be managed by GTK
    
    It'll help us adding a new custom widget there.

 src/gui/gtd-window.c      | 10 ++++++++++
 src/gui/gtd-window.ui     | 14 ++------------
 src/gui/gui.gresource.xml |  5 +++++
 src/gui/menus.ui          | 13 +++++++++++++
 4 files changed, 30 insertions(+), 12 deletions(-)
---
diff --git a/src/gui/gtd-window.c b/src/gui/gtd-window.c
index 73010b74..96f337a6 100644
--- a/src/gui/gtd-window.c
+++ b/src/gui/gtd-window.c
@@ -61,6 +61,7 @@ struct _GtdWindow
   AdwHeaderBar       *headerbar;
   GtkBox             *headerbar_box;
   GtkStack           *stack;
+  GtkMenuButton      *primary_menu_button;
   GtkBox             *workspace_box_end;
   GtkBox             *workspace_box_start;
   GtkListBox         *workspaces_listbox;
@@ -561,6 +562,7 @@ gtd_window_class_init (GtdWindowClass *klass)
   gtk_widget_class_bind_template_child (widget_class, GtdWindow, headerbar);
   gtk_widget_class_bind_template_child (widget_class, GtdWindow, headerbar_box);
   gtk_widget_class_bind_template_child (widget_class, GtdWindow, notification_widget);
+  gtk_widget_class_bind_template_child (widget_class, GtdWindow, primary_menu_button);
   gtk_widget_class_bind_template_child (widget_class, GtdWindow, stack);
   gtk_widget_class_bind_template_child (widget_class, GtdWindow, workspace_box_end);
   gtk_widget_class_bind_template_child (widget_class, GtdWindow, workspace_box_start);
@@ -574,6 +576,9 @@ gtd_window_class_init (GtdWindowClass *klass)
 static void
 gtd_window_init (GtdWindow *self)
 {
+  GtkApplication *application;
+  GMenu *primary_menu;
+
   static const GActionEntry entries[] = {
     { "activate-workspace", on_action_activate_workspace_activated_cb, "(sv)" },
   };
@@ -594,6 +599,11 @@ gtd_window_init (GtdWindow *self)
                            self,
                            NULL);
 
+  /* Fancy primary menu */
+  application = GTK_APPLICATION (g_application_get_default ());
+  primary_menu = gtk_application_get_menu_by_id (application, "primary-menu");
+  gtk_menu_button_set_menu_model (self->primary_menu_button, G_MENU_MODEL (primary_menu));
+
   /* Development build */
   if (is_development_build ())
     setup_development_build (self);
diff --git a/src/gui/gtd-window.ui b/src/gui/gtd-window.ui
index d45f6198..2114e3b3 100644
--- a/src/gui/gtd-window.ui
+++ b/src/gui/gtd-window.ui
@@ -58,9 +58,8 @@
 
 
                       <child type="end">
-                        <object class="GtkMenuButton">
-                          <property name="menu-model">app-menu</property>
-                          <property name="direction">none</property>
+                        <object class="GtkMenuButton" id="primary_menu_button">
+                          <property name="icon-name">open-menu-symbolic</property>
                         </object>
                       </child>
 
@@ -134,13 +133,4 @@
       </object>
     </child>
   </object>
-
-  <menu id="app-menu">
-    <section>
-      <item>
-        <attribute name="label" translatable="yes">_About To Do</attribute>
-        <attribute name="action">app.about</attribute>
-      </item>
-    </section>
-  </menu>
 </interface>
diff --git a/src/gui/gui.gresource.xml b/src/gui/gui.gresource.xml
index 39ec6f75..bb7161f7 100644
--- a/src/gui/gui.gresource.xml
+++ b/src/gui/gui.gresource.xml
@@ -18,4 +18,9 @@
     <!-- Assets -->
     <file>assets/all-done.svg</file>
   </gresource>
+
+  <!-- GTK -->
+  <gresource prefix="/org/gnome/todo/gtk">
+    <file compressed="true" preprocess="xml-stripblanks">menus.ui</file>
+  </gresource>
 </gresources>
diff --git a/src/gui/menus.ui b/src/gui/menus.ui
new file mode 100644
index 00000000..f90d756b
--- /dev/null
+++ b/src/gui/menus.ui
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <menu id="primary-menu">
+
+    <section>
+      <item>
+        <attribute name="label" translatable="yes">_About To Do</attribute>
+        <attribute name="action">app.about</attribute>
+      </item>
+    </section>
+
+  </menu>
+</interface>


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