[dconf-editor] Isolate access to key value within SettingsModel
- From: Arnaud Bonatti <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dconf-editor] Isolate access to key value within SettingsModel
- Date: Sun, 17 Dec 2017 01:46:10 +0000 (UTC)
commit 745abd946317dd264b913218e1cd28bd1aae45e9
Author: Davi da Silva Böger <dsboger gmail com>
Date: Sun Dec 10 17:22:02 2017 -0200
Isolate access to key value within SettingsModel
editor/browser-view.vala | 4 +-
editor/dconf-model.vala | 42 +++++++++++++++++++++++++++++++-
editor/dconf-window.vala | 6 ++--
editor/key-list-box-row.vala | 48 +++++++++++++++++-------------------
editor/modifications-handler.vala | 10 ++++----
editor/registry-info.vala | 32 ++++++++++++------------
6 files changed, 90 insertions(+), 52 deletions(-)
---
diff --git a/editor/browser-view.vala b/editor/browser-view.vala
index 01641c8..3b75dae 100644
--- a/editor/browser-view.vala
+++ b/editor/browser-view.vala
@@ -365,10 +365,10 @@ class BrowserView : Grid, PathElement
}
if (setting_object is DConfKey)
{
- if (!((DConfKey) setting_object).is_ghost)
+ if (!modifications_handler.model.is_key_ghost ((DConfKey) setting_object))
modifications_handler.add_delayed_setting ((Key) setting_object, null);
}
- else if (!((GSettingsKey) setting_object).is_default)
+ else if (!modifications_handler.model.is_key_default ((GSettingsKey) setting_object))
modifications_handler.add_delayed_setting ((Key) setting_object, null);
}
}
diff --git a/editor/dconf-model.vala b/editor/dconf-model.vala
index 72887dc..40cff19 100644
--- a/editor/dconf-model.vala
+++ b/editor/dconf-model.vala
@@ -992,6 +992,46 @@ public class SettingsModel : Object
* * Key value methods
\*/
+ public string get_key_copy_text (Key key)
+ {
+ return key.get_copy_text ();
+ }
+
+ public Variant get_key_value (Key key)
+ {
+ return key.value;
+ }
+
+ public void set_key_value (Key key, Variant value)
+ {
+ key.value = value;
+ }
+
+ public void set_key_to_default (GSettingsKey key)
+ {
+ key.set_to_default ();
+ }
+
+ public void erase_key (DConfKey key)
+ {
+ key.erase ();
+ }
+
+ public bool is_key_default (GSettingsKey key)
+ {
+ return key.is_default;
+ }
+
+ public bool is_key_ghost (DConfKey key)
+ {
+ return key.is_ghost;
+ }
+
+ public void set_key_is_ghost (DConfKey key, bool is_ghost)
+ {
+ key.is_ghost = is_ghost;
+ }
+
public void apply_key_value_changes (HashTable<Key, Variant?> changes)
{
HashTable<string, GLib.Settings> delayed_settings_hashtable = new HashTable<string, GLib.Settings>
(str_hash, str_equal);
@@ -1024,7 +1064,7 @@ public class SettingsModel : Object
dconf_changeset.set (key.full_name, planned_value);
if (planned_value == null)
- ((DConfKey) key).is_ghost = true;
+ set_key_is_ghost ((DConfKey) key, true);
}
});
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index e8098b5..958b3c5 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -343,7 +343,7 @@ class DConfWindow : ApplicationWindow
if (existing_key == null)
cannot_find_key (object_name, (!) dir);
- else if (((!) existing_key) is DConfKey && ((DConfKey) (!) existing_key).is_ghost)
+ else if (((!) existing_key) is DConfKey && model.is_key_ghost ((DConfKey) existing_key))
key_has_been_removed (object_name, (!) dir);
else
browser_view.show_properties_view ((Key) (!) existing_key, full_name, ((!)
dir).warning_multiple_schemas);
@@ -372,7 +372,7 @@ class DConfWindow : ApplicationWindow
{
SettingObject? object = model.get_object (current_path);
if (object != null && (!) object is Key)
- menu.append (_("Copy descriptor"), "app.copy(\"" + ((Key) (!) object).get_copy_text () +
"\")"); // TODO what happens on multiple schemas defining one key?..
+ menu.append (_("Copy descriptor"), "app.copy(\"" + model.get_key_copy_text ((Key) (!)
object) + "\")"); // TODO what happens on multiple schemas defining one key?..
else // fallback that should never be reached
menu.append (_("Copy current path"), "app.copy(\"" + current_path.escape (null).escape
(null) + "\")");
}
@@ -529,7 +529,7 @@ class DConfWindow : ApplicationWindow
{
SettingObject? setting_object = model.get_object (current_path);
if (setting_object != null && (!) setting_object is Key)
- selected_row_text = ((Key) (!) setting_object).get_copy_text ();
+ selected_row_text = model.get_key_copy_text ((Key) (!) setting_object);
}
ConfigurationEditor application = (ConfigurationEditor) get_application ();
application.copy (selected_row_text == null ? current_path : (!) selected_row_text);
diff --git a/editor/key-list-box-row.vala b/editor/key-list-box-row.vala
index ee6691b..a30d737 100644
--- a/editor/key-list-box-row.vala
+++ b/editor/key-list-box-row.vala
@@ -227,11 +227,6 @@ private abstract class KeyListBoxRow : ClickableListBoxRow
public signal void set_key_value (Variant? new_value);
public signal void change_dismissed ();
- protected static string cool_text_value (Key key) // TODO better
- {
- return Key.cool_text_value_from_variant (key.value, key.type_string);
- }
-
construct
{
if (abstract_key.type_string == "b") // TODO not with “always delay” behaviour, nor in “delay
mode”
@@ -283,7 +278,7 @@ private abstract class KeyListBoxRow : ClickableListBoxRow
else
{
context.remove_class ("delayed");
- if (key is DConfKey && ((DConfKey) key).is_ghost)
+ if (key is DConfKey && modifications_handler.model.is_key_ghost ((DConfKey) key))
context.add_class ("erase");
else
context.remove_class ("erase");
@@ -301,7 +296,8 @@ private class KeyListBoxRowEditableNoSchema : KeyListBoxRow
get_style_context ().add_class ("dconf-key");
if (boolean_switch != null)
- ((!) boolean_switch).notify ["active"].connect (() => key.value = new Variant.boolean (((!)
boolean_switch).get_active ()));
+ ((!) boolean_switch).notify ["active"].connect (
+ () => modifications_handler.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"));
@@ -314,7 +310,7 @@ private class KeyListBoxRowEditableNoSchema : KeyListBoxRow
protected override void update ()
{
- if (key.is_ghost)
+ if (modifications_handler.model.is_key_ghost (key))
{
if (boolean_switch != null)
{
@@ -325,24 +321,25 @@ private class KeyListBoxRowEditableNoSchema : KeyListBoxRow
}
else
{
+ Variant key_value = modifications_handler.model.get_key_value (key);
if (boolean_switch != null)
{
key_value_label.hide ();
((!) boolean_switch).show ();
- ((!) boolean_switch).set_active (key.value.get_boolean ());
+ ((!) boolean_switch).set_active (key_value.get_boolean ());
}
- key_value_label.set_label (cool_text_value (key));
+ key_value_label.set_label (Key.cool_text_value_from_variant (key_value, key.type_string));
}
}
protected override string get_text ()
{
- return key.get_copy_text ();
+ return modifications_handler.model.get_key_copy_text (key);
}
protected override bool generate_popover (ContextPopover popover)
{
- if (key.is_ghost)
+ if (modifications_handler.model.is_key_ghost (key))
{
popover.new_copy_action (get_text ());
return true;
@@ -422,9 +419,9 @@ private class KeyListBoxRowEditable : KeyListBoxRow
boolean_switch_toggled_handler = ((!) boolean_switch).notify ["active"].connect (() => {
bool boolean = ((!) boolean_switch).get_active ();
if (boolean == key.default_value.get_boolean ())
- key.set_to_default ();
+ modifications_handler.model.set_key_to_default (key);
else
- key.value = new Variant.boolean (boolean);
+ modifications_handler.model.set_key_value (key, new Variant.boolean (boolean));
});
if (key.summary != "")
@@ -445,7 +442,7 @@ private class KeyListBoxRowEditable : KeyListBoxRow
{
if (boolean_switch != null)
{
- bool boolean = key.value.get_boolean ();
+ bool boolean = modifications_handler.model.get_key_value (key).get_boolean ();
if (((!) boolean_switch).get_active () != boolean)
{
if (boolean_switch_toggled_handler > 0)
@@ -460,17 +457,16 @@ private class KeyListBoxRowEditable : KeyListBoxRow
}
StyleContext css_context = get_style_context ();
- if (key.is_default)
+ if (modifications_handler.model.is_key_default (key))
css_context.remove_class ("edited");
else
css_context.add_class ("edited");
-
- key_value_label.set_label (cool_text_value (key));
+ key_value_label.set_label (Key.cool_text_value_from_variant
(modifications_handler.model.get_key_value (key), key.type_string));
}
protected override string get_text ()
{
- return key.get_copy_text ();
+ return modifications_handler.model.get_key_copy_text (key);
}
protected override bool generate_popover (ContextPopover popover)
@@ -509,7 +505,8 @@ private class KeyListBoxRowEditable : KeyListBoxRow
});
popover.value_changed.connect ((gvariant) => {
hide_right_click_popover ();
- action.change_state (new Variant.maybe (null, new Variant.maybe (new VariantType
(key.value.get_type_string ()), gvariant)));
+ Variant key_value = modifications_handler.model.get_key_value (key);
+ action.change_state (new Variant.maybe (null, new Variant.maybe (new VariantType
(key_value.get_type_string ()), gvariant)));
set_key_value (gvariant);
});
}
@@ -517,7 +514,7 @@ private class KeyListBoxRowEditable : KeyListBoxRow
{
popover.new_section ();
- if (!key.is_default)
+ if (!modifications_handler.model.is_key_default (key))
popover.new_action ("default2", () => {
destroy_popover ();
set_key_value (null);
@@ -541,7 +538,7 @@ private class KeyListBoxRowEditable : KeyListBoxRow
set_key_value (null);
});
}
- else if (!key.is_default)
+ else if (!modifications_handler.model.is_key_default (key))
{
popover.new_section ();
popover.new_action ("default1", () => {
@@ -713,7 +710,8 @@ private class ContextPopover : Popover
const string ACTION_NAME = "choice";
string group_dot_action = "enum.choice";
- VariantType original_type = key.value.get_type ();
+ Variant key_value = modifications_handler.model.get_key_value (key);
+ VariantType original_type = key_value.get_type ();
VariantType nullable_type = new VariantType.maybe (original_type);
VariantType nullable_nullable_type = new VariantType.maybe (nullable_type);
string type_string = original_type.dup_string ();
@@ -727,10 +725,10 @@ private class ContextPopover : Popover
value_variant = modifications_handler.get_key_custom_value (key);
else if (planned_change)
value_variant = planned_value;
- else if (key is GSettingsKey && ((GSettingsKey) key).is_default)
+ else if (key is GSettingsKey && modifications_handler.model.is_key_default ((GSettingsKey) key))
value_variant = null;
else
- value_variant = key.value;
+ value_variant = key_value;
Variant variant = new Variant.maybe (original_type, value_variant);
Variant nullable_variant;
if (delayed_apply_menu && !planned_change)
diff --git a/editor/modifications-handler.vala b/editor/modifications-handler.vala
index 05ec32c..af7b61d 100644
--- a/editor/modifications-handler.vala
+++ b/editor/modifications-handler.vala
@@ -156,14 +156,14 @@ class ModificationsHandler : Object
{
bool planned_change = key_has_planned_change (key);
Variant? planned_value = get_key_planned_value (key);
- return planned_change && (planned_value != null) ? (!) planned_value : key.value;
+ return planned_change && (planned_value != null) ? (!) planned_value : model.get_key_value (key);
}
public bool key_value_is_default (GSettingsKey key) // doesn't make sense for DConfKey?
{
bool planned_change = key_has_planned_change (key);
Variant? planned_value = get_key_planned_value (key);
- return planned_change ? planned_value == null : key.is_default;
+ return planned_change ? planned_value == null : model.is_key_default (key);
}
public void set_key_value (Key key, Variant? new_value)
@@ -171,16 +171,16 @@ class ModificationsHandler : Object
if (get_current_delay_mode ())
add_delayed_setting (key, new_value);
else if (new_value != null)
- key.value = (!) new_value;
+ model.set_key_value (key, (!) new_value);
else if (key is GSettingsKey)
- ((GSettingsKey) key).set_to_default ();
+ model.set_key_to_default ((GSettingsKey) key);
else if (behaviour != Behaviour.UNSAFE)
{
enter_delay_mode ();
add_delayed_setting (key, null);
}
else
- ((DConfKey) key).erase ();
+ model.erase_key ((DConfKey) key);
}
public bool key_has_planned_change (Key key)
diff --git a/editor/registry-info.vala b/editor/registry-info.vala
index 4bb6841..f859850 100644
--- a/editor/registry-info.vala
+++ b/editor/registry-info.vala
@@ -60,7 +60,7 @@ class RegistryInfo : Grid, BrowsableView
public void populate_properties_list_box (Key key, bool warning_multiple_schemas)
{
- if (key is DConfKey && ((DConfKey) key).is_ghost) // TODO place in "requires"
+ if (key is DConfKey && modifications_handler.model.is_key_ghost ((DConfKey) key)) // TODO place in
"requires"
assert_not_reached ();
clean (); // for when switching between two keys, for example with a search (maybe also bookmarks)
@@ -96,12 +96,12 @@ class RegistryInfo : Grid, BrowsableView
if (!dict.lookup ("type-code", "s", out tmp_string)) assert_not_reached ();
- Label label = new Label (get_current_value_text (has_schema && ((GSettingsKey) key).is_default,
key));
+ Label label = new Label (get_current_value_text (has_schema &&
modifications_handler.model.is_key_default ((GSettingsKey) key), key));
ulong key_value_changed_handler = key.value_changed.connect (() => {
- if (!has_schema && ((DConfKey) key).is_ghost)
+ if (!has_schema && modifications_handler.model.is_key_ghost ((DConfKey) key))
((BrowserView) DConfWindow._get_parent (DConfWindow._get_parent (this))).request_path
(parent_path);
else
- label.set_text (get_current_value_text (has_schema && ((GSettingsKey) key).is_default,
key));
+ label.set_text (get_current_value_text (has_schema &&
modifications_handler.model.is_key_default ((GSettingsKey) key), key));
});
label.halign = Align.START;
label.valign = Align.START;
@@ -133,7 +133,7 @@ class RegistryInfo : Grid, BrowsableView
modifications_handler.dismiss_change (key);
}
else
- key.value = key_editor_child.get_variant ();
+ modifications_handler.model.set_key_value (key, key_editor_child.get_variant ());
});
if (has_schema)
@@ -165,20 +165,20 @@ class RegistryInfo : Grid, BrowsableView
{
if (custom_value_switch.get_active ())
{
- ((GSettingsKey) key).set_to_default ();
+ modifications_handler.model.set_key_to_default ((GSettingsKey) key);
SignalHandler.block (key_editor_child, value_has_changed_handler);
- key_editor_child.reload (key.value);
+ key_editor_child.reload (modifications_handler.model.get_key_value (key));
//if (tmp_string == "<flags>") let's try to live without
this...
// key.planned_value = key.value;
SignalHandler.unblock (key_editor_child, value_has_changed_handler);
}
else
- key.value = key.value; // TODO that hurts...
+ modifications_handler.model.set_key_value (key,
modifications_handler.model.get_key_value (key)); // TODO that hurts...
}
});
revealer_reload_1_handler = modifications_handler.reload.connect (() => {
SignalHandler.block (custom_value_switch, switch_active_handler);
- custom_value_switch.set_active (gkey.is_default);
+ custom_value_switch.set_active (modifications_handler.model.is_key_default (gkey));
SignalHandler.unblock (custom_value_switch, switch_active_handler);
});
custom_value_switch.destroy.connect (() => custom_value_switch.disconnect
(switch_active_handler));
@@ -193,10 +193,10 @@ class RegistryInfo : Grid, BrowsableView
ulong child_activated_handler = key_editor_child.child_activated.connect (() =>
modifications_handler.apply_delayed_settings ()); // TODO "only" used for string-based and spin widgets
revealer_reload_2_handler = modifications_handler.reload.connect (() => {
- if (key is DConfKey && ((DConfKey) key).is_ghost)
+ if (key is DConfKey && modifications_handler.model.is_key_ghost ((DConfKey) key))
return;
SignalHandler.block (key_editor_child, value_has_changed_handler);
- key_editor_child.reload (key.value);
+ key_editor_child.reload (modifications_handler.model.get_key_value (key));
//if (tmp_string == "<flags>") let's try to live without this...
// key.planned_value = key.value;
SignalHandler.unblock (key_editor_child, value_has_changed_handler);
@@ -219,7 +219,7 @@ class RegistryInfo : Grid, BrowsableView
switch (((GSettingsKey) key).range_content.n_children ())
{
case 0: assert_not_reached ();
- case 1: return (KeyEditorChild) new KeyEditorChildSingle (key.value,
key.value.get_string ());
+ case 1: return (KeyEditorChild) new KeyEditorChildSingle
(modifications_handler.model.get_key_value (key), modifications_handler.model.get_key_value (key).get_string
());
default: return (KeyEditorChild) new KeyEditorChildEnum (key, initial_value,
modifications_handler);
}
case "<flags>":
@@ -234,7 +234,7 @@ class RegistryInfo : Grid, BrowsableView
{
Variant range = ((GSettingsKey) key).range_content;
if (Key.get_variant_as_int64 (range.get_child_value (0)) == Key.get_variant_as_int64
(range.get_child_value (1)))
- return (KeyEditorChild) new KeyEditorChildSingle (key.value, key.value.print
(false));
+ return (KeyEditorChild) new KeyEditorChildSingle
(modifications_handler.model.get_key_value (key), modifications_handler.model.get_key_value (key).print
(false));
}
return (KeyEditorChild) new KeyEditorChildNumberInt (key, initial_value);
case "y":
@@ -245,7 +245,7 @@ class RegistryInfo : Grid, BrowsableView
{
Variant range = ((GSettingsKey) key).range_content;
if (Key.get_variant_as_uint64 (range.get_child_value (0)) == Key.get_variant_as_uint64
(range.get_child_value (1)))
- return (KeyEditorChild) new KeyEditorChildSingle (key.value, key.value.print
(false));
+ return (KeyEditorChild) new KeyEditorChildSingle
(modifications_handler.model.get_key_value (key), modifications_handler.model.get_key_value (key).print
(false));
}
return (KeyEditorChild) new KeyEditorChildNumberInt (key, initial_value);
case "d":
@@ -260,12 +260,12 @@ class RegistryInfo : Grid, BrowsableView
}
}
- private static string get_current_value_text (bool is_default, Key key)
+ private string get_current_value_text (bool is_default, Key key)
{
if (is_default)
return _("Default value");
else
- return Key.cool_text_value_from_variant (key.value, key.type_string);
+ return Key.cool_text_value_from_variant (modifications_handler.model.get_key_value (key),
key.type_string);
}
public string? get_copy_text ()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]