[dconf-editor] Make is_key_ghost take a path.



commit 5745bc4ec65aab331bdcd1bbd3d83685b6348e5e
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Thu Jun 28 10:49:20 2018 +0200

    Make is_key_ghost take a path.

 editor/dconf-model.vala            | 17 +++++++++++++++--
 editor/key-list-box-row.vala       |  6 +++---
 editor/modifications-revealer.vala |  4 ++--
 editor/registry-info.vala          |  6 +++---
 4 files changed, 23 insertions(+), 10 deletions(-)
---
diff --git a/editor/dconf-model.vala b/editor/dconf-model.vala
index a536731..3e18970 100644
--- a/editor/dconf-model.vala
+++ b/editor/dconf-model.vala
@@ -514,9 +514,22 @@ public class SettingsModel : Object
         return settings.get_user_value (key.name) == null;
     }
 
-    public bool is_key_ghost (DConfKey key)
+    private bool key_has_no_schema (string full_name)
     {
-        return get_dconf_key_value_or_null (key.full_name, client) == null;
+        if (!is_key_path (full_name))
+            assert_not_reached ();
+
+        Key? key = get_key (full_name, "");
+        return key == null || (!) key is DConfKey;
+    }
+
+    public bool is_key_ghost (string full_name)
+    {
+        // we're "sure" the key is a DConfKey, but that might have changed since
+        if (!key_has_no_schema (full_name))
+            warning (@"Function is_key_ghost called for path:\n  $full_name\nbut key found is not a 
DConfKey.");
+
+        return get_dconf_key_value_or_null (full_name, client) == null;
     }
 
     public void apply_key_value_changes (HashTable<string, Variant?> changes)
diff --git a/editor/key-list-box-row.vala b/editor/key-list-box-row.vala
index de86d4c..ba225fd 100644
--- a/editor/key-list-box-row.vala
+++ b/editor/key-list-box-row.vala
@@ -276,7 +276,7 @@ private abstract class KeyListBoxRow : ClickableListBoxRow
         else
         {
             context.remove_class ("delayed");
-            if (key is DConfKey && model.is_key_ghost ((DConfKey) key))
+            if (key is DConfKey && model.is_key_ghost (key.full_name))
                 context.add_class ("erase");
             else
                 context.remove_class ("erase");
@@ -351,7 +351,7 @@ private class KeyListBoxRowEditableNoSchema : KeyListBoxRow
     protected override void update ()
     {
         SettingsModel model = modifications_handler.model;
-        if (model.is_key_ghost (key))
+        if (model.is_key_ghost (key.full_name))
         {
             if (boolean_switch != null)
             {
@@ -390,7 +390,7 @@ private class KeyListBoxRowEditableNoSchema : KeyListBoxRow
         Variant variant_s = new Variant.string (key.full_name);
         Variant variant_ss = new Variant ("(ss)", key.full_name, ".dconf");
 
-        if (model.is_key_ghost (key))
+        if (model.is_key_ghost (key.full_name))
         {
             popover.new_gaction ("copy", "app.copy(" + get_text_variant ().print (false) + ")");
             return true;
diff --git a/editor/modifications-revealer.vala b/editor/modifications-revealer.vala
index 03365ea..41925d6 100644
--- a/editor/modifications-revealer.vala
+++ b/editor/modifications-revealer.vala
@@ -101,7 +101,7 @@ class ModificationsRevealer : Revealer
             }
             if (setting_object is DConfKey)
             {
-                if (!model.is_key_ghost ((DConfKey) setting_object))
+                if (!model.is_key_ghost (setting_object.full_name))
                     modifications_handler.add_delayed_setting (setting_object.full_name, null);
             }
             else if (!model.is_key_default ((GSettingsKey) setting_object))
@@ -157,7 +157,7 @@ class ModificationsRevealer : Revealer
         string full_name = ((Key) key).full_name;
         bool has_schema = key is GSettingsKey;
         bool is_default_or_ghost = has_schema ? modifications_handler.model.is_key_default ((GSettingsKey) 
key)
-                                              : modifications_handler.model.is_key_ghost ((DConfKey) key);
+                                              : modifications_handler.model.is_key_ghost (full_name);
         Variant? planned_value = modifications_handler.get_key_planned_value (full_name);
         string? cool_planned_value = null;
         if (planned_value != null)
diff --git a/editor/registry-info.vala b/editor/registry-info.vala
index 6d2833b..605c617 100644
--- a/editor/registry-info.vala
+++ b/editor/registry-info.vala
@@ -66,7 +66,7 @@ class RegistryInfo : Grid, BrowsableView
     public void populate_properties_list_box (Key key)
     {
         SettingsModel model = modifications_handler.model;
-        if (key is DConfKey && model.is_key_ghost ((DConfKey) key))   // TODO place in "requires"
+        if (key is DConfKey && model.is_key_ghost (key.full_name))   // TODO place in "requires"
             assert_not_reached ();
         clean ();   // for when switching between two keys, for example with a search (maybe also bookmarks)
 
@@ -146,7 +146,7 @@ class RegistryInfo : Grid, BrowsableView
         {
             label = new Label (get_current_value_text (has_schema && model.is_key_default ((GSettingsKey) 
key), key, modifications_handler.model));
             key_value_changed_handler = key.value_changed.connect (() => {
-                    if (!has_schema && model.is_key_ghost ((DConfKey) key))
+                    if (!has_schema && model.is_key_ghost (key.full_name))
                         label.set_text (_("Key erased."));
                     else
                         label.set_text (get_current_value_text (has_schema && model.is_key_default 
((GSettingsKey) key), key, modifications_handler.model));
@@ -245,7 +245,7 @@ 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.leave_delay_mode.connect (() => {
-                if (key is DConfKey && model.is_key_ghost ((DConfKey) key))
+                if (key is DConfKey && model.is_key_ghost (key.full_name))
                     return;
                 SignalHandler.block (key_editor_child, value_has_changed_handler);
                 key_editor_child.reload (model.get_key_value (key));


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