Move global GTK CSS loading from main window to the app
This commit is contained in:
parent
8f8709f2af
commit
1ea97dcdb6
2 changed files with 36 additions and 27 deletions
|
|
@ -424,6 +424,23 @@ public class Application.Client : Gtk.Application {
|
|||
add_edit_accelerators(Action.Edit.REDO, { "<Ctrl><Shift>Z" });
|
||||
add_edit_accelerators(Action.Edit.UNDO, { "<Ctrl>Z" });
|
||||
|
||||
// Load Geary GTK CSS
|
||||
var provider = new Gtk.CssProvider();
|
||||
Gtk.StyleContext.add_provider_for_screen(
|
||||
Gdk.Display.get_default().get_default_screen(),
|
||||
provider,
|
||||
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
|
||||
);
|
||||
provider.parsing_error.connect(on_css_parse_error);
|
||||
try {
|
||||
var file = GLib.File.new_for_uri(
|
||||
"resource:///org/gnome/Geary/geary.css"
|
||||
);
|
||||
provider.load_from_file(file);
|
||||
} catch (GLib.Error error) {
|
||||
warning("Could not load CSS: %s", error.message);
|
||||
}
|
||||
|
||||
MainWindow.add_accelerators(this);
|
||||
Composer.Widget.add_accelerators(this);
|
||||
Components.Inspector.add_accelerators(this);
|
||||
|
|
@ -1066,4 +1083,19 @@ public class Application.Client : Gtk.Application {
|
|||
}
|
||||
}
|
||||
|
||||
private void on_css_parse_error(Gtk.CssSection section, GLib.Error error) {
|
||||
uint start = section.get_start_line();
|
||||
uint end = section.get_end_line();
|
||||
if (start == end) {
|
||||
warning(
|
||||
"Error parsing %s:%u: %s",
|
||||
section.get_file().get_uri(), start, error.message
|
||||
);
|
||||
} else {
|
||||
warning(
|
||||
"Error parsing %s:%u-%u: %s",
|
||||
section.get_file().get_uri(), start, end, error.message
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -284,6 +284,10 @@ public class Application.MainWindow :
|
|||
load_config(application.config);
|
||||
restore_saved_window_state();
|
||||
|
||||
if (_PROFILE != "") {
|
||||
this.get_style_context().add_class("devel");
|
||||
}
|
||||
|
||||
// Edit actions
|
||||
this.edit_actions.add_action_entries(EDIT_ACTIONS, this);
|
||||
insert_action_group(Action.Edit.GROUP_NAME, this.edit_actions);
|
||||
|
|
@ -291,7 +295,6 @@ public class Application.MainWindow :
|
|||
// Window actions
|
||||
add_action_entries(MainWindow.WINDOW_ACTIONS, this);
|
||||
|
||||
set_styling();
|
||||
setup_layout(application.config);
|
||||
on_change_orientation();
|
||||
|
||||
|
|
@ -889,32 +892,6 @@ public class Application.MainWindow :
|
|||
notification.show();
|
||||
}
|
||||
|
||||
private void set_styling() {
|
||||
Gtk.CssProvider provider = new Gtk.CssProvider();
|
||||
Gtk.StyleContext.add_provider_for_screen(Gdk.Display.get_default().get_default_screen(),
|
||||
provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
|
||||
|
||||
if (_PROFILE != "") {
|
||||
Gtk.StyleContext ctx = this.get_style_context();
|
||||
ctx.add_class("devel");
|
||||
}
|
||||
|
||||
provider.parsing_error.connect((section, error) => {
|
||||
uint start = section.get_start_line();
|
||||
uint end = section.get_end_line();
|
||||
if (start == end)
|
||||
debug("Error parsing css on line %u: %s", start, error.message);
|
||||
else
|
||||
debug("Error parsing css on lines %u-%u: %s", start, end, error.message);
|
||||
});
|
||||
try {
|
||||
File file = File.new_for_uri(@"resource:///org/gnome/Geary/geary.css");
|
||||
provider.load_from_file(file);
|
||||
} catch (Error e) {
|
||||
error("Could not load CSS: %s", e.message);
|
||||
}
|
||||
}
|
||||
|
||||
private void setup_layout(Configuration config) {
|
||||
this.notify["has-toplevel-focus"].connect(on_has_toplevel_focus);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue