[gnome-dictionary] Use GTK's automagic menu loading
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-dictionary] Use GTK's automagic menu loading
- Date: Thu, 14 Jan 2016 21:12:07 +0000 (UTC)
commit ff46d7628515b3ef5bd0bf38181edbe8629bdb92
Author: Emmanuele Bassi <ebassi gnome org>
Date: Thu Jan 14 20:55:10 2016 +0000
Use GTK's automagic menu loading
Instead of loading the application and the menu button popup ourselves
we should reuse the support in GTK+ for automatically loading menus.
This simplifies our code base.
src/gdict-app-menus.ui | 2 +-
src/gdict-app.c | 10 +---------
src/gdict-window.c | 39 +++++++++++++++++----------------------
src/gdict.gresource.xml | 2 +-
4 files changed, 20 insertions(+), 33 deletions(-)
---
diff --git a/src/gdict-app-menus.ui b/src/gdict-app-menus.ui
index f6a462e..03bdd4e 100644
--- a/src/gdict-app-menus.ui
+++ b/src/gdict-app-menus.ui
@@ -30,7 +30,7 @@
</section>
</menu>
- <menu id="menubar">
+ <menu id="popup">
<section>
<item>
<attribute name="label" translatable="yes">_Save a Copy...</attribute>
diff --git a/src/gdict-app.c b/src/gdict-app.c
index 7ae4201..557629d 100644
--- a/src/gdict-app.c
+++ b/src/gdict-app.c
@@ -321,23 +321,14 @@ gdict_app_startup (GApplication *application)
static const char *lookup_accels[2] = { "<Primary>l", NULL };
static const char *escape_accels[2] = { "Escape", NULL };
- GtkBuilder *builder = gtk_builder_new ();
- GError * error = NULL;
-
G_APPLICATION_CLASS (gdict_app_parent_class)->startup (application);
g_action_map_add_action_entries (G_ACTION_MAP (application),
app_entries, G_N_ELEMENTS (app_entries),
application);
- gtk_builder_add_from_resource (builder, "/org/gnome/Dictionary/gdict-app-menus.ui", NULL);
-
- gtk_application_set_app_menu (GTK_APPLICATION (application),
- G_MENU_MODEL (gtk_builder_get_object (builder, "app-menu")));
gtk_application_set_accels_for_action (GTK_APPLICATION (application), "win.lookup", lookup_accels);
gtk_application_set_accels_for_action (GTK_APPLICATION (application), "win.escape", escape_accels);
-
- g_object_unref (builder);
}
static void
@@ -376,6 +367,7 @@ gdict_app_new (void)
{
return g_object_new (gdict_app_get_type (),
"application-id", "org.gnome.Dictionary",
+ "resource-base-path", "/org/gnome/Dictionary",
"flags", G_APPLICATION_HANDLES_COMMAND_LINE,
NULL);
}
diff --git a/src/gdict-window.c b/src/gdict-window.c
index 3304cd5..8ea2629 100644
--- a/src/gdict-window.c
+++ b/src/gdict-window.c
@@ -1322,23 +1322,21 @@ gdict_window_handle_notify_position_cb (GtkWidget *widget,
window->sidebar_width = window_width - pos;
}
-static GObject *
-gdict_window_constructor (GType type,
- guint n_construct_properties,
- GObjectConstructParam *construct_params)
+static void
+gdict_window_constructed (GObject *gobject)
{
+ GApplication *app;
GObject *object;
GdictWindow *window;
- GtkBuilder *builder;
GtkWidget *handle;
GtkWidget *frame1, *frame2;
GtkWidget *button;
PangoFontDescription *font_desc;
gchar *font_name;
GtkAllocation allocation;
+ GMenu *menu;
- object = G_OBJECT_CLASS (gdict_window_parent_class)->constructor (type, n_construct_properties,
construct_params);
- window = GDICT_WINDOW (object);
+ window = GDICT_WINDOW (gobject);
window->in_construction = TRUE;
@@ -1351,31 +1349,29 @@ gdict_window_constructor (GType type,
window);
gdict_window_ensure_menu_state (window);
+ /* The :application property of GtkWindow is not yet set inside
+ * the constructed() vfunc, so we need to use the global singleton
+ */
+ app = g_application_get_default ();
+ menu = gtk_application_get_menu_by_id (GTK_APPLICATION (app), "popup");
button = gtk_menu_button_new ();
- builder = gtk_builder_new ();
- gtk_builder_add_from_resource (builder, "/org/gnome/Dictionary/gdict-app-menus.ui", NULL);
- gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (button),
- G_MENU_MODEL (gtk_builder_get_object (builder, "menubar")));
- g_object_unref (builder);
+ gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (button), G_MENU_MODEL (menu));
gtk_menu_button_set_direction (GTK_MENU_BUTTON (button), GTK_ARROW_NONE);
gtk_header_bar_pack_end (GTK_HEADER_BAR (window->header_bar), button);
gtk_widget_show (button);
- window->completion_model = gtk_list_store_new (COMPLETION_N_COLUMNS,
- G_TYPE_STRING);
+ window->completion_model = gtk_list_store_new (COMPLETION_N_COLUMNS, G_TYPE_STRING);
window->completion = gtk_entry_completion_new ();
gtk_entry_completion_set_popup_completion (window->completion, TRUE);
gtk_entry_completion_set_model (window->completion,
GTK_TREE_MODEL (window->completion_model));
- gtk_entry_completion_set_text_column (window->completion,
- COMPLETION_TEXT_COLUMN);
+ gtk_entry_completion_set_text_column (window->completion, COMPLETION_TEXT_COLUMN);
if (window->word)
gtk_entry_set_text (GTK_ENTRY (window->entry), window->word);
- gtk_entry_set_completion (GTK_ENTRY (window->entry),
- window->completion);
+ gtk_entry_set_completion (GTK_ENTRY (window->entry), window->completion);
g_signal_connect_swapped (window->entry, "activate",
G_CALLBACK (lookup_word),
window);
@@ -1418,8 +1414,7 @@ gdict_window_constructor (GType type,
/* Speller */
window->speller = gdict_speller_new ();
if (window->context)
- gdict_speller_set_context (GDICT_SPELLER (window->speller),
- window->context);
+ gdict_speller_set_context (GDICT_SPELLER (window->speller), window->context);
g_signal_connect (window->speller, "word-activated",
G_CALLBACK (speller_word_activated_cb),
window);
@@ -1556,7 +1551,7 @@ gdict_window_constructor (GType type,
window->in_construction = FALSE;
- return object;
+ G_OBJECT_CLASS (gdict_window_parent_class)->constructed (gobject);
}
static void
@@ -1658,7 +1653,7 @@ gdict_window_class_init (GdictWindowClass *klass)
gobject_class->dispose = gdict_window_dispose;
gobject_class->set_property = gdict_window_set_property;
gobject_class->get_property = gdict_window_get_property;
- gobject_class->constructor = gdict_window_constructor;
+ gobject_class->constructed = gdict_window_constructed;
g_object_class_install_properties (gobject_class,
LAST_PROP,
diff --git a/src/gdict.gresource.xml b/src/gdict.gresource.xml
index 59a12f3..d95716e 100644
--- a/src/gdict.gresource.xml
+++ b/src/gdict.gresource.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/gnome/Dictionary">
- <file preprocess="xml-stripblanks">gdict-app-menus.ui</file>
+ <file preprocess="xml-stripblanks" alias="gtk/menus.ui">gdict-app-menus.ui</file>
<file preprocess="xml-stripblanks">gdict-app-window.ui</file>
<file preprocess="xml-stripblanks">gdict-pref-dialog.ui</file>
<file preprocess="xml-stripblanks">gdict-source-dialog.ui</file>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]