From 460237687f2ad03b60e33a43ebc8ce6ff8275499 Mon Sep 17 00:00:00 2001 From: Romain Vigier Date: Mon, 15 Jun 2020 16:44:12 +0200 Subject: [PATCH] Update sensitivity of the whole row --- src/preferences/Backgrounds.js | 28 +++- src/preferences/Commands.js | 28 +++- src/preferences/CursorTheme.js | 28 +++- src/preferences/IconTheme.js | 28 +++- src/preferences/Schedule.js | 259 ++++++++++++++++++--------------- 5 files changed, 218 insertions(+), 153 deletions(-) diff --git a/src/preferences/Backgrounds.js b/src/preferences/Backgrounds.js index 9f0c686..aea4070 100644 --- a/src/preferences/Backgrounds.js +++ b/src/preferences/Backgrounds.js @@ -36,13 +36,31 @@ if ( shell_minor_version <= 30 ) { var BackgroundsPreferences = class { constructor() { + const settings = extensionUtils.getSettings(); + const label = _('Backgrounds'); const description = _('You can set different backgrounds for day and night.'); const content = new SettingsList(); content.add_row(new SettingsListRow(_('Switch backgrounds'), new BackgroundsEnabledControl())); - content.add_row(new SettingsListRow(_('Day background'), new TimeBackgroundControl('day'))); - content.add_row(new SettingsListRow(_('Night background'), new TimeBackgroundControl('night'))); + + const day_background_row = new SettingsListRow(_('Day background'), new TimeBackgroundControl('day')); + settings.bind( + 'backgrounds-enabled', + day_background_row, + 'sensitive', + Gio.SettingsBindFlags.DEFAULT + ); + content.add_row(day_background_row); + + const night_background_row = new SettingsListRow(_('Night background'), new TimeBackgroundControl('night')); + settings.bind( + 'backgrounds-enabled', + night_background_row, + 'sensitive', + Gio.SettingsBindFlags.DEFAULT + ); + content.add_row(night_background_row); return new SettingsPage(label, description, content); } @@ -97,12 +115,6 @@ class TimeBackgroundControl { preview.set_from_pixbuf(pixbuf); }); button.connect('file-set', () => settings.set_string(`background-${time}`, button.get_uri())); - settings.bind( - 'backgrounds-enabled', - button, - 'sensitive', - Gio.SettingsBindFlags.DEFAULT - ); settings.connect(`changed::background-${time}`, () => button.set_uri(settings.get_string(`background-${time}`))); return button; diff --git a/src/preferences/Commands.js b/src/preferences/Commands.js index 0aa425f..2b3d61f 100644 --- a/src/preferences/Commands.js +++ b/src/preferences/Commands.js @@ -36,13 +36,31 @@ if ( shell_minor_version <= 30 ) { var CommandsPreferences = class { constructor() { + const settings = extensionUtils.getSettings(); + const label = _('Commands'); const description = _('You can set custom commands that will be run when the time of the day changes.'); const content = new SettingsList(); content.add_row(new SettingsListRow(_('Use custom commands'), new CommandsEnabledControl())); - content.add_row(new SettingsListRow(_('Sunrise'), new SuntimeCommandControl('sunrise'))); - content.add_row(new SettingsListRow(_('Sunset'), new SuntimeCommandControl('sunset'))); + + const day_command_row = new SettingsListRow(_('Sunrise'), new SuntimeCommandControl('sunrise')); + settings.bind( + 'commands-enabled', + day_command_row, + 'sensitive', + Gio.SettingsBindFlags.DEFAULT + ); + content.add_row(day_command_row); + + const night_command_row = new SettingsListRow(_('Sunset'), new SuntimeCommandControl('sunset')); + settings.bind( + 'commands-enabled', + night_command_row, + 'sensitive', + Gio.SettingsBindFlags.DEFAULT + ); + content.add_row(night_command_row); return new SettingsPage(label, description, content); } @@ -87,12 +105,6 @@ class SuntimeCommandControl { 'text', Gio.SettingsBindFlags.DEFAULT ); - settings.bind( - 'commands-enabled', - entry, - 'sensitive', - Gio.SettingsBindFlags.DEFAULT - ); return entry; } diff --git a/src/preferences/CursorTheme.js b/src/preferences/CursorTheme.js index 5c361ad..05ad438 100644 --- a/src/preferences/CursorTheme.js +++ b/src/preferences/CursorTheme.js @@ -37,13 +37,31 @@ if ( shell_minor_version <= 30 ) { var CursorThemePreferences = class { constructor() { + const settings = extensionUtils.getSettings(); + const label = _('Cursor theme'); const description = _('You can set different cursor themes for day and night.'); const content = new SettingsList(); content.add_row(new SettingsListRow(_('Switch cursor variants'), new CursorVariantsEnabledControl())); - content.add_row(new SettingsListRow(_('Day variant'), new TimeCursorVariantControl('day'))); - content.add_row(new SettingsListRow(_('Night variant'), new TimeCursorVariantControl('night'))); + + const day_variant_row = new SettingsListRow(_('Day variant'), new TimeCursorVariantControl('day')); + settings.bind( + 'cursor-variants-enabled', + day_variant_row, + 'sensitive', + Gio.SettingsBindFlags.DEFAULT + ); + content.add_row(day_variant_row); + + const night_variant_row = new SettingsListRow(_('Night variant'), new TimeCursorVariantControl('night')); + settings.bind( + 'cursor-variants-enabled', + night_variant_row, + 'sensitive', + Gio.SettingsBindFlags.DEFAULT + ); + content.add_row(night_variant_row); return new SettingsPage(label, description, content); } @@ -83,12 +101,6 @@ class TimeCursorVariantControl { 'active-id', Gio.SettingsBindFlags.DEFAULT ); - settings.bind( - 'cursor-variants-enabled', - combo, - 'sensitive', - Gio.SettingsBindFlags.DEFAULT - ); return combo; } diff --git a/src/preferences/IconTheme.js b/src/preferences/IconTheme.js index afc00c4..f4d747b 100644 --- a/src/preferences/IconTheme.js +++ b/src/preferences/IconTheme.js @@ -37,13 +37,31 @@ if ( shell_minor_version <= 30 ) { var IconThemePreferences = class { constructor() { + const settings = extensionUtils.getSettings(); + const label = _('Icon theme'); const description = _('You can set different icon themes for day and night.'); const content = new SettingsList(); content.add_row(new SettingsListRow(_('Switch icon variants'), new IconVariantsEnabledControl())); - content.add_row(new SettingsListRow(_('Day variant'), new TimeIconVariantControl('day'))); - content.add_row(new SettingsListRow(_('Night variant'), new TimeIconVariantControl('night'))); + + const day_variant_row = new SettingsListRow(_('Day variant'), new TimeIconVariantControl('day')); + settings.bind( + 'icon-variants-enabled', + day_variant_row, + 'sensitive', + Gio.SettingsBindFlags.DEFAULT + ); + content.add_row(day_variant_row); + + const night_variant_row = new SettingsListRow(_('Night variant'), new TimeIconVariantControl('night')); + settings.bind( + 'icon-variants-enabled', + night_variant_row, + 'sensitive', + Gio.SettingsBindFlags.DEFAULT + ); + content.add_row(night_variant_row); return new SettingsPage(label, description, content); } @@ -83,12 +101,6 @@ class TimeIconVariantControl { 'active-id', Gio.SettingsBindFlags.DEFAULT ); - settings.bind( - 'icon-variants-enabled', - combo, - 'sensitive', - Gio.SettingsBindFlags.DEFAULT - ); return combo; } diff --git a/src/preferences/Schedule.js b/src/preferences/Schedule.js index a867f7e..52845a4 100644 --- a/src/preferences/Schedule.js +++ b/src/preferences/Schedule.js @@ -36,21 +36,155 @@ if ( shell_minor_version <= 30 ) { var SchedulePreferences = class { constructor() { + const settings = extensionUtils.getSettings(); + const label = _('Schedule'); const description = _('The extension will try to use Night Light or Location Services to automatically set your current sunrise and sunset times if they are enabled.\n\nIf you prefer, you can manually choose a time source.'); const content = new SettingsList(); content.add_row(new SettingsListRow(_('Manual time source'), new ManualTimeSourceControl())); - content.add_row(new SettingsListRow(_('Time source'), new TimeSourceControl())); - content.add_row(new SettingsListRow(_('Shortcut'), new KeyBindingControl())); - content.add_row(new SettingsListRow(_('Sunrise'), new SuntimeControl('sunrise'))); - content.add_row(new SettingsListRow(_('Sunset'), new SuntimeControl('sunset'))); + + const time_source_row = new SettingsListRow(_('Time source'), new TimeSourceControl()); + settings.bind( + 'manual-time-source', + time_source_row, + 'sensitive', + Gio.SettingsBindFlags.DEFAULT + ); + content.add_row(time_source_row); + + const ondemand_shortcut_row = new SettingsListRow(_('On-demand shortcut'), new KeyBindingControl()); + const update_ondemand_shortcut_row_sensitivity = () => ondemand_shortcut_row.set_sensitive(!!(settings.get_boolean('manual-time-source') && settings.get_string('time-source') === 'ondemand')); + settings.connect('changed::manual-time-source', () => update_ondemand_shortcut_row_sensitivity()); + settings.connect('changed::time-source', () => update_ondemand_shortcut_row_sensitivity()); + update_ondemand_shortcut_row_sensitivity(); + content.add_row(ondemand_shortcut_row); + + const sunrise_row = new SettingsListRow(_('Sunrise'), new SuntimeControl('sunrise')); + const update_sunrise_row_sensitivity = () => sunrise_row.set_sensitive(!!(settings.get_boolean('manual-time-source') && settings.get_string('time-source') === 'schedule')); + settings.connect('changed::manual-time-source', () => update_sunrise_row_sensitivity()); + settings.connect('changed::time-source', () => update_sunrise_row_sensitivity()); + update_sunrise_row_sensitivity(); + content.add_row(sunrise_row); + + const sunset_row = new SettingsListRow(_('Sunset'), new SuntimeControl('sunset')); + const update_sunset_row_sensitivity = () => sunset_row.set_sensitive(!!(settings.get_boolean('manual-time-source') && settings.get_string('time-source') === 'schedule')); + settings.connect('changed::manual-time-source', () => update_sunset_row_sensitivity()); + settings.connect('changed::time-source', () => update_sunset_row_sensitivity()); + update_sunset_row_sensitivity(); + content.add_row(sunset_row); return new SettingsPage(label, description, content); } } +class ManualTimeSourceControl { + + constructor() { + const settings = extensionUtils.getSettings(); + const toggle = new Gtk.Switch({ + active: false + }); + settings.bind( + 'manual-time-source', + toggle, + 'active', + Gio.SettingsBindFlags.DEFAULT + ); + return toggle; + } + +} + + +class TimeSourceControl { + + constructor() { + const settings = extensionUtils.getSettings(); + const colorSettings = new Gio.Settings({ schema: 'org.gnome.settings-daemon.plugins.color' }); + const locationSettings = new Gio.Settings({ schema: 'org.gnome.system.location' }); + + const box = new Gtk.Box({ + spacing: 8, + orientation: Gtk.Orientation.HORIZONTAL, + can_focus: false + }); + + const nightlight_radio = new Gtk.RadioButton({ + label: _('Night Light'), + active: (settings.get_string('time-source') === 'nightlight') + }); + nightlight_radio.connect('toggled', () => { + if ( nightlight_radio.get_active() ) { + settings.set_string('time-source', 'nightlight') + } + }); + colorSettings.bind( + 'night-light-enabled', + nightlight_radio, + 'sensitive', + Gio.SettingsBindFlags.DEFAULT + ); + box.pack_start(nightlight_radio, false, false, 0); + + const location_radio = new Gtk.RadioButton({ + label: _('Location Services'), + group: nightlight_radio, + active: (settings.get_string('time-source') === 'location') + }); + location_radio.connect('toggled', () => { + if ( location_radio.get_active() ) { + settings.set_string('time-source', 'location') + } + }); + locationSettings.bind( + 'enabled', + location_radio, + 'sensitive', + Gio.SettingsBindFlags.DEFAULT + ); + box.pack_start(location_radio, false, false, 0); + + const schedule_radio = new Gtk.RadioButton({ + label: _('Manual schedule'), + group: nightlight_radio, + active: (settings.get_string('time-source') === 'schedule') + }); + schedule_radio.connect('toggled', () => { + if ( schedule_radio.get_active() ) { + settings.set_string('time-source', 'schedule') + } + }); + settings.bind( + 'manual-time-source', + schedule_radio, + 'sensitive', + Gio.SettingsBindFlags.DEFAULT + ); + box.pack_start(schedule_radio, false, false, 0); + + const ondemand_radio = new Gtk.RadioButton({ + label: _('On-demand'), + group: nightlight_radio, + active: (settings.get_string('time-source') === 'ondemand') + }); + ondemand_radio.connect('toggled', () => { + settings.set_string('time-source', 'ondemand') + }); + settings.bind( + 'manual-time-source', + ondemand_radio, + 'sensitive', + Gio.SettingsBindFlags.DEFAULT + ); + box.pack_start(ondemand_radio, false, false, 0); + + return box; + } + +} + class KeyBindingControl { @@ -96,120 +230,11 @@ class KeyBindingControl { tree_view.append_column(column); update_shortcut_row(settings.get_strv(KEYBINDING_KEY)[0]); - const update_treeview_sensitivity = (tree_view) => { - tree_view.set_sensitive(!!(settings.get_string('time-source') === 'ondemand')); - } - settings.connect('changed::time-source', () => update_treeview_sensitivity(tree_view)); - update_treeview_sensitivity(tree_view) - return tree_view; } } -class ManualTimeSourceControl { - - constructor() { - const settings = extensionUtils.getSettings(); - const toggle = new Gtk.Switch({ - active: false - }); - settings.bind( - 'manual-time-source', - toggle, - 'active', - Gio.SettingsBindFlags.DEFAULT - ); - return toggle; - } - -} - - -class TimeSourceControl { - - constructor() { - const settings = extensionUtils.getSettings(); - const colorSettings = new Gio.Settings({ schema: 'org.gnome.settings-daemon.plugins.color' }); - const locationSettings = new Gio.Settings({ schema: 'org.gnome.system.location' }); - - const box = new Gtk.Box({ - spacing: 8, - orientation: Gtk.Orientation.HORIZONTAL, - can_focus: false - }); - - const nightlight_radio = new Gtk.RadioButton({ - label: _('Night Light'), - active: (settings.get_string('time-source') === 'nightlight') - }); - const update_nightlight_radio_sensitivity = () => nightlight_radio.set_sensitive(!!(settings.get_boolean('manual-time-source') && colorSettings.get_boolean('night-light-enabled'))); - settings.connect('changed::manual-time-source', update_nightlight_radio_sensitivity); - colorSettings.connect('changed::night-light-enabled', update_nightlight_radio_sensitivity); - update_nightlight_radio_sensitivity(); - nightlight_radio.connect('toggled', () => { - if ( nightlight_radio.get_active() ) { - settings.set_string('time-source', 'nightlight') - } - }); - box.pack_start(nightlight_radio, false, false, 0); - - const location_radio = new Gtk.RadioButton({ - label: _('Location Services'), - group: nightlight_radio, - active: (settings.get_string('time-source') === 'location') - }); - const update_location_radio_sensitivity = () => location_radio.set_sensitive(!!(settings.get_boolean('manual-time-source') && locationSettings.get_boolean('enabled'))); - settings.connect('changed::manual-time-source', update_location_radio_sensitivity); - locationSettings.connect('changed::enabled', update_location_radio_sensitivity); - update_location_radio_sensitivity(); - location_radio.connect('toggled', () => { - if ( location_radio.get_active() ) { - settings.set_string('time-source', 'location') - } - }); - box.pack_start(location_radio, false, false, 0); - - const schedule_radio = new Gtk.RadioButton({ - label: _('Manual schedule'), - group: nightlight_radio, - active: (settings.get_string('time-source') === 'schedule') - }); - settings.bind( - 'manual-time-source', - schedule_radio, - 'sensitive', - Gio.SettingsBindFlags.DEFAULT - ); - schedule_radio.connect('toggled', () => { - if ( schedule_radio.get_active() ) { - settings.set_string('time-source', 'schedule') - } - }); - box.pack_start(schedule_radio, false, false, 0); - - const ondemand_radio = new Gtk.RadioButton({ - label: _('On-demand'), - group: nightlight_radio, - active: (settings.get_string('time-source') === 'ondemand') - }); - settings.bind( - 'manual-time-source', - ondemand_radio, - 'sensitive', - Gio.SettingsBindFlags.DEFAULT - ); - ondemand_radio.connect('toggled', () => { - settings.set_string('time-source', 'ondemand') - }); - box.pack_start(ondemand_radio, false, false, 0); - - - return box; - } - -} - class SuntimeControl { @@ -221,8 +246,6 @@ class SuntimeControl { can_focus: false }); - const update_spin_sensitivity = (spin) => spin.set_sensitive(!!(settings.get_boolean('manual-time-source') && settings.get_string('time-source') === 'schedule')); - const time = settings.get_double(`schedule-${suntime}`); const hours = Math.trunc(time); const minutes = Math.round((time - hours) * 60); @@ -253,9 +276,6 @@ class SuntimeControl { const new_time = hours_spin.value + minutes; settings.set_double(`schedule-${suntime}`, new_time); }); - settings.connect('changed::manual-time-source', () => update_spin_sensitivity(hours_spin)); - settings.connect('changed::time-source', () => update_spin_sensitivity(hours_spin)); - update_spin_sensitivity(hours_spin); const separator = new Gtk.Label({ label: ':' }); @@ -284,9 +304,6 @@ class SuntimeControl { const new_time = hour + minutes; settings.set_double(`schedule-${suntime}`, new_time); }); - settings.connect('changed::manual-time-source', () => update_spin_sensitivity(minutes_spin)); - settings.connect('changed::time-source', () => update_spin_sensitivity(minutes_spin)); - update_spin_sensitivity(minutes_spin); box.pack_start(hours_spin, false, false, 0); box.pack_start(separator, false, false, 0);