[gnome-terminal/wip/fmuellner/headerbar: 5/6] window: Add primary menu to headerbar
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-terminal/wip/fmuellner/headerbar: 5/6] window: Add primary menu to headerbar
- Date: Fri, 2 Nov 2018 20:03:29 +0000 (UTC)
commit 46ee5ed009ad2292b800bb06316c9e90c342d52f
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-app.c | 7 ++++++-
src/terminal-headerbar.c | 13 +++++++++++--
src/terminal-headerbar.ui | 19 +++++++++++++++++++
src/terminal-headermenu.ui | 36 ++++++++++++++++++++++++++++++++++++
src/terminal.gresource.xml | 1 +
6 files changed, 74 insertions(+), 3 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-app.c b/src/terminal-app.c
index bb232e09..b1e6c464 100644
--- a/src/terminal-app.c
+++ b/src/terminal-app.c
@@ -645,6 +645,11 @@ terminal_app_startup (GApplication *application)
"gtk-shell-shows-menubar", &shell_shows_menubar,
NULL);
+ /* Header menu */
+ GMenu *headermenu_new_terminal_section = gtk_application_get_menu_by_id (GTK_APPLICATION (app),
+ "new-terminal-section");
+ fill_new_terminal_section (app, headermenu_new_terminal_section, NULL, 0); /* no submenu */
+
/* Menubar */
/* If the menubar is shown by the shell, omit mnemonics for the submenus. This is because Alt+F etc.
* are more important to be usable in the terminal, the menu cannot be replaced runtime (to toggle
@@ -671,7 +676,7 @@ terminal_app_startup (GApplication *application)
/* Install the encodings submenu */
terminal_encodings_append_menu (app->menubar_set_encoding_submenu);
- /* Show/hide the menubar as appropriate: If the shell wants to show the menubar, make it available. */
+ /* If the shell wants to show the menubar, make it available. */
if (shell_shows_menubar)
gtk_application_set_menubar (GTK_APPLICATION (app), app->menubar);
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 6b6b1bf5..d7f65b3a 100644
--- a/src/terminal-headerbar.ui
+++ b/src/terminal-headerbar.ui
@@ -37,6 +37,25 @@
</child>
</object>
</child>
+ <child>
+ <object class="GtkMenuButton" id="menubutton">
+ <property name="visible">True</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..156fa7a3
--- /dev/null
+++ b/src/terminal-headermenu.ui
@@ -0,0 +1,36 @@
+<?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 id="new-terminal-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]