[dconf-editor] Use GAction for boolean switch.
- From: Arnaud Bonatti <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dconf-editor] Use GAction for boolean switch.
- Date: Thu, 1 Feb 2018 16:46:13 +0000 (UTC)
commit ac3c6327c8a587eea2f6233fbb3b6b7ed30423f8
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Thu Feb 1 16:10:49 2018 +0100
Use GAction for boolean switch.
editor/browser-view.vala | 40 ++++++++++++++++++-
editor/dconf-model.vala | 79 +++++++++++++++++++++++++------------
editor/key-list-box-row.vala | 45 +++++++--------------
editor/modifications-handler.vala | 10 +++++
4 files changed, 117 insertions(+), 57 deletions(-)
---
diff --git a/editor/browser-view.vala b/editor/browser-view.vala
index be8ab0a..d0fe781 100644
--- a/editor/browser-view.vala
+++ b/editor/browser-view.vala
@@ -88,10 +88,17 @@ class BrowserView : Grid
private const GLib.ActionEntry [] action_entries =
{
+ { "empty", empty , "*" },
+
{ "refresh-folder", refresh_folder },
- { "set-to-default", set_to_default, "(ss)" }
+ { "set-to-default", set_to_default, "(ss)" },
+
+ { "toggle-dconf-key-switch", toggle_dconf_key_switch, "(sb)" },
+ { "toggle-gsettings-key-switch", toggle_gsettings_key_switch, "(ssbb)" }
};
+ private void empty (/* SimpleAction action, Variant? variant */) {}
+
private void refresh_folder (/* SimpleAction action, Variant? path_variant */)
requires (key_model != null)
{
@@ -109,6 +116,37 @@ class BrowserView : Grid
invalidate_popovers ();
}
+ private void toggle_dconf_key_switch (SimpleAction action, Variant? value_variant)
+ requires (value_variant != null)
+ {
+ if (modifications_handler.get_current_delay_mode ())
+ assert_not_reached ();
+
+ string full_name;
+ bool key_value_request;
+ ((!) value_variant).@get ("(sb)", out full_name, out key_value_request);
+
+ modifications_handler.set_dconf_key_value (full_name, key_value_request);
+ }
+
+ private void toggle_gsettings_key_switch (SimpleAction action, Variant? value_variant)
+ requires (value_variant != null)
+ {
+ if (modifications_handler.get_current_delay_mode ())
+ assert_not_reached ();
+
+ string full_name;
+ string context;
+ bool key_value_request;
+ bool key_default_value;
+ ((!) value_variant).@get ("(ssbb)", out full_name, out context, out key_value_request, out
key_default_value);
+
+ if (key_value_request == key_default_value)
+ modifications_handler.set_to_default (full_name, context);
+ else
+ modifications_handler.set_gsettings_key_value (full_name, context, new Variant.boolean
(key_value_request));
+ }
+
/*\
* * Views
\*/
diff --git a/editor/dconf-model.vala b/editor/dconf-model.vala
index eee6ecc..10c8c93 100644
--- a/editor/dconf-model.vala
+++ b/editor/dconf-model.vala
@@ -425,27 +425,66 @@ public class SettingsModel : Object
return client.read (full_name);
}
- public void set_key_value (Key key, Variant value)
+ public void set_key_value (Key key, Variant key_value)
{
if (key is GSettingsKey)
- ((GSettingsKey) key).settings.set_value (key.name, value);
+ ((GSettingsKey) key).settings.set_value (key.name, key_value);
else
{
- try
- {
- client.write_sync (key.full_name, value, out last_change_tag);
- }
- catch (Error error)
- {
- warning (error.message);
- }
+ set_dconf_value (key.full_name, key_value);
key.value_changed ();
}
}
+ public void set_gsettings_key_value (string full_name, string schema_id, Variant key_value)
+ {
+ Key? key = get_key (full_name, schema_id);
+ if (key == null)
+ {
+ warning ("Non-existing key gsettings set-value request.");
+ set_dconf_value (full_name, key_value);
+ }
+ else if ((!) key is GSettingsKey)
+ ((GSettingsKey) (!) key).settings.set_value (((!) key).name, key_value);
+ else if ((!) key is DConfKey) // should not happen for now
+ {
+ warning ("Key without schema gsettings set-value request.");
+ set_dconf_value (full_name, key_value);
+ ((!) key).value_changed ();
+ }
+ else
+ assert_not_reached ();
+ }
+
+ public void set_dconf_key_value (string full_name, Variant key_value)
+ {
+ Key? key = get_key (full_name, "");
+ set_dconf_value (full_name, key_value);
+
+ if (key == null)
+ warning ("Non-existing key dconf set-value request.");
+ else
+ {
+ if (!(((!) key) is DConfKey))
+ warning ("Non-DConfKey key dconf set-value request.");
+ ((Key) (!) key).value_changed ();
+ }
+ }
+ private void set_dconf_value (string full_name, Variant? key_value)
+ {
+ try
+ {
+ client.write_sync (full_name, key_value, out last_change_tag);
+ }
+ catch (Error error)
+ {
+ warning (error.message);
+ }
+ }
+
public void set_key_to_default (string full_name, string schema_id)
{
- SettingObject? key = get_key (full_name, schema_id);
+ Key? key = get_key (full_name, schema_id);
if (key == null && !(key is GSettingsKey))
return; // TODO better
@@ -458,27 +497,17 @@ public class SettingsModel : Object
public void erase_key (string full_name)
{
- SettingObject? key = get_key (full_name);
-
- try
- {
- client.write_sync (full_name, null);
- }
- catch (Error error)
- {
- warning (error.message);
- }
+ Key? key = get_key (full_name, "");
+ set_dconf_value (full_name, null);
if (key == null)
warning ("Non-existing key erase request.");
- else if (((!) key) is Key)
+ else
{
if (!(((!) key) is DConfKey))
warning ("Non-DConfKey key erase request.");
((Key) (!) key).value_changed ();
}
- else
- assert_not_reached ();
}
public bool is_key_default (GSettingsKey key)
@@ -497,7 +526,7 @@ public class SettingsModel : Object
HashTable<string, GLib.Settings> delayed_settings_hashtable = new HashTable<string, GLib.Settings>
(str_hash, str_equal);
DConf.Changeset dconf_changeset = new DConf.Changeset ();
changes.foreach ((key_name, planned_value) => {
- SettingObject? key = get_key (key_name);
+ Key? key = get_key (key_name);
if (key == null)
{
// TODO change value anyway?
diff --git a/editor/key-list-box-row.vala b/editor/key-list-box-row.vala
index 94cff5d..8b8d360 100644
--- a/editor/key-list-box-row.vala
+++ b/editor/key-list-box-row.vala
@@ -259,7 +259,7 @@ private abstract class KeyListBoxRow : ClickableListBoxRow
{
if (boolean_switch == null)
return;
- ((!) boolean_switch).set_active (!((!) boolean_switch).get_active ());
+ ((!) boolean_switch).activate ();
}
public void set_delayed_icon ()
@@ -296,13 +296,8 @@ private class KeyListBoxRowEditableNoSchema : KeyListBoxRow
construct
{
- SettingsModel model = modifications_handler.model;
get_style_context ().add_class ("dconf-key");
- if (boolean_switch != null)
- ((!) boolean_switch).notify ["active"].connect (
- () => model.set_key_value (key, new Variant.boolean (((!) boolean_switch).get_active
())));
-
key_info_label.get_style_context ().add_class ("italic-label");
key_info_label.set_label (_("No Schema Found"));
}
@@ -331,7 +326,12 @@ private class KeyListBoxRowEditableNoSchema : KeyListBoxRow
{
key_value_label.hide ();
((!) boolean_switch).show ();
- ((!) boolean_switch).set_active (key_value.get_boolean ());
+
+ bool key_value_boolean = key_value.get_boolean ();
+ Variant switch_variant = new Variant ("(sb)", key.full_name, !key_value_boolean);
+ ((!) boolean_switch).set_action_name ("bro.empty");
+ ((!) boolean_switch).set_active (key_value_boolean);
+ ((!) boolean_switch).set_detailed_action_name ("bro.toggle-dconf-key-switch(" +
switch_variant.print (false) + ")");
}
key_value_label.set_label (Key.cool_text_value_from_variant (key_value, key.type_string));
}
@@ -413,22 +413,11 @@ private class KeyListBoxRowEditable : KeyListBoxRow
{
public GSettingsKey key { get; construct; }
private override Key abstract_key { get { return (Key) key; }}
- private ulong boolean_switch_toggled_handler = 0;
construct
{
- SettingsModel model = modifications_handler.model;
get_style_context ().add_class ("gsettings-key");
- if (boolean_switch != null)
- boolean_switch_toggled_handler = ((!) boolean_switch).notify ["active"].connect (() => {
- bool boolean = ((!) boolean_switch).get_active ();
- if (boolean == key.default_value.get_boolean ())
- model.set_key_to_default (key.full_name, key.schema_id);
- else
- model.set_key_value (key, new Variant.boolean (boolean));
- });
-
if (key.summary != "")
key_info_label.set_label (key.summary);
else
@@ -463,20 +452,14 @@ private class KeyListBoxRowEditable : KeyListBoxRow
protected override void update ()
{
SettingsModel model = modifications_handler.model;
+ Variant key_value = model.get_key_value (key);
if (boolean_switch != null)
{
- bool boolean = model.get_key_value (key).get_boolean ();
- if (((!) boolean_switch).get_active () != boolean)
- {
- if (boolean_switch_toggled_handler > 0)
- {
- SignalHandler.block ((!) boolean_switch, boolean_switch_toggled_handler);
- ((!) boolean_switch).set_active (boolean);
- SignalHandler.unblock ((!) boolean_switch, boolean_switch_toggled_handler);
- }
- else // first init
- ((!) boolean_switch).set_active (boolean);
- }
+ bool key_value_boolean = key_value.get_boolean ();
+ Variant switch_variant = new Variant ("(ssbb)", key.full_name, key.schema_id,
!key_value_boolean, key.default_value.get_boolean ());
+ ((!) boolean_switch).set_action_name ("bro.empty");
+ ((!) boolean_switch).set_active (key_value_boolean);
+ ((!) boolean_switch).set_detailed_action_name ("bro.toggle-gsettings-key-switch(" +
switch_variant.print (false) + ")");
}
StyleContext css_context = get_style_context ();
@@ -484,7 +467,7 @@ private class KeyListBoxRowEditable : KeyListBoxRow
css_context.remove_class ("edited");
else
css_context.add_class ("edited");
- key_value_label.set_label (Key.cool_text_value_from_variant (model.get_key_value (key),
key.type_string));
+ key_value_label.set_label (Key.cool_text_value_from_variant (key_value, key.type_string));
}
protected override string get_text ()
diff --git a/editor/modifications-handler.vala b/editor/modifications-handler.vala
index 26495a7..3c2fb0b 100644
--- a/editor/modifications-handler.vala
+++ b/editor/modifications-handler.vala
@@ -183,6 +183,16 @@ class ModificationsHandler : Object
model.erase_key (((DConfKey) key).full_name);
}
+ public void set_dconf_key_value (string full_name, Variant key_value)
+ {
+ model.set_dconf_key_value (full_name, key_value);
+ }
+
+ public void set_gsettings_key_value (string full_name, string schema_id, Variant key_value)
+ {
+ model.set_gsettings_key_value (full_name, schema_id, key_value);
+ }
+
public void erase_dconf_key (string full_name)
{
if (get_current_delay_mode ())
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]