[dconf-editor] Generate keys properties late.



commit 70cc90774e477a608be70d80052e5322591c4b21
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Tue Jul 24 17:27:50 2018 +0200

    Generate keys properties late.
    
    That will allow to include infos about duplicated keys in it.

 editor/dconf-model.vala    |   2 +-
 editor/registry-info.vala  |   3 +-
 editor/setting-object.vala | 117 +++++++++++++++++++++++++++++----------------
 3 files changed, 79 insertions(+), 43 deletions(-)
---
diff --git a/editor/dconf-model.vala b/editor/dconf-model.vala
index 21cc18c..27efc41 100644
--- a/editor/dconf-model.vala
+++ b/editor/dconf-model.vala
@@ -756,7 +756,7 @@ public class SettingsModel : Object
         if (key == null)
             return null;
 
-        return ((!) key).properties;
+        return ((!) key).get_properties ({});
     }
 
     public string get_key_copy_text (string full_name, string context)
diff --git a/editor/registry-info.vala b/editor/registry-info.vala
index ab64bab..7735df3 100644
--- a/editor/registry-info.vala
+++ b/editor/registry-info.vala
@@ -115,11 +115,10 @@ class RegistryInfo : Grid, BrowsableView
         Variant dict = dict_container [0];
 
         // TODO use VariantDict
-        string key_name, parent_path, type_code, range_type, tmp_string;
+        string key_name, type_code, range_type, tmp_string;
         bool test;
 
         if (!dict.lookup ("key-name",     "s", out key_name))    assert_not_reached ();
-        if (!dict.lookup ("parent-path",  "s", out parent_path)) assert_not_reached ();
         if (!dict.lookup ("type-code",    "s", out type_code))   assert_not_reached ();
 
         if (dict.lookup ("defined-by",    "s", out tmp_string))  add_row_from_label (_("Defined by"),  
tmp_string);
diff --git a/editor/setting-object.vala b/editor/setting-object.vala
index 645927d..90a7f99 100644
--- a/editor/setting-object.vala
+++ b/editor/setting-object.vala
@@ -52,7 +52,22 @@ public class Directory : SettingObject
 public abstract class Key : SettingObject
 {
     public string type_string { get; protected set; default = "*"; }
-    public Variant properties { owned get; protected set; }
+
+    private Variant? all_properties = null;
+    protected abstract Variant generate_properties (string [] query);
+    public Variant get_properties (string [] query)
+    {
+        bool all_properties_queried = query.length == 0;
+        if (all_properties_queried && all_properties != null)
+            return (!) all_properties;
+
+        // generating properties late allows to include things about duplicated keys, that are known at the 
key's creation
+        Variant properties = generate_properties (query);
+
+        if (all_properties_queried)
+            all_properties = properties;
+        return properties;
+    }
 
     public signal void value_changed ();
     public ulong key_value_changed_handler = 0;
@@ -267,33 +282,43 @@ public class DConfKey : Key
     {
         Object (context: ".dconf", full_name: parent_full_name + name, name: name, type_string: type_string);
 
+        client.changed.connect ((client, prefix, changes, tag) => {
+                foreach (string item in changes)
+                    if (prefix + item == full_name)
+                    {
+                        value_changed ();
+                        return;
+                    }
+            });
+    }
+
+    protected override Variant generate_properties (string [] query)
+    {
+        bool all_properties_queried = query.length == 0;
+
         VariantBuilder builder = new VariantBuilder (new VariantType ("(ba{ss})"));     // TODO add 
VariantBuilder add_parsed () function in vala/glib-2.0.vapi line ~5490
         builder.add ("b",    false);
         builder.open (new VariantType ("a{ss}"));
-        builder.add ("{ss}", "key-name",    name);
-        builder.add ("{ss}", "defined-by",  _("DConf backend"));
-        builder.add ("{ss}", "parent-path", parent_full_name);
-        builder.add ("{ss}", "type-code",   type_string);
-        builder.add ("{ss}", "type-name",   key_to_description (type_string));
-        if (show_min_and_max (type_string))
+
+        if (all_properties_queried || "key-name" in query)
+            builder.add ("{ss}",      "key-name",           name);
+        if (all_properties_queried || "defined-by" in query)
+            builder.add ("{ss}",      "defined-by",         _("DConf backend"));
+        if (all_properties_queried || "type-code" in query)
+            builder.add ("{ss}",      "type-code",          type_string);
+        if (all_properties_queried || "type-name" in query)
+            builder.add ("{ss}",      "type-name",          key_to_description (type_string));
+
+        if (show_min_and_max (type_string) && (all_properties_queried || "minimum" in query || "maximum" in 
query))
         {
             string min, max;
             get_min_and_max_string (out min, out max, type_string);
 
-            builder.add ("{ss}", "minimum", min);
-            builder.add ("{ss}", "maximum", max);
+            builder.add ("{ss}",      "minimum",            min);
+            builder.add ("{ss}",      "maximum",            max);
         }
         builder.close ();
-        properties = builder.end ();
-
-        client.changed.connect ((client, prefix, changes, tag) => {
-                foreach (string item in changes)
-                    if (prefix + item == full_name)
-                    {
-                        value_changed ();
-                        return;
-                    }
-            });
+        return builder.end ();
     }
 }
 
