[dconf-editor] Clean ModificationsRevealer API.



commit 9c287d1df64d761bb505d78341a4ff22fc88cbf1
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Thu Jun 23 15:58:18 2016 +0200

    Clean ModificationsRevealer API.

 editor/dconf-model.vala            |    5 +++-
 editor/key-list-box-row.vala       |    2 +-
 editor/modifications-revealer.vala |   36 ++++++++++++---------------------
 editor/registry-view.vala          |   38 +++++++++++------------------------
 4 files changed, 30 insertions(+), 51 deletions(-)
---
diff --git a/editor/dconf-model.vala b/editor/dconf-model.vala
index 53fceba..1036c6c 100644
--- a/editor/dconf-model.vala
+++ b/editor/dconf-model.vala
@@ -175,6 +175,7 @@ public abstract class Key : SettingObject
 {
     public override bool is_view { get { return false; } }
     public abstract bool has_schema { get; }
+    public abstract string descriptor { owned get; }
 
     public string type_string { get; protected set; default = "*"; }
     public Variant properties { owned get; protected set; }
@@ -328,6 +329,8 @@ public class DConfKey : Key
 {
     public override bool has_schema { get { return false; } }
 
+    public override string descriptor { owned get { return full_name; } }
+
     private DConf.Client client;
 
     public bool is_ghost { get; set; default = false; }
@@ -390,7 +393,7 @@ public class GSettingsKey : Key
     public string range_type             { get; construct; }
     public Variant range_content         { get; construct; }
 
-    public string descriptor { owned get { return schema_id + " " + name; } }
+    public override string descriptor { owned get { return schema_id + " " + name; } }
 
     private GLib.Settings settings;
 
diff --git a/editor/key-list-box-row.vala b/editor/key-list-box-row.vala
index 8607bcf..820da23 100644
--- a/editor/key-list-box-row.vala
+++ b/editor/key-list-box-row.vala
@@ -156,7 +156,7 @@ private class KeyListBoxRowEditableNoSchema : KeyListBoxRow
 
     protected override string get_text ()
     {
-        return key.is_ghost ? _("%s (key erased)").printf (key.full_name) : key.full_name + " " + 
key.value.print (false);
+        return key.is_ghost ? _("%s (key erased)").printf (key.full_name) : key.descriptor + " " + 
key.value.print (false);
     }
 
     protected override bool generate_popover (ContextPopover popover, bool delayed_apply_menu)
diff --git a/editor/modifications-revealer.vala b/editor/modifications-revealer.vala
index 95f4235..7280d32 100644
--- a/editor/modifications-revealer.vala
+++ b/editor/modifications-revealer.vala
@@ -33,38 +33,28 @@ class ModificationsRevealer : Revealer
     * * Public calls
     \*/
 
-    public void add_delayed_dconf_settings (DConfKey key, Variant? new_value)
+    public void add_delayed_setting (Key key, Variant? new_value)
     {
         key.planned_change = true;
         key.planned_value = new_value;
-        dconf_keys_awaiting_hashtable.insert (key.full_name, key);
 
-        update ();
-    }
-
-    public void add_delayed_glib_settings (GSettingsKey key, Variant? new_value)
-    {
-        key.planned_change = true;
-        key.planned_value = new_value;
-        gsettings_keys_awaiting_hashtable.insert (key.descriptor, key);
+        if (key.has_schema)
+            gsettings_keys_awaiting_hashtable.insert (key.descriptor, (GSettingsKey) key);
+        else
+            dconf_keys_awaiting_hashtable.insert (key.descriptor, (DConfKey) key);
 
         update ();
     }
 
-    public void dismiss_dconf_change (DConfKey key)
+    public void dismiss_change (Key key)
     {
         key.planned_change = false;
         key.planned_value = null;
-        dconf_keys_awaiting_hashtable.remove (key.full_name);
 
-        update ();
-    }
-
-    public void dismiss_glib_change (GSettingsKey key)
-    {
-        key.planned_change = false;
-        key.planned_value = null;
-        gsettings_keys_awaiting_hashtable.remove (key.descriptor);
+        if (key.has_schema)
+            gsettings_keys_awaiting_hashtable.remove (key.descriptor);
+        else
+            dconf_keys_awaiting_hashtable.remove (key.descriptor);
 
         update ();
     }
@@ -105,8 +95,8 @@ class ModificationsRevealer : Revealer
         /* DConf stuff */
 
         DConf.Changeset dconf_changeset = new DConf.Changeset ();
-        dconf_keys_awaiting_hashtable.foreach_remove ((full_name, key) => {
-                dconf_changeset.set (full_name, key.planned_value);
+        dconf_keys_awaiting_hashtable.foreach_remove ((descriptor, key) => {
+                dconf_changeset.set (key.full_name, key.planned_value);
 
                 if (key.planned_value == null)
                     key.is_ghost = true;
@@ -137,7 +127,7 @@ class ModificationsRevealer : Revealer
 
         /* DConf stuff */
 
-        dconf_keys_awaiting_hashtable.foreach_remove ((full_name, key) => {
+        dconf_keys_awaiting_hashtable.foreach_remove ((descriptor, key) => {
                 key.planned_change = false;
                 return true;
             });
diff --git a/editor/registry-view.vala b/editor/registry-view.vala
index a7c1f22..4b540e5 100644
--- a/editor/registry-view.vala
+++ b/editor/registry-view.vala
@@ -136,19 +136,13 @@ class RegistryView : Grid
         {
             Key key = (Key) item;
             if (key.has_schema)
-            {
-                GSettingsKey gkey = (GSettingsKey) key;
-                row = new KeyListBoxRowEditable (gkey);
-                ((KeyListBoxRow) row).set_key_value.connect ((variant) => { set_glib_key_value (gkey, 
variant); });
-                ((KeyListBoxRow) row).change_dismissed.connect (() => { revealer.dismiss_glib_change (gkey); 
});
-            }
+                row = new KeyListBoxRowEditable ((GSettingsKey) key);
             else
-            {
-                DConfKey dkey = (DConfKey) key;
-                row = new KeyListBoxRowEditableNoSchema (dkey);
-                ((KeyListBoxRow) row).set_key_value.connect ((variant) => { set_dconf_key_value (dkey, 
variant); });
-                ((KeyListBoxRow) row).change_dismissed.connect (() => { revealer.dismiss_dconf_change 
(dkey); });
-            }
+                row = new KeyListBoxRowEditableNoSchema ((DConfKey) key);
+
+            ((KeyListBoxRow) row).set_key_value.connect ((variant) => { set_key_value (key, variant); });
+            ((KeyListBoxRow) row).change_dismissed.connect (() => { revealer.dismiss_change (key); });
+
             row.on_row_clicked.connect (() => { new_key_editor (key); });
             // TODO bug: row is always visually activated after the dialog destruction if mouse is over at 
this time
         }
@@ -310,26 +304,18 @@ class RegistryView : Grid
     * * Revealer stuff
     \*/
 
-    private void set_dconf_key_value (DConfKey key, Variant? new_value)
+    private void set_key_value (Key key, Variant? new_value)
     {
         if (delayed_apply_menu || key.planned_change)
-            revealer.add_delayed_dconf_settings (key, new_value);
+            revealer.add_delayed_setting (key, new_value);
         else if (new_value != null)
             key.value = (!) new_value;
+        else if (key.has_schema)
+            ((GSettingsKey) key).set_to_default ();
         else
             assert_not_reached ();
     }
 
-    private void set_glib_key_value (GSettingsKey key, Variant? new_value)
-    {
-        if (delayed_apply_menu || key.planned_change)
-            revealer.add_delayed_glib_settings (key, new_value);
-        else if (new_value != null)
-            key.value = (!) new_value;
-        else
-            key.set_to_default ();
-    }
-
     /*\
     * * Action entries
     \*/
@@ -361,10 +347,10 @@ class RegistryView : Grid
             if (!((Key) setting_object).has_schema)
             {
                 if (!((DConfKey) setting_object).is_ghost)
-                    revealer.add_delayed_dconf_settings ((DConfKey) setting_object, null);
+                    revealer.add_delayed_setting ((Key) setting_object, null);
             }
             else if (!((GSettingsKey) setting_object).is_default)
-                revealer.add_delayed_glib_settings ((GSettingsKey) setting_object, null);
+                revealer.add_delayed_setting ((Key) setting_object, null);
         }
     }
 


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