[gnome-terminal] window: Add primary menu to headerbar



commit 9e9e7c21054998470d3d6022074a24c57b23111e
Author: Florian Müllner <fmuellner gnome org>
Date:   Mon Dec 10 22:00:33 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

 po/POTFILES.in             |  1 +
 src/Makefile.am            |  1 +
 src/terminal-app.c         | 26 ++++++++++++++++++++++++++
 src/terminal-app.h         |  2 ++
 src/terminal-headerbar.c   | 10 ++++++++--
 src/terminal-headerbar.ui  | 20 ++++++++++++++++++++
 src/terminal-headermenu.ui | 42 ++++++++++++++++++++++++++++++++++++++++++
 src/terminal.gresource.xml |  1 +
 8 files changed, 101 insertions(+), 2 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 1aa950d8..fa872e50 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -14,6 +14,7 @@ src/terminal-app.c
 src/terminal.c
 src/terminal-encoding.c
 [type: gettext/glade]src/terminal-headerbar.ui
+[type: gettext/glade]src/terminal-headermenu.ui
 src/terminal-headerbar.c
 src/terminal-mdi-container.c
 [type: gettext/glade]src/terminal-menubar.ui.in
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-app.c b/src/terminal-app.c
index c6e4ae7d..6034025e 100644
--- a/src/terminal-app.c
+++ b/src/terminal-app.c
@@ -108,6 +108,8 @@ struct _TerminalApp
   GMenu *menubar_new_terminal_section;
   GMenu *menubar_set_profile_section;
   GMenu *menubar_set_encoding_submenu;
+
+  GMenuModel *headermenu;
   GMenu *set_profile_menu;
 
   GtkClipboard *clipboard;
@@ -527,6 +529,14 @@ terminal_app_create_menubar (TerminalApp *app,
   return app->menubar;
 }
 
+static void
+terminal_app_create_headermenu (TerminalApp *app)
+{
+  terminal_util_load_objects_resource ("/org/gnome/terminal/ui/headerbar-menu.ui",
+                                       "headermenu", &app->headermenu,
+                                       NULL);
+}
+
 /* Clipboard */
 
 static void
@@ -779,6 +789,7 @@ terminal_app_finalize (GObject *object)
   g_clear_object (&app->menubar_new_terminal_section);
   g_clear_object (&app->menubar_set_profile_section);
   g_clear_object (&app->menubar_set_encoding_submenu);
+  g_clear_object (&app->headermenu);
   g_clear_object (&app->set_profile_menu);
 
   terminal_accels_shutdown ();
@@ -1092,6 +1103,21 @@ terminal_app_get_menubar (TerminalApp *app)
   return app->menubar;
 }
 
+/**
+ * terminal_app_get_headermenu:
+ * @app: a #TerminalApp
+ *
+ * Returns: (tranfer none): the main window headerbar menu bar as a #GMenuModel
+ */
+GMenuModel *
+terminal_app_get_headermenu (TerminalApp *app)
+{
+  if (app->headermenu == NULL)
+    terminal_app_create_headermenu (app);
+
+  return app->headermenu;
+}
+
 /**
  * terminal_app_get_profile_section:
  * @app: a #TerminalApp
diff --git a/src/terminal-app.h b/src/terminal-app.h
index b98a4c35..15d5301c 100644
--- a/src/terminal-app.h
+++ b/src/terminal-app.h
@@ -101,6 +101,8 @@ TerminalSettingsList *terminal_app_get_profiles_list (TerminalApp *app);
 
 GMenuModel *terminal_app_get_menubar (TerminalApp *app);
 
+GMenuModel *terminal_app_get_headermenu (TerminalApp *app);
+
 GMenuModel *terminal_app_get_profile_section (TerminalApp *app);
 
 gboolean terminal_app_get_menu_unified (TerminalApp *app);
diff --git a/src/terminal-headerbar.c b/src/terminal-headerbar.c
index 58132e31..66173c20 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,14 @@ G_DEFINE_TYPE_WITH_PRIVATE (TerminalHeaderbar, terminal_headerbar, GTK_TYPE_HEAD
 static void
 terminal_headerbar_init (TerminalHeaderbar *headerbar)
 {
-  //  TerminalHeaderbarPrivate *priv = PRIV (headerbar);
+  TerminalHeaderbarPrivate *priv = PRIV (headerbar);
   GtkWidget *widget = GTK_WIDGET (headerbar);
+  TerminalApp *app = terminal_app_get ();
 
   gtk_widget_init_template (widget);
+
+  gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (priv->menubutton),
+                                  terminal_app_get_headermenu (app));
 }
 
 static void
@@ -118,6 +123,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 626273ce..1e12ac51 100644
--- a/src/terminal-headerbar.ui
+++ b/src/terminal-headerbar.ui
@@ -38,6 +38,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..1d970154
--- /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</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..8fd50407 100644
--- a/src/terminal.gresource.xml
+++ b/src/terminal.gresource.xml
@@ -19,6 +19,7 @@
   <gresource prefix="/org/gnome/terminal">
     <file alias="css/terminal.css" compressed="true">terminal.common.css</file>
     <file alias="ui/headerbar.ui" compressed="true" preprocess="xml-stripblanks">terminal-headerbar.ui</file>
+    <file alias="ui/headerbar-menu.ui" compressed="true" 
preprocess="xml-stripblanks">terminal-headermenu.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>
     <file alias="ui/notebook-menu.ui" compressed="true" 
preprocess="xml-stripblanks">terminal-notebook-menu.ui</file>


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