@@ -302,12 +327,12 @@ public class GSettingsKey : Key
     public bool warning_conflicting_key = false;
     public bool error_hard_conflicting_key = false;
 
-    public string? schema_path   { private get; construct; }
-    public string summary        { private get; construct; }
-    public string description    { private get; construct; }
-    public Variant default_value         { get; construct; }
-    public string range_type             { get; construct; }
-    public Variant range_content         { get; construct; }
+    public string? schema_path  { private get; construct; }
+    public string summary       { private get; construct; }
+    public string description   { private get; construct; }
+    public Variant default_value        { get; construct; }
+    public string range_type            { get; construct; }
+    public Variant range_content        { get; construct; }
 
     public string descriptor {
         owned get {
@@ -348,29 +373,42 @@ public class GSettingsKey : Key
                 schema_path: schema_path,
                 summary: summary,
                 description: description,
+                type_string: type_string,
                 default_value: default_value,       // TODO devel default/admin default
                 range_type: range_type,
                 range_content: range_content);
 
         settings.changed [name].connect (() => value_changed ());
+    }
 
-        this.type_string = type_string;
+    protected override Variant generate_properties (string [] query)
+    {
+        bool all_properties_queried = query.length == 0;
 
         string defined_by = schema_path == null ? _("Relocatable schema") : _("Schema with path");
 
         VariantBuilder builder = new VariantBuilder (new VariantType ("(ba{ss})"));
         builder.add ("b",    true);
         builder.open (new VariantType ("a{ss}"));
-        builder.add ("{ss}", "key-name",      name);
-        builder.add ("{ss}", "defined-by",    defined_by);
-        builder.add ("{ss}", "parent-path",   parent_full_name);
-        builder.add ("{ss}", "type-code",     type_string);
-        builder.add ("{ss}", "type-name",     key_to_description (type_string));
-        builder.add ("{ss}", "summary",       summary);
-        builder.add ("{ss}", "description",   description);
-        builder.add ("{ss}", "default-value", cool_text_value_from_variant (default_value));
-        builder.add ("{ss}", "range-type",    range_type);
-        if (show_min_and_max (type_string))
+
+        if (all_properties_queried || "key-name" in query)
+            builder.add ("{ss}",      "key-name",           name);
+        if (all_properties_queried || "defined-by" in query)
+            builder.add ("{ss}",      "defined-by",         defined_by);
+        if (all_properties_queried || "type-code" in query)
+            builder.add ("{ss}",      "type-code",          type_string);
+        if (all_properties_queried || "type-name" in query)
+            builder.add ("{ss}",      "type-name",          key_to_description (type_string));
+        if (all_properties_queried || "summary" in query)
+            builder.add ("{ss}",      "summary",            summary);
+        if (all_properties_queried || "description" in query)
+            builder.add ("{ss}",      "description",        description);
+        if (all_properties_queried || "default-value" in query)
+            builder.add ("{ss}",      "default-value",      cool_text_value_from_variant (default_value));
+        if (all_properties_queried || "range-type" in query)
+            builder.add ("{ss}",      "range-type",         range_type);
+
+        if (show_min_and_max (type_string) && (all_properties_queried || "minimum" in query || "maximum" in 
query))
         {
             string min, max;
             if (range_type == "range")     // TODO test more; and what happen if only min/max is in range?
@@ -381,11 +419,10 @@ public class GSettingsKey : Key
             else
                 get_min_and_max_string (out min, out max, type_string);
 
-            builder.add ("{ss}", "minimum", min);
-            builder.add ("{ss}", "maximum", max);
+            builder.add ("{ss}",      "minimum",            min);
+            builder.add ("{ss}",      "maximum",            max);
         }
         builder.close ();
-        properties = builder.end ();
+        return builder.end ();
     }
 }
-


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