[dconf-editor] Use GSettingsSchema* APIs.



commit 90923b44cccb882b839b818e146d6b491c955848
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Wed Sep 30 22:21:01 2015 +0200

    Use GSettingsSchema* APIs.

 configure.ac             |    1 -
 editor/dconf-model.vala  |   56 +++---
 editor/dconf-schema.vala |  490 +++-------------------------------------------
 editor/dconf-view.vala   |   79 ++++----
 editor/dconf-window.vala |   37 +---
 5 files changed, 97 insertions(+), 566 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 13ec23c..010e737 100644
--- a/configure.ac
+++ b/configure.ac
@@ -36,7 +36,6 @@ PKG_CHECK_MODULES(DCONF_EDITOR, [
   gtk+-3.0 >= $GTK_REQUIRED
   dconf >= $DCONF_REQUIRED
   gmodule-2.0
-  libxml-2.0
 ])
 
 AC_SUBST([GLIB_REQUIRED])
diff --git a/editor/dconf-model.vala b/editor/dconf-model.vala
index 0526b50..3a33414 100644
--- a/editor/dconf-model.vala
+++ b/editor/dconf-model.vala
@@ -76,17 +76,12 @@ public class Key : GLib.Object
         this.parent = parent;
         this.name = name;
         this.full_name = full_name;
-        this.schema = model.schemas.keys.lookup(full_name);
 
+        schema = model.keys.lookup (full_name);
         has_schema = schema != null;
 
         if (has_schema)
-        {
-            if (schema.type == "s" && schema.enum_name != null)
-                type_string = "<enum>";
-            else
-                type_string = schema.type;
-        }
+            type_string = schema.type;
         else if (value != null)
             type_string = value.get_type_string ();
 
