[dconf-editor] Remove SchemaKey.



commit 868d21cf9987ec3449288923c00c304d4632aeb7
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Tue Oct 13 01:08:58 2015 +0200

    Remove SchemaKey.

 editor/dconf-model.vala  |  100 ++++++++++++++++++++++-----------------------
 editor/dconf-view.vala   |   20 +++++-----
 editor/dconf-window.vala |   10 ++--
 3 files changed, 64 insertions(+), 66 deletions(-)
---
diff --git a/editor/dconf-model.vala b/editor/dconf-model.vala
index 7ad8dcd..e4611ff 100644
--- a/editor/dconf-model.vala
+++ b/editor/dconf-model.vala
@@ -15,18 +15,6 @@
   along with Dconf Editor.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-public struct SchemaKey
-{
-    public string schema_id;
-    public string name;
-    public string summary;
-    public string description;
-    public Variant default_value;
-    public string type;
-    public string range_type;
-    public Variant range_content;
-}
-
 public class SettingObject : Object
 {
     public Directory? parent { get; protected set; }    // TODO make protected or even remove
@@ -156,7 +144,12 @@ public class GSettingsKey : Key
 {
     private DConf.Client client;
 
-    public SchemaKey schema;
+    public string schema_id { get; private set; }
+    public string summary { get; private set; }
+    public string description { get; private set; }
+    public Variant default_value { get; private set; }
+    public string range_type { get; private set; }
+    public Variant range_content { get; private set; }
 
     public override bool has_schema { get { return true; } }
 
@@ -166,7 +159,7 @@ public class GSettingsKey : Key
         get
         {
             update_value ();
-            return _value ?? schema.default_value;
+            return _value ?? default_value;
         }
         set
         {
@@ -187,7 +180,7 @@ public class GSettingsKey : Key
         get { update_value (); return _value == null; }
     }
 
-    public GSettingsKey (DConf.Client client, Directory parent, string name, SchemaKey schema)
+    public GSettingsKey (DConf.Client client, Directory parent, string name, string schema_id, string 
summary, string description, string type_string, Variant default_value, string range_type, Variant 
range_content)
     {
         this.client = client;
         this.parent = parent;
@@ -196,8 +189,16 @@ public class GSettingsKey : Key
         path = parent.full_name;
         full_name = path + name;
 
-        this.schema = schema;
-        type_string = schema.type;
+        this.schema_id = schema_id;
+
+        this.summary = summary;
+        this.description = description;
+
+        this.type_string = type_string;
+        this.default_value = default_value;
+
+        this.range_type = range_type;
+        this.range_content = range_content;
     }
 
     public void set_to_default ()
@@ -270,16 +271,12 @@ public class SettingsModel : Object, Gtk.TreeModel
 
     private void create_dconf_views (Directory parent_view)
     {
-        string [] items = client.list (parent_view.full_name);
-        for (int i = 0; i < items.length; i++)
+        foreach (string item in client.list (parent_view.full_name))
         {
-            if (DConf.is_dir (parent_view.full_name + items [i]))
-            {
-                Directory view = get_child (parent_view, items [i][0:-1]);
-                create_dconf_views (view);
-            }
-            else
-                make_key (parent_view, items [i], null);
+            if (DConf.is_dir (parent_view.full_name + item))
+                create_dconf_views (get_child (parent_view, item [0:-1]));
+            else if (!key_exists (parent_view, item))
+                connect_key (parent_view, item, new DConfKey (client, parent_view, item));
         }
     }
 
@@ -304,44 +301,45 @@ public class SettingsModel : Object, Gtk.TreeModel
         string schema_id = settings_schema.get_id ();
         foreach (string key_id in settings_schema.list_keys ())
         {
+            if (key_exists (view, key_id))
+                continue;
+
             SettingsSchemaKey settings_schema_key = settings_schema.get_key (key_id);
 
             string range_type = settings_schema_key.get_range ().get_child_value (0).get_string (); // don’t 
put it in the switch, or it fails
-            string type;
+            string type_string;
             switch (range_type)
             {
-                case "enum":    type = "<enum>"; break;  // <choices> or enum="", and hopefully <aliases>
-                case "flags":   type = "as";     break;  // TODO better
+                case "enum":    type_string = "<enum>"; break;  // <choices> or enum="", and hopefully 
<aliases>
+                case "flags":   type_string = "as";     break;  // TODO better
                 default:
-                case "type":    type = (string) settings_schema_key.get_value_type ().peek_string (); break;
+                case "type":    type_string = (string) settings_schema_key.get_value_type ().peek_string (); 
break;
             }
 
-            SchemaKey key = SchemaKey () {
-                    schema_id = schema_id,
-                    name = key_id,
-                    summary = (settings_schema_key.get_summary () ?? "").strip (),
-                    description = (settings_schema_key.get_description () ?? "").strip (),
-                    default_value = settings_schema_key.get_default_value (),
-                    type = type,
-                    range_type = range_type,
-                    range_content = settings_schema_key.get_range ().get_child_value (1).get_child_value (0)
-                };
-
-            make_key (view, key_id, key);
+            GSettingsKey new_key = new GSettingsKey (
+                    client,
+                    view,
+                    key_id,
+                    schema_id,
+                    (settings_schema_key.get_summary () ?? "").strip (),
+                    (settings_schema_key.get_description () ?? "").strip (),
+                    type_string,
+                    settings_schema_key.get_default_value (),
+                    range_type,
+                    settings_schema_key.get_range ().get_child_value (1).get_child_value (0)
+                );
+            connect_key (view, key_id, (Key) new_key);
         }
     }
 
-    private void make_key (Directory view, string name, SchemaKey? schema_key)
+    private bool key_exists (Directory view, string key_id)     // TODO better
     {
-        Key? key = view.key_map.lookup (name);
-        if (key != null)
-            return;
+        Key? key = view.key_map.lookup (key_id);
+        return key != null;
+    }
 
-        Key new_key;
-        if (schema_key == null)
-            new_key = new DConfKey (client, view, name);
-        else
-            new_key = new GSettingsKey (client, view, name, (!) schema_key);
+    private void connect_key (Directory view, string name, Key new_key)
+    {
         item_changed.connect ((key_name) => {
                 if ((key_name.has_suffix ("/") && new_key.full_name.has_prefix (key_name)) || key_name == 
new_key.full_name)
                     new_key.value_changed ();
diff --git a/editor/dconf-view.vala b/editor/dconf-view.vala
index cd743db..e7ceb8e 100644
--- a/editor/dconf-view.vala
+++ b/editor/dconf-view.vala
@@ -225,11 +225,11 @@ private class KeyEditor : KeyEditorDialog
 
         // infos
 
-        schema_label.set_text (key.schema.schema_id);
-        summary_label.set_text (key.schema.summary);
-        description_label.set_text (key.schema.description);
+        schema_label.set_text (key.schema_id);
+        summary_label.set_text (key.summary);
+        description_label.set_text (key.description);
         type_label.set_text (key_to_description ());
-        default_label.set_text (Key.cool_text_value_from_variant (key.schema.default_value, 
key.schema.type));
+        default_label.set_text (Key.cool_text_value_from_variant (key.default_value, key.type_string));
 
         // switch
 
@@ -240,10 +240,10 @@ private class KeyEditor : KeyEditorDialog
 
     protected override void get_min_and_max (out string min, out string max)
     {
-        if (key.schema.range_type == "range")     // TODO test more; and what happen if only min/max is in 
range?
+        if (key.range_type == "range")     // TODO test more; and what happen if only min/max is in range?
         {
-            min = Key.cool_text_value_from_variant (key.schema.range_content.get_child_value (0), 
key.type_string);
-            max = Key.cool_text_value_from_variant (key.schema.range_content.get_child_value (1), 
key.type_string);
+            min = Key.cool_text_value_from_variant (key.range_content.get_child_value (0), key.type_string);
+            max = Key.cool_text_value_from_variant (key.range_content.get_child_value (1), key.type_string);
         }
         else
             base.get_min_and_max (out min, out max);
@@ -420,10 +420,10 @@ private class KeyEditorChildNumber : Grid, KeyEditorChild
         this.attach (new_label_custom_value (), 0, 0, 1, 1);
 
         double min, max;
-        if (key.has_schema && ((GSettingsKey) key).schema.range_type == "range")    // TODO test more; and 
what happen if only min/max is in range?
+        if (key.has_schema && ((GSettingsKey) key).range_type == "range")    // TODO test more; and what 
happen if only min/max is in range?
         {
-            min = get_variant_as_double (((GSettingsKey) key).schema.range_content.get_child_value (0));
-            max = get_variant_as_double (((GSettingsKey) key).schema.range_content.get_child_value (1));
+            min = get_variant_as_double (((GSettingsKey) key).range_content.get_child_value (0));
+            max = get_variant_as_double (((GSettingsKey) key).range_content.get_child_value (1));
         }
         else
             get_min_and_max_double (out min, out max, key.type_string);
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index 2492be3..d26e634 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -252,9 +252,9 @@ class DConfWindow : ApplicationWindow
         /* Check key schema (description) */
         if (key.has_schema)
         {
-            if (((GSettingsKey) key).schema.summary.index_of (text) >= 0)
+            if (((GSettingsKey) key).summary.index_of (text) >= 0)
                 return true;
-            if (((GSettingsKey) key).schema.description.index_of (text) >= 0)
+            if (((GSettingsKey) key).description.index_of (text) >= 0)
                 return true;
         }
 
@@ -472,7 +472,7 @@ private class KeyListBoxRowEditable : KeyListBoxRow
         key_value_label.set_attributes (attr_list);
         update ();      // sets key_name_label attributes and key_value_label label
         key_name_label.label = key.name;
-        key_info_label.label = key.schema.summary;
+        key_info_label.label = key.summary;
 
         key.value_changed.connect (() => { update (); if (popover != null) popover.destroy (); });
     }
@@ -485,7 +485,7 @@ private class KeyListBoxRowEditable : KeyListBoxRow
                 Gdk.Display? display = Gdk.Display.get_default ();
                     if (display == null) return;
                 Clipboard clipboard = Clipboard.get_default ((!) display);
-                string copy = key.schema.schema_id + " " + key.name + " " + key.value.print (false);
+                string copy = key.schema_id + " " + key.name + " " + key.value.print (false);
                 clipboard.set_text (copy, copy.length);
             });
 
@@ -576,7 +576,7 @@ private class ContextPopover : Popover
                 add_model_button (Key.cool_boolean_text_value (false), new Variant.maybe 
(VariantType.BOOLEAN, new Variant.boolean (false)));
                 break;
             case "<enum>":      // defined by the schema
-                Variant range = ((GSettingsKey) key).schema.range_content;
+                Variant range = ((GSettingsKey) key).range_content;
                 uint size = (uint) range.n_children ();
                 if (size == 0)      // TODO special case also 1?
                     assert_not_reached ();


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