[dconf] editor: Support changing of choices
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dconf] editor: Support changing of choices
- Date: Tue, 15 Mar 2011 01:56:00 +0000 (UTC)
commit f13345d4631da443958f5364bd1eabe08ff9d00b
Author: Robert Ancell <robert ancell canonical com>
Date: Tue Mar 15 12:55:53 2011 +1100
editor: Support changing of choices
editor/dconf-schema.vala | 33 +++++++++++++++++++++++++++++----
editor/dconf-view.vala | 21 ++++++++++++++++++++-
2 files changed, 49 insertions(+), 5 deletions(-)
---
diff --git a/editor/dconf-schema.vala b/editor/dconf-schema.vala
index 8f3a70d..b074223 100644
--- a/editor/dconf-schema.vala
+++ b/editor/dconf-schema.vala
@@ -6,7 +6,7 @@ public class SchemaKey
public Variant default_value;
public SchemaValueRange? range;
public SchemaValueRange type_range;
- public List<Variant> choices;
+ public List<SchemaChoice> choices;
public string? enum_name;
public string? summary;
public string? description;
@@ -58,6 +58,8 @@ public class SchemaKey
{
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);
@@ -82,8 +84,8 @@ public class SchemaKey
Variant v;
try
{
- v = Variant.parse(new VariantType(type), value);
- choices.append (v);
+ v = new Variant(type, value);
+ choices.append (new SchemaChoice(value, v));
}
catch (VariantParseError e)
{
@@ -95,6 +97,8 @@ public class SchemaKey
{
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);
@@ -123,7 +127,16 @@ public class SchemaKey
continue;
}
- // FIXME: Use it
+ Variant v;
+ try
+ {
+ v = new Variant(type, target);
+ choices.append (new SchemaChoice(value, v));
+ }
+ catch (VariantParseError e)
+ {
+ warning ("Invalid alias value '%s'", target);
+ }
}
}
else if (child->type != Xml.ElementType.TEXT_NODE && child->type != Xml.ElementType.COMMENT_NODE)
@@ -151,6 +164,18 @@ public class SchemaEnumValue : GLib.Object
}
}
+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;
diff --git a/editor/dconf-view.vala b/editor/dconf-view.vala
index 1725af1..2c57385 100644
--- a/editor/dconf-view.vala
+++ b/editor/dconf-view.vala
@@ -13,6 +13,22 @@ private class KeyValueRenderer: Gtk.CellRenderer
set
{
_key = value;
+
+ if (key.has_schema && key.schema.choices != null)
+ {
+ combo_renderer.text = key.value.print(false);
+ var model = new Gtk.ListStore(2, typeof(string), typeof(string));
+ foreach (var choice in key.schema.choices)
+ {
+ Gtk.TreeIter iter;
+ model.append(out iter);
+ model.set(iter, 0, choice.name, 1, choice.value.print(false), -1);
+ }
+ combo_renderer.model = model;
+ mode = Gtk.CellRendererMode.EDITABLE;
+ return;
+ }
+
switch (key.type_string)
{
case "<enum>":
@@ -39,7 +55,7 @@ private class KeyValueRenderer: Gtk.CellRenderer
spin_renderer.text = key.value.print(false);
var v = get_variant_as_double(key.value);
double min = 0.0, max = 0.0;
- if (key.schema != null && key.schema.range != null)
+ if (key.has_schema && key.schema.range != null)
{
min = get_variant_as_double(key.schema.range.min);
max = get_variant_as_double(key.schema.range.max);
@@ -118,6 +134,9 @@ private class KeyValueRenderer: Gtk.CellRenderer
set {}
get
{
+ if (key.has_schema && key.schema.choices != null)
+ return combo_renderer;
+
switch (key.type_string)
{
case "<enum>":
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]