[meld] Add per-application preference for GTK's dark theme support (#571)



commit 6b0502dabd06229795dd7d7cc3a638d57f5b7d15
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sun Jul 25 09:57:06 2021 +1000

    Add per-application preference for GTK's dark theme support (#571)

 data/org.gnome.meld.gschema.xml  |  7 +++++++
 meld/preferences.py              |  2 ++
 meld/resources/ui/preferences.ui | 20 ++++++++++++++++++--
 meld/settings.py                 |  7 ++++++-
 4 files changed, 33 insertions(+), 3 deletions(-)
---
diff --git a/data/org.gnome.meld.gschema.xml b/data/org.gnome.meld.gschema.xml
index d966b43b..93b4bf35 100644
--- a/data/org.gnome.meld.gschema.xml
+++ b/data/org.gnome.meld.gschema.xml
@@ -52,6 +52,13 @@
 
   <schema id="org.gnome.meld" path="/org/gnome/meld/">
 
+      <!-- GtkSettings overrides -->
+      <key name="prefer-dark-theme" type="b">
+          <default>false</default>
+          <summary>Prefer application-wide dark theme</summary>
+          <description>If true, the GTK dark theme variant will be used, if available. Note that this is 
separate from the syntax highlighting scheme.</description>
+      </key>
+
       <!-- File loading settings -->
       <key name="detect-encodings" type="as">
           <default>[]</default>
diff --git a/meld/preferences.py b/meld/preferences.py
index cf8b9def..8139a65f 100644
--- a/meld/preferences.py
+++ b/meld/preferences.py
@@ -258,6 +258,7 @@ class PreferencesDialog(Gtk.Dialog):
     checkbutton_highlight_current_line = Gtk.Template.Child()
     checkbutton_ignore_blank_lines = Gtk.Template.Child()
     checkbutton_ignore_symlinks = Gtk.Template.Child()
+    checkbutton_prefer_dark_theme = Gtk.Template.Child()
     checkbutton_shallow_compare = Gtk.Template.Child()
     checkbutton_show_commit_margin = Gtk.Template.Child()
     checkbutton_show_line_numbers = Gtk.Template.Child()
@@ -292,6 +293,7 @@ class PreferencesDialog(Gtk.Dialog):
             ('insert-spaces-instead-of-tabs', self.checkbutton_spaces_instead_of_tabs, 'active'),  # noqa: 
E501
             ('highlight-current-line', self.checkbutton_highlight_current_line, 'active'),  # noqa: E501
             ('show-line-numbers', self.checkbutton_show_line_numbers, 'active'),  # noqa: E501
+            ('prefer-dark-theme', self.checkbutton_prefer_dark_theme, 'active'),  # noqa: E501
             ('highlight-syntax', self.checkbutton_use_syntax_highlighting, 'active'),  # noqa: E501
             ('enable-space-drawer', self.checkbutton_show_whitespace, 'active'),  # noqa: E501
             ('use-system-editor', self.system_editor_checkbutton, 'active'),
diff --git a/meld/resources/ui/preferences.ui b/meld/resources/ui/preferences.ui
index 4f53b299..7f745b58 100644
--- a/meld/resources/ui/preferences.ui
+++ b/meld/resources/ui/preferences.ui
@@ -376,6 +376,22 @@
                                 <property name="position">6</property>
                               </packing>
                             </child>
+                            <child>
+                              <object class="GtkCheckButton" id="checkbutton_prefer_dark_theme">
+                                <property name="label" translatable="yes">Prefer dark theme</property>
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="receives_default">False</property>
+                                <property name="use_underline">True</property>
+                                <property name="xalign">0</property>
+                                <property name="draw_indicator">True</property>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">False</property>
+                                <property name="position">7</property>
+                              </packing>
+                            </child>
                             <child>
                               <object class="GtkCheckButton" id="checkbutton_use_syntax_highlighting">
                                 <property name="label" translatable="yes">Use s_yntax highlighting</property>
@@ -389,7 +405,7 @@
                               <packing>
                                 <property name="expand">False</property>
                                 <property name="fill">False</property>
-                                <property name="position">7</property>
+                                <property name="position">8</property>
                               </packing>
                             </child>
                             <child>
@@ -432,7 +448,7 @@
                               <packing>
                                 <property name="expand">False</property>
                                 <property name="fill">False</property>
-                                <property name="position">8</property>
+                                <property name="position">9</property>
                               </packing>
                             </child>
                           </object>
diff --git a/meld/settings.py b/meld/settings.py
index a240a8e3..942269c8 100644
--- a/meld/settings.py
+++ b/meld/settings.py
@@ -15,7 +15,7 @@
 
 import sys
 
-from gi.repository import Gio, GObject, GtkSource, Pango
+from gi.repository import Gio, GObject, Gtk, GtkSource, Pango
 
 import meld.conf
 import meld.filters
@@ -35,6 +35,7 @@ class MeldSettings(GObject.GObject):
         self.on_setting_changed(settings, 'filename-filters')
         self.on_setting_changed(settings, 'text-filters')
         self.on_setting_changed(settings, 'use-system-font')
+        self.on_setting_changed(settings, 'prefer-dark-theme')
         self.style_scheme = self._style_scheme_from_gsettings()
         settings.connect('changed', self.on_setting_changed)
 
@@ -50,6 +51,10 @@ class MeldSettings(GObject.GObject):
         elif key in ('use-system-font', 'custom-font'):
             self.font = self._current_font_from_gsetting()
             self.emit('changed', 'font')
+        elif key == 'prefer-dark-theme':
+            gtk_settings = Gtk.Settings.get_default()
+            prefer_dark = settings.get_boolean(key)
+            gtk_settings.props.gtk_application_prefer_dark_theme = prefer_dark
         elif key in ('style-scheme'):
             self.style_scheme = self._style_scheme_from_gsettings()
             self.emit('changed', 'style-scheme')


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