@@ -219,7 +214,8 @@ public class Directory : GLib.Object
 
 public class SettingsModel: GLib.Object, Gtk.TreeModel
 {
-    public SchemaList schemas;
+    public GLib.HashTable<string, Schema> schemas = new GLib.HashTable<string, Schema> (str_hash, str_equal);
+    public GLib.HashTable<string, SchemaKey> keys = new GLib.HashTable<string, SchemaKey> (str_hash, 
str_equal);
 
     public DConf.Client client;
     private Directory root;
@@ -235,27 +231,15 @@ public class SettingsModel: GLib.Object, Gtk.TreeModel
 
     public SettingsModel()
     {
-        schemas = new SchemaList();
-        try
-        {
-            var dirs = GLib.Environment.get_system_data_dirs();
+        SettingsSchemaSource settings_schema_source = SettingsSchemaSource.get_default ();
+        string [] non_relocatable_schemas;
+        string [] relocatable_schemas;
+        settings_schema_source.list_schemas (true /* TODO is_recursive = false */, out 
non_relocatable_schemas, out relocatable_schemas);
 
-            /* Walk directories in reverse so the schemas in the
-             * directory which appears first in the XDG_DATA_DIRS are
-             * not overridden. */
-            for (int i = dirs.length - 1; i >= 0; i--)
-            {
-                var path = Path.build_filename (dirs[i], "glib-2.0", "schemas");
-                if (File.new_for_path (path).query_exists ())
-                    schemas.load_directory (path);
-            }
-
-            var dir = GLib.Environment.get_variable ("GSETTINGS_SCHEMA_DIR");
-            if (dir != null)
-                schemas.load_directory(dir);
-        } catch (Error e) {
-            warning("Failed to parse schemas: %s", e.message);
-        }
+        foreach (string settings_schema_id in non_relocatable_schemas)
+            create_schema (settings_schema_source.lookup (settings_schema_id, true));
+//        foreach (string settings_schema_id in relocatable_schemas)           // TODO
+//            stderr.printf ("%s\n", settings_schema_id);
 
         client = new DConf.Client ();
         client.changed.connect (watch_func);
@@ -263,10 +247,24 @@ public class SettingsModel: GLib.Object, Gtk.TreeModel
         client.watch_sync ("/");
 
         /* Add keys for the values in the schemas */
-        foreach (var schema in schemas.schemas.get_values())
+        foreach (Schema schema in schemas.get_values ())
             root.load_schema (schema, schema.path [1:schema.path.length]);
     }
 
+    public void create_schema (SettingsSchema settings_schema)
+    {
+        string schema_id = settings_schema.get_id ();
+        Schema schema = new Schema ();
+        schema.path = settings_schema.get_path ();          // TODO will always returns null for relocatable 
schemas
+        foreach (string key_id in settings_schema.list_keys ())
+        {
+            SchemaKey key = new SchemaKey (key_id, settings_schema.get_key (key_id));
+            schema.keys.insert (key.name, key);
+            keys.insert (schema.path + key.name, key);
+        }
+        schemas.insert (schema_id, schema);
+    }
+
     public Gtk.TreeModelFlags get_flags()
     {
         return 0;
diff --git a/editor/dconf-schema.vala b/editor/dconf-schema.vala
index 4e4449f..b35696f 100644
--- a/editor/dconf-schema.vala
+++ b/editor/dconf-schema.vala
@@ -15,488 +15,44 @@
   along with Dconf Editor.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-public class SchemaKey
+public class SchemaKey : GLib.Object
 {
-    public Schema schema;
+    public string id;
+    public SettingsSchemaKey settings_schema_key;
+
     public string name;
-    public string type;
-    public Variant default_value;
-    public SchemaValueRange? range;
-    public SchemaValueRange type_range;
-    public List<SchemaChoice> choices;
-    public string? enum_name;
     public string? summary;
     public string? description;
-    public string? gettext_domain;
-
-    public SchemaKey.from_xml(Xml.Node* node, Schema schema, string? gettext_domain)
-    {
-        this.schema = schema;
-        this.gettext_domain = gettext_domain;
-
-        for (var prop = node->properties; prop != null; prop = prop->next)
-        {
-            if (prop->name == "name")
-                name = prop->children->content;
-            else if (prop->name == "type")
-                type = prop->children->content;
-            else if (prop->name == "enum")
-            {
-                type = "s";
-                enum_name = prop->children->content;
-            }
-            else if (prop->name == "flags")
-                /* TODO: support this properly */
-                type = "as";
-            else
-                warning ("Unknown property on <key>, %s", prop->name);
-        }
-
-        //if (name == null || type == null)
-        //    ?
-
-        for (var child = node->children; child != null; child = child->next)
-        {
-            if (child->name == "default")
-            {
-                try
-                {
-                    default_value = Variant.parse(new VariantType(type), child->get_content());
-                }
-                catch (VariantParseError e)
-                {
-                    // ...
-                }
-            }
-            else if (child->name == "summary")
-                summary = child->get_content();
-            else if (child->name == "description")
-                description = child->get_content();
-            else if (child->name == "range")
-                range = new SchemaValueRange.from_xml(type, child);
-            else if (child->name == "choices")
-            {
-                for (var n = child->children; n != null; n = n->next)
-                {
-                    if (n->type != Xml.ElementType.ELEMENT_NODE)
-                        continue;
-                    if (n->name != "choice")
-                    {
-                        warning ("Unknown child tag in <choices>, <%s>", n->name);
-                        continue;
-                    }
-
-                    string? value = null;
-                    for (var prop = n->properties; prop != null; prop = prop->next)
-                    {
-                        if (prop->name == "value")
-                            value = prop->children->content;
-                        else
-                            warning ("Unknown property on <choice>, %s", prop->name);
-                    }
-
-                    if (value == null)
-                    {
-                        warning ("Ignoring <choice> with no value");
-                        continue;
-                    }
-
-                    var v = new Variant.string (value);
-                    choices.append (new SchemaChoice(value, v));
-                }
-            }
-            else if (child->name == "aliases")
-            {
-                for (var n = child->children; n != null; n = n->next)
-                {
-                    if (n->type != Xml.ElementType.ELEMENT_NODE)
-                        continue;
-                    if (n->name != "alias")
-                    {
-                        warning ("Unknown child tag in <aliases>, <%s>", n->name);
-                        continue;
-                    }
-
-                    string? value = null, target = null;
-                    for (var prop = n->properties; prop != null; prop = prop->next)
-                    {
-                        if (prop->name == "value")
-                            value = prop->children->content;
-                        else if (prop->name == "target")
-                            target = prop->children->content;
-                        else
-                            warning ("Unknown property on <alias>, %s", prop->name);
-                    }
-
-                    if (value == null)
-                    {
-                        warning ("Ignoring <alias> with no value");
-                        continue;
-                    }
-                    if (target == null)
-                    {
-                        warning ("Ignoring <alias> with no target");
-                        continue;
-                    }
-
-                    var v = new Variant.string (target);
-                    choices.append (new SchemaChoice(value, v));
-                }
-            }
-            else if (child->type != Xml.ElementType.TEXT_NODE && child->type != Xml.ElementType.COMMENT_NODE)
-                warning ("Unknown child tag in <key>, <%s>", child->name);
-        }
-
-        //if (default_value == null)
-        //    ?
-    }
-}
-
-public class SchemaValue : GLib.Object
-{
-    public uint index;
-    public string nick;
-    public int value;
-
-    public SchemaValue(uint index, string nick, int value)
-    {
-        this.index = index;
-        this.nick = nick;
-        this.value = value;
-    }
-}
-
-public class SchemaChoice
-{
-    public string name;
-    public Variant value;
-
-    public SchemaChoice(string name, Variant value)
-    {
-        this.name = name;
-        this.value = value;
-    }
-}
-
-public class SchemaValueRange
-{
-    public Variant min;
-    public Variant max;
-
-    public SchemaValueRange.from_xml(string type, Xml.Node* node)
-    {
-        for (var prop = node->properties; prop != null; prop = prop->next)
-        {
-            if (prop->name == "min")
-            {
-                try
-                {
-                    min = Variant.parse(new VariantType(type), prop->children->content);
-                }
-                catch (VariantParseError e)
-                {
-                    // ...
-                }
-            }
-            else if (prop->name == "max")
-            {
-                try
-                {
-                    max = Variant.parse(new VariantType(type), prop->children->content);
-                }
-                catch (VariantParseError e)
-                {
-                    // ...
-                }
-            }
-            else
-                warning ("Unknown property in <range>, %s", prop->name);
-        }
-
-        //if (min == null || max == null)
-        //    ?
-    }
-}
-
-public class SchemaEnum
-{
-    public SchemaList list;
-    public string id;
-    public GLib.List<SchemaValue> values = new GLib.List<SchemaValue>();
-
-    public SchemaEnum.from_xml(SchemaList list, Xml.Node* node)
-    {
-        this.list = list;
-
-        for (var prop = node->properties; prop != null; prop = prop->next)
-        {
-            if (prop->name == "id")
-                id = prop->children->content;
-            else
-                warning ("Unknown property in <enum>, %s", prop->name);
-        }
-
-        //if (id = null)
-        //    ?
-
-        for (var child = node->children; child != null; child = child->next)
-        {
-            if (child->name == "value")
-            {
-                string? nick = null;
-                int value = -1;
-
-                for (var prop = child->properties; prop != null; prop = prop->next)
-                {
-                    if (prop->name == "value")
-                        value = int.parse(prop->children->content);
-                    else if (prop->name == "nick")
-                        nick = prop->children->content;
-                    else
-                        warning ("Unknown property in enum <value>, %s", prop->name);
-                }
-
-                //if (value < 0 || nick == null)
-                //    ?
-
-                var schema_value = new SchemaValue (values.length(), nick, value);
-                values.append(schema_value);
-            }
-            else if (child->type != Xml.ElementType.TEXT_NODE && child->type != Xml.ElementType.COMMENT_NODE)
-                warning ("Unknown tag in <enum>, <%s>", child->name);
-        }
-
-        //if (default_value == null)
-        //    ?
-    }
-}
+    public Variant default_value;
 
-public class SchemaFlags
-{
-    public SchemaList list;
-    public string id;
-    public GLib.List<SchemaValue> values = new GLib.List<SchemaValue>();
+    public string type;
+    public string range_type;
+    public Variant range_content;
 
-    public SchemaFlags.from_xml(SchemaList list, Xml.Node* node)
+    public SchemaKey (string _id, SettingsSchemaKey _settings_schema_key)
     {
-        this.list = list;
-
-        for (var prop = node->properties; prop != null; prop = prop->next)
-        {
-            if (prop->name == "id")
-                id = prop->children->content;
-            else
-                warning ("Unknown property in <flags>, %s", prop->name);
-        }
+        this.id = _id;
+        this.settings_schema_key = _settings_schema_key;
 
-        //if (id = null)
-        //    ?
+        name = settings_schema_key.get_name ();
+        summary = settings_schema_key.get_summary ();
+        description = settings_schema_key.get_description ();
+        default_value = settings_schema_key.get_default_value ();
 
-        for (var child = node->children; child != null; child = child->next)
+        range_type = settings_schema_key.get_range ().get_child_value (0).get_string ();    // don’t put it 
in the switch, or it fails
+        switch (range_type)
         {
-            if (child->name == "value")
-            {
-                string? nick = null;
-                int value = -1;
-
-                for (var prop = child->properties; prop != null; prop = prop->next)
-                {
-                    if (prop->name == "value")
-                        value = int.parse(prop->children->content);
-                    else if (prop->name == "nick")
-                        nick = prop->children->content;
-                    else
-                        warning ("Unknown property in flags <value>, %s", prop->name);
-                }
-
-                //if (value < 0 || nick == null)
-                //    ?
-
-                var schema_value = new SchemaValue (values.length(), nick, value);
-                values.append(schema_value);
-            }
-            else if (child->type != Xml.ElementType.TEXT_NODE && child->type != Xml.ElementType.COMMENT_NODE)
-                warning ("Unknown tag in <flags>, <%s>", child->name);
+            case "enum":    type = "<enum>"; break;  // <choices> or enum="", and hopefully <aliases>
+            case "flags":   type = "as";     break;  // TODO better
+            default:
+            case "type":    type = (string) settings_schema_key.get_value_type ().peek_string (); break;
         }
-
-        //if (default_value == null)
-        //    ?
+        range_content = settings_schema_key.get_range ().get_child_value (1).get_child_value (0);
     }
 }
 
-public class Schema
+public class Schema : GLib.Object
 {
-    public SchemaList list;
-    public string id;
     public string? path;
     public GLib.HashTable<string, SchemaKey> keys = new GLib.HashTable<string, SchemaKey> (str_hash, 
str_equal);
-
-    public Schema.from_xml(SchemaList list, Xml.Node* node, string? gettext_domain)
-    {
-        this.list = list;
-
-        for (var prop = node->properties; prop != null; prop = prop->next)
-        {
-            if (prop->name == "id")
-                id = prop->children->content;
-            else if (prop->name == "path")
-                path = prop->children->content; // FIXME: Does the path have to end with '/'?
-            else if (prop->name == "gettext-domain")
-                gettext_domain = prop->children->content;
-            else
-                warning ("Unknown property on <schema>, %s", prop->name);
-        }
-
-        //if (id == null)
-            //?
-
-        for (var child = node->children; child != null; child = child->next)
-        {
-            if (child->name != "key")
-               continue;
-            var key = new SchemaKey.from_xml(child, this, gettext_domain);
-            keys.insert(key.name, key);
-        }
-    }
-}
-
-public class SchemaList
-{
-    public GLib.HashTable<string, Schema> schemas = new GLib.HashTable<string, Schema>(str_hash, str_equal);
-    public GLib.HashTable<string, SchemaKey> keys = new GLib.HashTable<string, SchemaKey>(str_hash, 
str_equal);
-    public GLib.HashTable<string, SchemaEnum> enums = new GLib.HashTable<string, SchemaEnum>(str_hash, 
str_equal);
-    public GLib.HashTable<string, SchemaFlags> flags = new GLib.HashTable<string, SchemaFlags>(str_hash, 
str_equal);
-
-    public void parse_file(string path)
-    {
-        var doc = Xml.Parser.parse_file(path);
-        if (doc == null)
-            return;
-
-        var root = doc->get_root_element();
-        if (root == null)
-            return;
-        if (root->name != "schemalist")
-            return;
-
-        string? gettext_domain = null;
-        for (var prop = root->properties; prop != null; prop = prop->next)
-        {
-            if (prop->name == "gettext-domain")
-                gettext_domain = prop->children->content;
-        }
-
-        for (var node = root->children; node != null; node = node->next)
-        {
-            if (node->name == "schema")
-            {
-                var schema = new Schema.from_xml(this, node, gettext_domain);
-                if (schema.path == null)
-                {
-                    // FIXME: What to do here?
-                    continue;
-                }
-
-                foreach (var key in schema.keys.get_values())
-                {
-                    string full_name = schema.path + key.name;
-                    keys.insert(full_name, key);
-                }
-                schemas.insert(schema.id, schema);
-            }
-            else if (node->name == "enum")
-            {
-                var enum = new SchemaEnum.from_xml(this, node);
-                enums.insert(enum.id, enum);
-            }
-            else if (node->name == "flags")
-            {
-                var f = new SchemaFlags.from_xml(this, node);
-                flags.insert(f.id, f);
-            }
-            else if (node->type == Xml.ElementType.COMMENT_NODE)
-            {
-            }
-            else if (node->type != Xml.ElementType.TEXT_NODE)
-                warning ("Unknown tag <%s>", node->name);
-        }
-
-        delete doc;
-    }
-
-    public void parse_override(string path)
-    {
-        var keyfile = new KeyFile();
-        try
-        {
-            keyfile.load_from_file(path, KeyFileFlags.NONE);
-        }
-        catch (Error e)
-        {
-            warning("Failed to load override file %s: %s", path, e.message);
-            return;
-        }
-
-        foreach (var group in keyfile.get_groups())
-        {
-            var schema = schemas.lookup(group);
-            if (schema == null)
-                continue;
-
-            string[] keys;
-            try { keys = keyfile.get_keys(group); } catch (Error e) { continue; }
-
-            foreach (var key_name in keys)
-            {
-                string value;
-                try { value = keyfile.get_value(group, key_name); } catch (Error e) { continue; }
-
-                var key = schema.keys.lookup (key_name);
-                if (key == null)
-                    continue;
-
-                Variant default_value;
-                try
-                {
-                    default_value = Variant.parse(new VariantType(key.type), value);
-                }
-                catch (VariantParseError e)
-                {
-                    // ...
-                    continue;
-                }
-
-                key.default_value = default_value;
-            }
-        }
-    }
-
-    public void load_directory(string dir) throws Error
-    {
-        var directory = File.new_for_path(dir);
-
-        var i = directory.enumerate_children (FileAttribute.STANDARD_NAME, 0, null);
-        while (true)
-        {
-            var info = i.next_file (null);
-            if (info == null)
-                break;
-            var name = info.get_name();
-
-            if (name.has_suffix(".gschema.xml") || name.has_suffix(".enums.xml"))
-                parse_file(Path.build_filename(dir, name, null));
-        }
-
-        i = directory.enumerate_children (FileAttribute.STANDARD_NAME, 0, null);
-        while (true)
-        {
-            var info = i.next_file (null);
-            if (info == null)
-                break;
-            var name = info.get_name();
-
-            if (name.has_suffix(".override"))
-                parse_override(Path.build_filename(dir, name, null));
-        }
-    }
 }
diff --git a/editor/dconf-view.vala b/editor/dconf-view.vala
index 55f56f6..0ecfd3c 100644
--- a/editor/dconf-view.vala
+++ b/editor/dconf-view.vala
@@ -45,17 +45,10 @@ private class KeyEditor : Dialog
         if (this.use_header_bar == 1)        // TODO else..?
             ((HeaderBar) this.get_header_bar ()).subtitle = key.parent.full_name;       // TODO 
get_header_bar() is [transfer none]
 
-        string? gettext_domain = key.schema.gettext_domain;
-
         string summary = key.schema.summary ?? "";
-        if (gettext_domain != null && summary != "")
-            summary = dgettext (gettext_domain, summary);
-
         string description = key.schema.description ?? "";
-        if (gettext_domain != null && description != "")
-            description = dgettext (gettext_domain, description);
 
-        schema_label.set_text (key.schema.schema.id);
+        schema_label.set_text (key.schema.id);
         summary_label.set_text (summary.strip ());
         description_label.set_text (description.strip ());
         type_label.set_text (key_to_description ());
@@ -73,13 +66,10 @@ private class KeyEditor : Dialog
 
     private KeyEditorChild create_child ()
     {
-        if (key.schema.choices != null)
-            return new KeyEditorChildMulti (key);
-
         switch (key.type_string)
         {
             case "<enum>":
-                return new KeyEditorChildMulti (key);
+                return new KeyEditorChildEnum (key);
             case "b":
                 return new KeyEditorChildBool (key.value.get_boolean ());
             case "s":
@@ -111,33 +101,13 @@ private class KeyEditor : Dialog
             case "u":
             case "x":
             case "t":
-                Variant min, max;
-                if (key.schema.range != null)
-                {
-                    min = key.schema.range.min;
-                    max = key.schema.range.max;
-                }
-                else
-                {
-                    string variant_type = key.value.get_type_string ();
-                    min = Key.get_min (variant_type);
-                    max = Key.get_max (variant_type);
-                }
-                return _("Integer [%s..%s]").printf (min.print (false), max.print (false));
+                string min, max;
+                get_min_and_max (out min, out max);
+                return _("Integer [%s..%s]").printf (min, max);
             case "d":
-                Variant min, max;
-                if (key.schema.range != null)
-                {
-                    min = key.schema.range.min;
-                    max = key.schema.range.max;
-                }
-                else
-                {
-                    string variant_type = key.value.get_type_string ();
-                    min = Key.get_min (variant_type);
-                    max = Key.get_max (variant_type);
-                }
-                return _("Double [%s..%s]").printf (min.print (false), max.print (false));
+                string min, max;
+                get_min_and_max (out min, out max);
+                return _("Double [%s..%s]").printf (min, max);
             case "b":
                 return _("Boolean");
             case "s":
@@ -149,6 +119,21 @@ private class KeyEditor : Dialog
         }
     }
 
+    private 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?
+        {
+            min = key.schema.range_content.get_child_value (0).print (false);
+            max = key.schema.range_content.get_child_value (1).print (false);
+        }
+        else
+        {
+            string variant_type = key.value.get_type_string ();
+            min = Key.get_min (variant_type).print (false);
+            max = Key.get_max (variant_type).print (false);
+        }
+    }
+
     private void response_cb (Dialog dialog, int response_id)
     {
         if (response_id == ResponseType.APPLY)
@@ -171,13 +156,13 @@ public interface KeyEditorChild : Widget
     public abstract Variant get_variant ();
 }
 
-private class KeyEditorChildMulti : Grid, KeyEditorChild
+private class KeyEditorChildEnum : Grid, KeyEditorChild
 {
     private ContextPopover popover;
 
     private Variant variant;
 
-    public KeyEditorChildMulti (Key key)
+    public KeyEditorChildEnum (Key key)
     {
         this.variant = key.value;
 
@@ -276,9 +261,17 @@ private class KeyEditorChildNumber : Grid, KeyEditorChild
         label.hexpand = true;
         this.attach (label, 0, 0, 1, 1);
 
-        bool has_range = /* key.has_schema && */ key.schema.range != null;
-        double min = get_variant_as_double ((has_range && key.schema.range.min != null) ? 
key.schema.range.min : Key.get_min (key.value.get_type_string ()));
-        double max = get_variant_as_double ((has_range && key.schema.range.max != null) ? 
key.schema.range.max : Key.get_max (key.value.get_type_string ()));
+        double min, max;
+        if (key.schema.range_type == "range")       // TODO test more; and what happen if only min/max is in 
range?
+        {
+            min = get_variant_as_double (key.schema.range_content.get_child_value (0));
+            max = get_variant_as_double (key.schema.range_content.get_child_value (1));
+        }
+        else
+        {
+            min = get_variant_as_double (Key.get_min (key.value.get_type_string ()));
+            max = get_variant_as_double (Key.get_max (key.value.get_type_string ()));
+        }
 
         if (key.type_string == "d")
         {
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index 1bfd261..ae16e45 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -304,13 +304,7 @@ private class KeyListBoxRowEditable : KeyListBoxRow
         update ();      // sets key_name_label attributes and key_value_label label
         key_name_label.label = key.name;
 
-        string? summary = key.schema.summary;
-        if (summary == null || summary == "")
-            return;
-
-        string? gettext_domain = key.schema.gettext_domain;
-        if (gettext_domain != null)
-            summary = dgettext (gettext_domain, summary);
+        string summary = key.schema.summary ?? "";
         key_info_label.label = summary.strip ();
 
         key.value_changed.connect (() => { update (); if (popover != null) popover.destroy (); });
@@ -322,11 +316,11 @@ private class KeyListBoxRowEditable : KeyListBoxRow
         popover.add_action_button (_("Customize…"), () => { show_dialog (); });
         popover.add_action_button (_("Copy"), () => {
                 Clipboard clipboard = Clipboard.get_default (Gdk.Display.get_default ());
-                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);
             });
 
-        if (key.type_string == "b" || key.type_string == "<enum>" || key.schema.choices != null)
+        if (key.type_string == "b" || key.type_string == "<enum>")
         {
             popover.add_separator ();
             popover.create_buttons_list (key, true);
@@ -407,29 +401,20 @@ private class ContextPopover : Popover
         if (nullable)
             add_model_button (_("Default value"), new Variant.maybe (original_type, null));
 
-        if (key.schema.choices != null)
-        {
-            foreach (SchemaChoice choice in key.schema.choices)
-                add_model_button (choice.name, new Variant.maybe (original_type, choice.value));
-        }
-        else if (key.type_string == "b")
+        if (key.type_string == "b")
         {
             add_model_button (_("True"), new Variant.maybe (original_type, new Variant.boolean (true)));     
   // TODO string duplication
             add_model_button (_("False"), new Variant.maybe (original_type, new Variant.boolean (false)));   
   // TODO string duplication
         }
         else if (key.type_string == "<enum>")
         {
-            SchemaEnum schema_enum = key.schema.schema.list.enums.lookup (key.schema.enum_name);
-            if (schema_enum.values.length () <= 0)
-                assert_not_reached ();  // TODO special case 0?
-    //        else if (schema_enum.values.length () == 1)
-    //            assert_not_reached ();  // TODO
-
-            for (uint index = 0; index < schema_enum.values.length (); index++)
-            {
-                string nick = schema_enum.values.nth_data (index).nick;
-                add_model_button (nick, new Variant.maybe (VariantType.STRING, new Variant.string (nick)));  
   // FIXME in internals, it’s an int!
-            }
+            Variant range = key.schema.range_content;
+            uint size = (uint) range.n_children ();
+            if (size == 0)      // TODO special case also 1?
+                assert_not_reached ();
+            VariantType type = range.get_child_value (0).get_type ();
+            for (uint index = 0; index < size; index++)
+                add_model_button (range.get_child_value (index).print (false), new Variant.maybe (type, 
range.get_child_value (index)));
         }
 
         group.action_state_changed [ACTION_NAME].connect ((unknown_string, tmp_variant) => {


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