Load UI resources as GResources, not from the file system.

This commit is contained in:
Michael James Gratton 2016-04-03 19:21:50 +10:00 committed by Adam Dingle
parent 2a6120ba49
commit fe928afbdc
4 changed files with 14 additions and 21 deletions

View file

@ -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.

View file

@ -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

View file

@ -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();

View file

@ -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();