[gnome-documents] application: Add support for Night Mode



commit bd6ce176d055e23b8f4aaf0ed42c5fb542640aa3
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Dec 10 19:28:45 2014 +0100

    application: Add support for Night Mode
    
    https://bugzilla.gnome.org/show_bug.cgi?id=725400

 data/org.gnome.books.gschema.xml     |    5 +++++
 data/org.gnome.documents.gschema.xml |    5 +++++
 src/application.js                   |   26 ++++++++++++++++++++++++++
 src/resources/app-menu.ui            |    4 ++++
 4 files changed, 40 insertions(+), 0 deletions(-)
---
diff --git a/data/org.gnome.books.gschema.xml b/data/org.gnome.books.gschema.xml
index 80f0736..d8f071c 100644
--- a/data/org.gnome.books.gschema.xml
+++ b/data/org.gnome.books.gschema.xml
@@ -20,5 +20,10 @@
       <summary>Window maximized</summary>
       <description>Window maximized state</description>
     </key>
+    <key name="night-mode" type="b">
+      <default>false</default>
+      <summary>Night mode</summary>
+      <description>Whether the application is in night mode.</description>
+    </key>
   </schema>
 </schemalist>
diff --git a/data/org.gnome.documents.gschema.xml b/data/org.gnome.documents.gschema.xml
index 6bbe010..e4c8a72 100644
--- a/data/org.gnome.documents.gschema.xml
+++ b/data/org.gnome.documents.gschema.xml
@@ -20,5 +20,10 @@
       <summary>Window maximized</summary>
       <description>Window maximized state</description>
     </key>
+    <key name="night-mode" type="b">
+      <default>false</default>
+      <summary>Night mode</summary>
+      <description>Whether the application is in night mode.</description>
+    </key>
   </schema>
 </schemalist>
diff --git a/src/application.js b/src/application.js
index 26a70e6..58ea20d 100644
--- a/src/application.js
+++ b/src/application.js
@@ -197,6 +197,22 @@ const Application = new Lang.Class({
             }));
     },
 
+    _nightModeCreateHook: function(action) {
+        settings.connect('changed::night-mode', Lang.bind(this,
+            function() {
+                let state = settings.get_value('night-mode');
+                if (state.get_boolean()[0] != action.state.get_boolean()[0])
+                    action.state = state;
+
+                let gtkSettings = Gtk.Settings.get_default();
+                gtkSettings.gtk_application_prefer_dark_theme = state.get_boolean();
+            }));
+
+        let state = settings.get_value('night-mode');
+        let gtkSettings = Gtk.Settings.get_default();
+        gtkSettings.gtk_application_prefer_dark_theme = state.get_boolean();
+    },
+
     _onActionQuit: function() {
         this._mainWindow.window.destroy();
     },
@@ -215,6 +231,12 @@ const Application = new Lang.Class({
         }
     },
 
+    _onActionNightMode: function(action) {
+        let state = action.get_state();
+        action.change_state(GLib.Variant.new('b', !state.get_boolean()));
+        settings.set_value('night-mode', GLib.Variant.new('b', !state.get_boolean()));
+    },
+
     _onActionFullscreen: function() {
         modeController.toggleFullscreen();
     },
@@ -477,6 +499,10 @@ const Application = new Lang.Class({
               create_hook: this._fullscreenCreateHook,
               accel: 'F11',
               window_mode: WindowMode.WindowMode.PREVIEW },
+            { name: 'night-mode',
+              callback: this._onActionNightMode,
+              create_hook: this._nightModeCreateHook,
+              state: settings.get_value('night-mode') },
             { name: 'gear-menu',
               callback: this._onActionToggle,
               state: GLib.Variant.new('b', false),
diff --git a/src/resources/app-menu.ui b/src/resources/app-menu.ui
index 5202e21..c07ee3f 100644
--- a/src/resources/app-menu.ui
+++ b/src/resources/app-menu.ui
@@ -5,6 +5,10 @@
         <attribute name="action">app.fullscreen</attribute>
         <attribute name="label" translatable="yes">Fullscreen</attribute>
       </item>
+      <item>
+        <attribute name="action">app.night-mode</attribute>
+        <attribute name="label" translatable="yes">Night Mode</attribute>
+      </item>
     </section>
     <section>
       <item>


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