[gnome-terminal/wip/fmuellner/headerbar: 4/8] window: Add primary menu to headerbar



commit 30aff6bf5f4d73ace6862ab850da135e93c2812d
Author: Florian Müllner <fmuellner gnome org>
Date:   Fri Nov 2 00:33:49 2018 +0100

    window: Add primary menu to headerbar
    
    Commit 4b9f6d398d removed the app menu in line with the corresponding
    initiative[0]. The recommendation is to make the menu's action available
    under a primary menu button in the headerbar, so do that now that we
    have one.
    
    [0] https://gitlab.gnome.org/GNOME/Initiatives/wikis/App-Menu-Retirement
    
    https://bugzilla.gnome.org/show_bug.cgi?id=756798

 src/Makefile.am            |  1 +
 src/terminal-headerbar.c   | 13 +++++++++++--
 src/terminal-headerbar.ui  | 20 ++++++++++++++++++++
 src/terminal-headermenu.ui | 42 ++++++++++++++++++++++++++++++++++++++++++
 src/terminal.gresource.xml |  1 +
 5 files changed, 75 insertions(+), 2 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 30b7cebd..b36cc8e3 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -328,6 +328,7 @@ CLEANFILES = \
 EXTRA_DIST = \
        terminal.about \
        terminal-headerbar.ui \
+       terminal-headermenu.ui \
        terminal-menubar.ui.in \
        terminal-notebook-menu.ui \
        terminal-window.ui \
diff --git a/src/terminal-headerbar.c b/src/terminal-headerbar.c
index 58132e31..d9acb441 100644
--- a/src/terminal-headerbar.c
+++ b/src/terminal-headerbar.c
@@ -20,6 +20,7 @@
 #include <glib/gi18n.h>
 
 #include "terminal-headerbar.h"
+#include "terminal-app.h"
 #include "terminal-libgsystem.h"
 
 typedef struct _TerminalHeaderbarPrivate TerminalHeaderbarPrivate;
@@ -36,7 +37,7 @@ struct _TerminalHeaderbarClass
 
 struct _TerminalHeaderbarPrivate
 {
-  gpointer dummy;
+  GtkWidget *menubutton;
 };
 
 enum {
@@ -60,10 +61,17 @@ G_DEFINE_TYPE_WITH_PRIVATE (TerminalHeaderbar, terminal_headerbar, GTK_TYPE_HEAD
 static void
 terminal_headerbar_init (TerminalHeaderbar *headerbar)
 {
-  //  TerminalHeaderbarPrivate *priv = PRIV (headerbar);
+  GtkApplication *app = GTK_APPLICATION (terminal_app_get ());
+  GMenu *primary_menu;
+
+  TerminalHeaderbarPrivate *priv = PRIV (headerbar);
   GtkWidget *widget = GTK_WIDGET (headerbar);
 
   gtk_widget_init_template (widget);
+
+  primary_menu = gtk_application_get_menu_by_id (app, "headermenu");
+  gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (priv->menubutton),
+                                  G_MENU_MODEL (primary_menu));
 }
 
 static void
@@ -118,6 +126,7 @@ terminal_headerbar_class_init (TerminalHeaderbarClass *klass)
   /* g_object_class_install_properties (gobject_class, G_N_ELEMENTS (pspecs), pspecs); */
 
   gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/terminal/ui/headerbar.ui");
+  gtk_widget_class_bind_template_child_private (widget_class, TerminalHeaderbar, menubutton);
 }
 
 /* public API */
diff --git a/src/terminal-headerbar.ui b/src/terminal-headerbar.ui
index cc56f64c..d1bf3ebc 100644
--- a/src/terminal-headerbar.ui
+++ b/src/terminal-headerbar.ui
@@ -39,6 +39,26 @@
         </child>
       </object>
     </child>
+    <child>
+      <object class="GtkMenuButton" id="menubutton">
+        <property name="visible">True</property>
+        <property name="focus_on_click">False</property>
+        <property name="can_focus">True</property>
+        <property name="receives_default">True</property>
+        <style>
+          <class name="image-button"/>
+        </style>
+        <child>
+          <object class="GtkImage">
+            <property name="visible">True</property>
+            <property name="icon_name">open-menu-symbolic</property>
+          </object>
+        </child>
+      </object>
+      <packing>
+        <property name="pack_type">end</property>
+      </packing>
+    </child>
     <child>
       <object class="GtkButton">
         <property name="visible">True</property>
diff --git a/src/terminal-headermenu.ui b/src/terminal-headermenu.ui
new file mode 100644
index 00000000..2b06ca3b
--- /dev/null
+++ b/src/terminal-headermenu.ui
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Copyright © 2012 Christian Persch
+
+  This program is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+-->
+<interface>
+  <menu id="headermenu">
+    <section>
+      <item>
+        <attribute name="label" translatable="yes">New _Window</attribute>
+        <attribute name="action">win.new-terminal</attribute>
+        <attribute name="target" type="(ss)">('window', 'current')</attribute>
+      </item>
+    </section>
+    <section>
+      <item>
+        <attribute name="label" translatable="yes">_Preferences</attribute>
+        <attribute name="action">app.preferences</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">_Help</attribute>
+        <attribute name="action">app.help</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">_About Terminal</attribute>
+        <attribute name="action">app.about</attribute>
+      </item>
+    </section>
+  </menu>
+</interface>
diff --git a/src/terminal.gresource.xml b/src/terminal.gresource.xml
index ba26f3c8..a8e96c89 100644
--- a/src/terminal.gresource.xml
+++ b/src/terminal.gresource.xml
@@ -18,6 +18,7 @@
 <gresources>
   <gresource prefix="/org/gnome/terminal">
     <file alias="css/terminal.css" compressed="true">terminal.common.css</file>
+    <file alias="gtk/menus.ui" compressed="true" preprocess="xml-stripblanks">terminal-headermenu.ui</file>
     <file alias="ui/headerbar.ui" compressed="true" preprocess="xml-stripblanks">terminal-headerbar.ui</file>
     <file alias="ui/menubar-with-mnemonics.ui" compressed="true" 
preprocess="xml-stripblanks">terminal-menubar-with-mnemonics.ui</file>
     <file alias="ui/menubar-without-mnemonics.ui" compressed="true" 
preprocess="xml-stripblanks">terminal-menubar-without-mnemonics.ui</file>


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