[gnome-clocks/bilelmoussaoui/css] CSS: simplify loading code



commit 8cb69cffc3c9027e58e6cd386afe2444caa9dd85
Author: Bilal Elmoussaoui <bil elmoussaoui gmail com>
Date:   Sat Apr 4 13:40:53 2020 +0200

    CSS: simplify loading code
    
    the current code assumed we might add more 'themes' support
    we only need to special case highcontrast
    
    closes #89

 src/application.vala |  7 ++++---
 src/utils.vala       | 11 ++---------
 2 files changed, 6 insertions(+), 12 deletions(-)
---
diff --git a/src/application.vala b/src/application.vala
index 24ac931..dcd36d2 100644
--- a/src/application.vala
+++ b/src/application.vala
@@ -111,13 +111,14 @@ public class Application : Gtk.Application {
         string theme_name;
 
         settings.get ("gtk-theme-name", out theme_name);
-        Utils.load_theme_css (theme_name);
+               if (theme_name.down () == "highcontrast") {
+                       Utils.load_css ("/org/gnome/clocks/css/gnome-clocks.highcontrast.css");
+               }
     }
 
     protected override void startup () {
         base.startup ();
-
-        Utils.load_main_css ();
+        Utils.load_css ("/org/gnome/clocks/css/gnome-clocks.css");
 
         set_resource_base_path ("/org/gnome/clocks/");
 
diff --git a/src/utils.vala b/src/utils.vala
index 74b912d..2ecd14e 100644
--- a/src/utils.vala
+++ b/src/utils.vala
@@ -36,22 +36,15 @@ const double RISESET_CORRECTION_ASTRONOMICAL = 18.0;
 namespace Clocks {
 namespace Utils {
 
-private void load_css (string css, bool required) {
+public void load_css (string resource_uri) {
     var provider = new Gtk.CssProvider ();
-    provider.load_from_resource ("/org/gnome/clocks/css/" + css + ".css");
+    provider.load_from_resource (resource_uri);
 
     Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (),
                                               provider,
                                               Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
 }
 
-public void load_main_css () {
-    load_css ("gnome-clocks", true);
-}
-
-public void load_theme_css (string theme_name) {
-    load_css ("gnome-clocks." + theme_name.down (), false);
-}
 
 public void time_to_hms (double t, out int h, out int m, out int s, out double remainder) {
     h = (int) t / 3600;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]