[dconf-editor] Better support of string-based values.
- From: Arnaud Bonatti <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dconf-editor] Better support of string-based values.
- Date: Fri, 20 May 2016 04:42:59 +0000 (UTC)
commit 1167ddd26e079395b378f06442a42107b26f1b17
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Fri May 20 06:42:35 2016 +0200
Better support of string-based values.
editor/dconf-view.vala | 63 ++++++++++++++++++++++++---------------------
editor/dconf-window.vala | 41 ++++++++++++++---------------
2 files changed, 54 insertions(+), 50 deletions(-)
---
diff --git a/editor/dconf-view.vala b/editor/dconf-view.vala
index 9a38ad2..20b1be3 100644
--- a/editor/dconf-view.vala
+++ b/editor/dconf-view.vala
@@ -99,7 +99,7 @@ private class KeyEditor : Dialog
private static Widget? add_warning (string type)
{
- if (type != "<flags>" && (("s" in type && type != "s") || "g" in type) || "o" in type)
+ if (type != "<flags>" && ((type != "s" && "s" in type) || (type != "g" && "g" in type)) || (type !=
"o" && "o" in type))
{
if ("m" in type)
/* Translators: neither the "nothing" keyword nor the "m" type should be translated; a
"maybe type" is a type of variant that is nullable. */
@@ -107,7 +107,7 @@ private class KeyEditor : Dialog
else
return warning_label (_("Strings, signatures and object paths should be surrounded by
quotation marks."));
}
- else if ("m" in type && type != "m" && type != "mb" && type != "<enum>")
+ else if (type != "m" && type != "mb" && type != "<enum>" && "m" in type)
/* Translators: neither the "nothing" keyword nor the "m" type should be translated; a "maybe
type" is a type of variant that is nullable. */
return warning_label (_("Use the keyword “nothing” to set a maybe type (beginning with “m”) to
its empty value."));
return null;
@@ -126,6 +126,8 @@ private class KeyEditor : Dialog
public interface KeyEditorChild : Widget
{
+ public signal void value_has_changed (bool is_valid);
+
public abstract Variant get_variant ();
public signal void child_activated ();
}
@@ -135,6 +137,7 @@ private class KeyEditorChildEnum : MenuButton, KeyEditorChild
private Variant variant;
public KeyEditorChildEnum (Key key)
+ requires (key.type_string == "<enum>")
{
this.variant = key.value;
@@ -152,6 +155,8 @@ private class KeyEditorChildEnum : MenuButton, KeyEditorChild
variant = gvariant;
this.label = gvariant.get_type () == VariantType.STRING ? gvariant.get_string () :
gvariant.print (false);
popover.closed ();
+
+ value_has_changed (true);
});
this.set_popover ((Popover) popover);
}
@@ -167,6 +172,7 @@ private class KeyEditorChildFlags : Grid, KeyEditorChild
private Variant variant;
public KeyEditorChildFlags (GSettingsKey key)
+ requires (key.type_string == "<flags>")
{
this.variant = key.value;
@@ -192,6 +198,8 @@ private class KeyEditorChildFlags : Grid, KeyEditorChild
popover.value_changed.connect ((gvariant) => {
variant = gvariant;
label.label = gvariant.print (false);
+
+ value_has_changed (true);
});
button.set_popover ((Popover) popover);
}
@@ -207,6 +215,7 @@ private class KeyEditorChildNullableBool : MenuButton, KeyEditorChild
private Variant variant;
public KeyEditorChildNullableBool (Key key)
+ requires (key.type_string == "mb")
{
this.variant = key.value;
Variant? maybe_variant = variant.get_maybe ();
@@ -232,6 +241,8 @@ private class KeyEditorChildNullableBool : MenuButton, KeyEditorChild
else
this.label = Key.cool_boolean_text_value (((!) maybe_variant).get_boolean ());
popover.closed ();
+
+ value_has_changed (true);
});
this.set_popover ((Popover) popover);
}
@@ -267,6 +278,8 @@ private class KeyEditorChildBool : Grid, KeyEditorChild // might be managed by a
button_true.active = initial_value;
button_true.bind_property ("active", button_false, "active",
BindingFlags.INVERT_BOOLEAN|BindingFlags.SYNC_CREATE|BindingFlags.BIDIRECTIONAL);
+
+ button_true.toggled.connect (() => { value_has_changed (true); });
}
public Variant get_variant ()
@@ -275,11 +288,12 @@ private class KeyEditorChildBool : Grid, KeyEditorChild // might be managed by a
}
}
-private class KeyEditorChildNumber : SpinButton, KeyEditorChild // TODO check for correctness of entry
value
+private class KeyEditorChildNumber : SpinButton, KeyEditorChild
{
private string key_type;
public KeyEditorChildNumber (Key key)
+ requires (key.type_string == "y" || key.type_string == "n" || key.type_string == "q" ||
key.type_string == "i" || key.type_string == "u" || key.type_string == "d" || key.type_string == "h")
{
this.key_type = key.type_string;
@@ -311,7 +325,10 @@ private class KeyEditorChildNumber : SpinButton, KeyEditorChild // TODO chec
this.snap_to_ticks = true;
this.input_purpose = InputPurpose.NUMBER; // TODO spin.input_purpose = InputPurpose.DIGITS &
spin.numeric = true; (no “e”) if not double?
this.width_chars = 30;
- this.activate.connect (() => { child_activated (); });
+
+ this.buffer.deleted_text.connect (() => { value_has_changed (true); }); // TODO test value for
+ this.buffer.inserted_text.connect (() => { value_has_changed (true); }); // non-numeric chars
+ this.activate.connect (() => { update (); child_activated (); });
}
private static void get_min_and_max_double (out double min, out double max, string variant_type)
@@ -360,29 +377,11 @@ private class KeyEditorChildNumber : SpinButton, KeyEditorChild // TODO chec
}
}
-private class KeyEditorChildString : Entry, KeyEditorChild
-{
- public KeyEditorChildString (string _text)
- {
- this.visible = true;
- this.hexpand = true;
- this.text = _text;
-
- this.activate.connect (() => { child_activated (); });
- }
-
- public Variant get_variant ()
- {
- return new Variant.string (this.text);
- }
-}
-
private class KeyEditorChildDefault : Entry, KeyEditorChild
{
- public signal void is_valid (bool is_valid);
-
private string variant_type;
private Variant variant;
+ private bool is_string;
public KeyEditorChildDefault (string type, Variant initial_value)
{
@@ -391,21 +390,27 @@ private class KeyEditorChildDefault : Entry, KeyEditorChild
this.visible = true;
this.hexpand = true;
- this.text = initial_value.print (false);
- this.buffer.deleted_text.connect (emit_is_valid);
- this.buffer.inserted_text.connect (emit_is_valid);
- emit_is_valid ();
+ this.is_string = type == "s" || type == "o" || type == "g";
+ this.text = is_string ? initial_value.get_string () : initial_value.print (false);
+ this.buffer.deleted_text.connect (() => { value_has_changed (test_value ()); });
+ this.buffer.inserted_text.connect (() => { value_has_changed (test_value ()); });
this.activate.connect (() => { if (test_value ()) child_activated (); });
+ value_has_changed (test_value ());
}
- private void emit_is_valid () { is_valid (test_value ()); }
private bool test_value ()
{
+ if (variant_type == "s")
+ {
+ variant = new Variant.string (this.text);
+ return true;
+ }
try
{
- Variant? tmp_variant = Variant.parse (new VariantType (variant_type), this.text);
+ string tmp_text = is_string ? @"'$text'" : this.text;
+ Variant? tmp_variant = Variant.parse (new VariantType (variant_type), tmp_text);
variant = (!) tmp_variant;
return true;
}
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index 993a70c..8c3f5b4 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -277,7 +277,7 @@ class DConfWindow : ApplicationWindow
if (!dict.lookup ("type-code", "s", out tmp_string)) assert_not_reached ();
- Widget key_editor_child = create_child (key_editor, key);
+ KeyEditorChild key_editor_child = create_child (key_editor, key);
if (has_schema)
{
Switch custom_value_switch = new Switch ();
@@ -291,14 +291,17 @@ class DConfWindow : ApplicationWindow
GSettingsKey gkey = (GSettingsKey) key;
custom_value_switch.set_active (gkey.is_default);
- custom_value_switch.notify ["active"].connect (() => { key_editor.switch_is_active
(custom_value_switch.get_active ()); });
+ custom_value_switch.notify ["active"].connect (() => {
+ bool is_active = custom_value_switch.get_active ();
+ key_editor.switch_is_active (is_active);
+ });
key_editor.response.connect ((dialog, response_id) => {
if (response_id == ResponseType.APPLY)
{
if (!custom_value_switch.active)
{
- Variant variant = ((KeyEditorChild) key_editor_child).get_variant ();
+ Variant variant = key_editor_child.get_variant ();
if (key.value != variant)
key.value = variant;
}
@@ -313,33 +316,34 @@ class DConfWindow : ApplicationWindow
key_editor.response.connect ((dialog, response_id) => {
if (response_id == ResponseType.APPLY)
{
- Variant variant = ((KeyEditorChild) key_editor_child).get_variant ();
+ Variant variant = key_editor_child.get_variant ();
if (key.value != variant)
key.value = variant;
}
dialog.destroy ();
});
}
+ key_editor_child.value_has_changed.connect ((is_valid) => { key_editor.custom_value_is_valid =
is_valid; }); // TODO not always useful
+ key_editor_child.child_activated.connect (() => { // TODO "only" used for string-based and
spin widgets
+ if (key_editor.custom_value_is_valid)
+ key_editor.response (ResponseType.APPLY);
+ });
key_editor.add_row_from_widget (_("Custom value"), key_editor_child, tmp_string);
key_editor.set_transient_for (this);
key_editor.run ();
}
- private static Widget create_child (KeyEditor dialog, Key key)
+ private static KeyEditorChild create_child (KeyEditor dialog, Key key)
{
switch (key.type_string)
{
case "<enum>":
- return (Widget) new KeyEditorChildEnum (key);
+ return (KeyEditorChild) new KeyEditorChildEnum (key);
case "<flags>":
- return (Widget) new KeyEditorChildFlags ((GSettingsKey) key);
+ return (KeyEditorChild) new KeyEditorChildFlags ((GSettingsKey) key);
case "b":
- return (Widget) new KeyEditorChildBool (key.value.get_boolean ());
- case "s":
- KeyEditorChildString key_editor_child = new KeyEditorChildString (key.value.get_string ());
- key_editor_child.child_activated.connect (() => { dialog.response (ResponseType.APPLY); });
- return (Widget) key_editor_child;
+ return (KeyEditorChild) new KeyEditorChildBool (key.value.get_boolean ());
case "y":
case "n":
case "q":
@@ -347,16 +351,11 @@ class DConfWindow : ApplicationWindow
case "u":
case "d":
case "h": // TODO "x" and "t" are not working in spinbuttons (double-based)
- KeyEditorChildNumber key_editor_child = new KeyEditorChildNumber (key);
- key_editor_child.child_activated.connect (() => { dialog.response (ResponseType.APPLY); });
- return (Widget) key_editor_child;
+ return (KeyEditorChild) new KeyEditorChildNumber (key);
case "mb":
- return (Widget) new KeyEditorChildNullableBool (key);
- default: // TODO "o" is a string-only with syntax verification
- KeyEditorChildDefault key_editor_child = new KeyEditorChildDefault (key.type_string,
key.value);
- key_editor_child.is_valid.connect ((is_valid) => { dialog.custom_value_is_valid = is_valid;
});
- key_editor_child.child_activated.connect (() => { dialog.response (ResponseType.APPLY); });
- return (Widget) key_editor_child;
+ return (KeyEditorChild) new KeyEditorChildNullableBool (key);
+ default:
+ return (KeyEditorChild) new KeyEditorChildDefault (key.type_string, key.value);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]