[devhelp] App: get app-menu from automatic GtkApplication resource
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [devhelp] App: get app-menu from automatic GtkApplication resource
- Date: Fri, 15 Dec 2017 14:58:04 +0000 (UTC)
commit 6d8fd477b671e46eb5f6cfadbc5eb500f7a2974e
Author: Sébastien Wilmet <swilmet gnome org>
Date: Fri Dec 15 15:48:57 2017 +0100
App: get app-menu from automatic GtkApplication resource
po/POTFILES.in | 4 +-
src/Makefile.am | 2 +-
src/dh-app.c | 44 ++++++++++++++----------------------
src/dh.gresource.xml | 4 ++-
src/{devhelp-menu.ui => menus.ui} | 4 ++-
5 files changed, 26 insertions(+), 32 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 936328b..41ed3bb 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -5,8 +5,6 @@ data/org.gnome.Devhelp.desktop.in.in
data/org.gnome.devhelp.gschema.xml
misc/gedit-plugin/devhelp.plugin.desktop.in
misc/gedit-plugin/devhelp.py
-src/devhelp-menu.ui
-src/help-overlay.ui
src/dh-app.c
src/dh-assistant.c
src/dh-assistant.ui
@@ -22,3 +20,5 @@ src/dh-sidebar.c
src/dh-util.c
src/dh-window.c
src/dh-window.ui
+src/help-overlay.ui
+src/menus.ui
diff --git a/src/Makefile.am b/src/Makefile.am
index 4664b36..dd1d225 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -154,11 +154,11 @@ devhelp_LDFLAGS = \
$(AM_LDFLAGS)
resource_files = \
- devhelp-menu.ui \
dh-assistant.ui \
dh-preferences.ui \
dh-window.ui \
help-overlay.ui \
+ menus.ui \
$(NULL)
dh-resources.c: dh.gresource.xml $(resource_files)
diff --git a/src/dh-app.c b/src/dh-app.c
index 659fda1..f7afb7f 100644
--- a/src/dh-app.c
+++ b/src/dh-app.c
@@ -352,45 +352,35 @@ setup_accelerators (DhApp *self)
/******************************************************************************/
static void
+set_app_menu_if_needed (GtkApplication *app)
+{
+ GMenu *manual_app_menu;
+
+ manual_app_menu = gtk_application_get_menu_by_id (app, "manual-app-menu");
+
+ /* Have the g_return in all cases, to catch problems in all cases. */
+ g_return_if_fail (manual_app_menu != NULL);
+
+ if (gtk_application_prefers_app_menu (app))
+ gtk_application_set_app_menu (app, G_MENU_MODEL (manual_app_menu));
+}
+
+static void
dh_app_startup (GApplication *application)
{
DhApp *app = DH_APP (application);
g_application_set_resource_base_path (application, "/org/gnome/devhelp");
- /* Chain up parent's startup */
- G_APPLICATION_CLASS (dh_app_parent_class)->startup (application);
+ if (G_APPLICATION_CLASS (dh_app_parent_class)->startup != NULL)
+ G_APPLICATION_CLASS (dh_app_parent_class)->startup (application);
- /* Setup actions */
g_action_map_add_action_entries (G_ACTION_MAP (app),
app_entries, G_N_ELEMENTS (app_entries),
app);
- if (gtk_application_prefers_app_menu (GTK_APPLICATION (app))) {
- GtkBuilder *builder;
- GError *error = NULL;
-
- /* Setup menu */
- builder = gtk_builder_new ();
-
- if (!gtk_builder_add_from_resource (builder,
- "/org/gnome/devhelp/devhelp-menu.ui",
- &error)) {
- g_warning ("loading menu builder file: %s", error->message);
- g_error_free (error);
- } else {
- GMenuModel *app_menu;
-
- app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "app-menu"));
- gtk_application_set_app_menu (GTK_APPLICATION (application),
- app_menu);
- }
-
- g_object_unref (builder);
- }
-
- /* Setup accelerators */
setup_accelerators (app);
+ set_app_menu_if_needed (GTK_APPLICATION (app));
}
static void
diff --git a/src/dh.gresource.xml b/src/dh.gresource.xml
index 5dda3b0..f5e9d32 100644
--- a/src/dh.gresource.xml
+++ b/src/dh.gresource.xml
@@ -1,10 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/gnome/devhelp">
- <file preprocess="xml-stripblanks">devhelp-menu.ui</file>
<file preprocess="xml-stripblanks">dh-assistant.ui</file>
<file preprocess="xml-stripblanks">dh-preferences.ui</file>
<file preprocess="xml-stripblanks">dh-window.ui</file>
<file compressed="true" preprocess="xml-stripblanks">help-overlay.ui</file>
</gresource>
+ <gresource prefix="/org/gnome/devhelp/gtk">
+ <file preprocess="xml-stripblanks">menus.ui</file>
+ </gresource>
</gresources>
diff --git a/src/devhelp-menu.ui b/src/menus.ui
similarity index 93%
rename from src/devhelp-menu.ui
rename to src/menus.ui
index 9cf1ca8..79018dc 100644
--- a/src/devhelp-menu.ui
+++ b/src/menus.ui
@@ -3,6 +3,7 @@
<!--
Copyright (C) 2010 Imendio AB
Copyright (C) 2012 Aleksander Morgado <aleksander gnu org>
+ Copyright (C) 2017 Sébastien Wilmet <swilmet gnome org>
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
@@ -22,7 +23,8 @@
<interface>
<requires lib="gtk+" version="3.0"/>
- <menu id="app-menu">
+ <!-- The app menu is set manually if needed. -->
+ <menu id="manual-app-menu">
<section>
<item>
<attribute name="label" translatable="yes">New _Window</attribute>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]