From fe928afbdc1004cda4706d92d15407634803e130 Mon Sep 17 00:00:00 2001 From: Michael James Gratton Date: Sun, 3 Apr 2016 19:21:50 +1000 Subject: [PATCH] Load UI resources as GResources, not from the file system. --- src/client/application/geary-application.vala | 19 +++++++++---------- src/client/application/geary-controller.vala | 10 ++-------- src/client/components/main-toolbar.vala | 4 ++-- src/client/composer/composer-widget.vala | 2 +- 4 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/client/application/geary-application.vala b/src/client/application/geary-application.vala index 9f8ca0fe..072921ec 100644 --- a/src/client/application/geary-application.vala +++ b/src/client/application/geary-application.vala @@ -279,12 +279,11 @@ public class GearyApplication : Gtk.Application { return exec_dir.has_prefix(prefix_dir) ? prefix_dir : null; } - // Creates a GTK builder given the filename of a UI file in the ui directory. - public Gtk.Builder create_builder(string ui_filename) { + // Creates a GTK builder given the name of a GResource. + public Gtk.Builder create_builder(string name) { Gtk.Builder builder = new Gtk.Builder(); try { - builder.add_from_file(get_resource_directory().get_child("ui").get_child( - ui_filename).get_path()); + builder.add_from_resource("/org/gnome/Geary/" + name); } catch(GLib.Error error) { warning("Unable to create Gtk.Builder: %s".printf(error.message)); } @@ -309,18 +308,18 @@ public class GearyApplication : Gtk.Application { return get_resource_directory().get_child("ui").get_child(filename); } - // Loads a UI file (in the ui directory) into the specified UI manager. - public void load_ui_file_for_manager(Gtk.UIManager ui, string ui_filename) { + // Loads a UI GResource into the specified UI manager. + public void load_ui_resource_for_manager(Gtk.UIManager ui, string name) { try { - ui.add_ui_from_file(get_ui_file(ui_filename).get_path()); + ui.add_ui_from_resource("/org/gnome/Geary/" + name); } catch(GLib.Error error) { warning("Unable to create Gtk.UIManager: %s".printf(error.message)); } } - // Loads a UI file (in the ui directory) into the UI manager. - public void load_ui_file(string ui_filename) { - load_ui_file_for_manager(ui_manager, ui_filename); + // Loads a UI GResource into the UI manager. + public void load_ui_resource(string name) { + load_ui_resource_for_manager(ui_manager, name); } // This call will fire "exiting" only if it's not already been fired. diff --git a/src/client/application/geary-controller.vala b/src/client/application/geary-controller.vala index 27724bcb..cb192487 100644 --- a/src/client/application/geary-controller.vala +++ b/src/client/application/geary-controller.vala @@ -180,7 +180,7 @@ public class GearyController : Geary.BaseObject { // Setup actions. setup_actions(); - GearyApplication.instance.load_ui_file("accelerators.ui"); + GearyApplication.instance.load_ui_resource("accelerators.ui"); // Listen for attempts to close the application. GearyApplication.instance.exiting.connect(on_application_exiting); @@ -592,13 +592,7 @@ public class GearyController : Geary.BaseObject { } GearyApplication.instance.ui_manager.insert_action_group(action_group, 0); - Gtk.Builder builder = new Gtk.Builder(); - try { - builder.add_from_file( - GearyApplication.instance.get_ui_file("app_menu.interface").get_path()); - } catch (Error e) { - error("Unable to parse app_menu.interface: %s", e.message); - } + Gtk.Builder builder = GearyApplication.instance.create_builder("app_menu.interface"); app_menu = (MenuModel) builder.get_object("app-menu"); // We'd *like* to always export an app menu and just let the shell diff --git a/src/client/components/main-toolbar.vala b/src/client/components/main-toolbar.vala index a9eeb52f..8d33713e 100644 --- a/src/client/components/main-toolbar.vala +++ b/src/client/components/main-toolbar.vala @@ -57,7 +57,7 @@ public class MainToolbar : Gtk.Box { bool rtl = get_direction() == Gtk.TextDirection.RTL; // Assemble mark menu. - GearyApplication.instance.load_ui_file("toolbar_mark_menu.ui"); + GearyApplication.instance.load_ui_resource("toolbar_mark_menu.ui"); Gtk.Menu mark_menu = (Gtk.Menu) GearyApplication.instance.ui_manager.get_widget("/ui/ToolbarMarkMenu"); mark_menu.foreach(GtkUtil.show_menuitem_accel_labels); @@ -70,7 +70,7 @@ public class MainToolbar : Gtk.Box { folder_header.add_start(folder_header.create_pill_buttons(insert, false)); // Assemble the empty menu - GearyApplication.instance.load_ui_file("toolbar_empty_menu.ui"); + GearyApplication.instance.load_ui_resource("toolbar_empty_menu.ui"); Gtk.Menu empty_menu = (Gtk.Menu) GearyApplication.instance.ui_manager.get_widget("/ui/ToolbarEmptyMenu"); empty_menu.foreach(GtkUtil.show_menuitem_accel_labels); insert.clear(); diff --git a/src/client/composer/composer-widget.vala b/src/client/composer/composer-widget.vala index 18b53323..d853c385 100644 --- a/src/client/composer/composer-widget.vala +++ b/src/client/composer/composer-widget.vala @@ -451,7 +451,7 @@ public class ComposerWidget : Gtk.EventBox { ui = new Gtk.UIManager(); ui.insert_action_group(actions, 0); - GearyApplication.instance.load_ui_file_for_manager(ui, "composer_accelerators.ui"); + GearyApplication.instance.load_ui_resource_for_manager(ui, "composer_accelerators.ui"); add_extra_accelerators();