[dconf-editor] Hacky support of the "mb" type.
- From: Arnaud Bonatti <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dconf-editor] Hacky support of the "mb" type.
- Date: Thu, 8 Oct 2015 21:29:40 +0000 (UTC)
commit 18891900ce0ac2a03cd18479d0437515c4c23fde
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Thu Oct 8 23:29:13 2015 +0200
Hacky support of the "mb" type.
editor/dconf-view.vala | 87 ++++++++++++++++++++++++++++++++++++---------
editor/dconf-window.vala | 47 ++++++++++++++-----------
2 files changed, 95 insertions(+), 39 deletions(-)
---
diff --git a/editor/dconf-view.vala b/editor/dconf-view.vala
index 89d7c0c..390ad47 100644
--- a/editor/dconf-view.vala
+++ b/editor/dconf-view.vala
@@ -65,6 +65,11 @@ private abstract class KeyEditorDialog : Dialog
key_editor_child.child_activated.connect (response_apply_cb);
custom_value_grid.add (_key_editor_child);
return;
+ case "mb":
+ KeyEditorChildNullableBool _key_editor_child = new KeyEditorChildNullableBool (key);
+ key_editor_child = (KeyEditorChild) _key_editor_child;
+ custom_value_grid.add (_key_editor_child);
+ return;
default:
KeyEditorChildDefault _key_editor_child = new KeyEditorChildDefault (key.type_string,
key.value);
_key_editor_child.is_valid.connect ((is_valid) => { custom_value_is_valid = is_valid; });
@@ -226,12 +231,19 @@ public interface KeyEditorChild : Widget
{
public abstract Variant get_variant ();
public signal void child_activated ();
+
+ protected Label new_label_custom_value () // not used by String & Default
+ {
+ Label label = new Label (_("Custom Value"));
+ label.visible = true;
+ label.halign = Align.START;
+ label.hexpand = true;
+ return label;
+ }
}
private class KeyEditorChildEnum : Grid, KeyEditorChild
{
- private ContextPopover popover;
-
private Variant variant;
public KeyEditorChildEnum (Key key)
@@ -241,11 +253,7 @@ private class KeyEditorChildEnum : Grid, KeyEditorChild
this.visible = true;
this.hexpand = true;
- Label label = new Label (_("Custom Value"));
- label.visible = true;
- label.halign = Align.START;
- label.hexpand = true;
- this.attach (label, 0, 0, 1, 1);
+ this.attach (new_label_custom_value (), 0, 0, 1, 1);
MenuButton button = new MenuButton ();
button.visible = true;
@@ -255,7 +263,7 @@ private class KeyEditorChildEnum : Grid, KeyEditorChild
button.label = variant.get_type () == VariantType.STRING ? variant.get_string () : variant.print
(false);
this.attach (button, 1, 0, 1, 1);
- popover = new ContextPopover ();
+ ContextPopover popover = new ContextPopover ();
popover.create_buttons_list (key, false);
popover.set_relative_to (button);
popover.value_changed.connect ((bytes) => {
@@ -272,6 +280,57 @@ private class KeyEditorChildEnum : Grid, KeyEditorChild
}
}
+private class KeyEditorChildNullableBool : Grid, KeyEditorChild
+{
+ private Variant variant;
+
+ public KeyEditorChildNullableBool (Key key)
+ {
+ this.variant = key.value;
+ Variant? maybe_variant = variant.get_maybe ();
+
+ this.visible = true;
+ this.hexpand = true;
+
+ this.attach (new_label_custom_value (), 0, 0, 1, 1);
+
+ MenuButton button = new MenuButton ();
+ button.visible = true;
+ button.use_popover = true;
+ button.halign = Align.END;
+ button.width_request = 100;
+ if (maybe_variant == null)
+ button.label = Key.cool_boolean_text_value (null);
+ else
+ button.label = Key.cool_boolean_text_value (maybe_variant.get_boolean ());
+ this.attach (button, 1, 0, 1, 1);
+
+ ContextPopover popover = new ContextPopover ();
+ popover.create_buttons_list (key, false);
+ popover.set_relative_to (button);
+ popover.value_changed.connect ((bytes) => {
+ if (bytes == null)
+ {
+ variant = new Variant.maybe (VariantType.BOOLEAN, null);
+ button.label = Key.cool_boolean_text_value (null);
+ }
+ else
+ {
+ variant = new Variant.from_bytes (key.value.get_type (), bytes, true);
+ maybe_variant = variant.get_maybe ();
+ button.label = Key.cool_boolean_text_value (maybe_variant.get_boolean ());
+ }
+ popover.closed ();
+ });
+ button.set_popover ((Popover) popover);
+ }
+
+ public Variant get_variant ()
+ {
+ return variant;
+ }
+}
+
private class KeyEditorChildBool : Grid, KeyEditorChild // might be managed by action, but can't find a way
to ensure one-and-only-one button is active
{
private ToggleButton button_true;
@@ -281,11 +340,7 @@ private class KeyEditorChildBool : Grid, KeyEditorChild // might be managed by a
this.visible = true;
this.hexpand = true;
- Label label = new Label (_("Custom Value"));
- label.visible = true;
- label.halign = Align.START;
- label.hexpand = true;
- this.attach (label, 0, 0, 1, 1);
+ this.attach (new_label_custom_value (), 0, 0, 1, 1);
Grid grid = new Grid ();
grid.visible = true;
@@ -327,11 +382,7 @@ private class KeyEditorChildNumber : Grid, KeyEditorChild
this.visible = true;
this.hexpand = true;
- Label label = new Label (_("Custom Value"));
- label.visible = true;
- label.halign = Align.START;
- label.hexpand = true;
- this.attach (label, 0, 0, 1, 1);
+ this.attach (new_label_custom_value (), 0, 0, 1, 1);
double min, max;
if (key.has_schema && key.schema.range_type == "range") // TODO test more; and what happen if
only min/max is in range?
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index eed0acf..c39ef5a 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -317,12 +317,12 @@ private class KeyListBoxRowEditableNoSchema : KeyListBoxRow
clipboard.set_text (copy, copy.length);
});
- if (key.type_string == "b")
+ if (key.type_string == "b" || key.type_string == "mb")
{
popover.add_separator ();
popover.create_buttons_list (key, false);
- popover.value_changed.connect ((bytes) => { key.value = new Variant.from_bytes
(key.value.get_type (), bytes, true); popover.destroy (); });
+ popover.value_changed.connect ((bytes) => { key.value = bytes == null ? new Variant.maybe
(VariantType.BOOLEAN, null) : new Variant.from_bytes (key.value.get_type (), bytes, true); popover.destroy
(); });
}
return true;
}
@@ -358,13 +358,13 @@ private class KeyListBoxRowEditable : KeyListBoxRow
clipboard.set_text (copy, copy.length);
});
- if (key.type_string == "b" || key.type_string == "<enum>")
+ if (key.type_string == "b" || key.type_string == "<enum>" || key.type_string == "mb")
{
popover.add_separator ();
popover.create_buttons_list (key, true);
popover.set_to_default.connect (() => { key.set_to_default (); popover.destroy (); });
- popover.value_changed.connect ((bytes) => { key.value = new Variant.from_bytes
(key.value.get_type (), bytes, true); popover.destroy (); });
+ popover.value_changed.connect ((bytes) => { key.value = bytes == null ? new Variant.maybe
(VariantType.BOOLEAN, null) : new Variant.from_bytes (key.value.get_type (), bytes, true); popover.destroy
(); });
}
else if (!key.is_default)
{
@@ -387,7 +387,7 @@ private class KeyListBoxRowEditable : KeyListBoxRow
private class ContextPopover : Popover
{
public signal void set_to_default ();
- public signal void value_changed (Bytes bytes);
+ public signal void value_changed (Bytes? bytes);
private static const string ACTION_NAME = "key_value";
private static const string GROUP_PREFIX = "group";
@@ -426,9 +426,6 @@ private class ContextPopover : Popover
public void create_buttons_list (Key key, bool nullable)
{
- if ("m" in key.value.get_type_string ()) // TODO better; is it really needed? ("mmmb"?)
- assert_not_reached ();
-
VariantType original_type = key.value.get_type ();
VariantType nullable_type = new VariantType.maybe (original_type);
Variant variant = new Variant.maybe (original_type, key.is_default ? null : key.value);
@@ -441,26 +438,34 @@ private class ContextPopover : Popover
if (nullable)
add_model_button (_("Default value"), new Variant.maybe (original_type, null));
- if (key.type_string == "b")
- {
- add_model_button (Key.cool_boolean_text_value (true), new Variant.maybe (original_type, new
Variant.boolean (true)));
- add_model_button (Key.cool_boolean_text_value (false), new Variant.maybe (original_type, new
Variant.boolean (false)));
- }
- else if (key.type_string == "<enum>")
+ switch (key.type_string)
{
- 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)));
+ case "b":
+ add_model_button (Key.cool_boolean_text_value (true), new Variant.maybe
(VariantType.BOOLEAN, new Variant.boolean (true)));
+ add_model_button (Key.cool_boolean_text_value (false), new Variant.maybe
(VariantType.BOOLEAN, new Variant.boolean (false)));
+ break;
+ case "<enum>":
+ 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)));
+ break;
+ case "mb":
+ add_model_button (Key.cool_boolean_text_value (null), new Variant.maybe (original_type, new
Variant.maybe (VariantType.BOOLEAN, null)));
+ add_model_button (Key.cool_boolean_text_value (true), new Variant.maybe (original_type, new
Variant.maybe (VariantType.BOOLEAN, new Variant.boolean (true))));
+ add_model_button (Key.cool_boolean_text_value (false), new Variant.maybe (original_type, new
Variant.maybe (VariantType.BOOLEAN, new Variant.boolean (false))));
+ break;
}
group.action_state_changed [ACTION_NAME].connect ((unknown_string, tmp_variant) => {
Variant? new_variant = tmp_variant.get_maybe ();
if (new_variant == null)
set_to_default ();
+ else if (new_variant.get_data () == null)
+ value_changed (null);
else
value_changed (new_variant.get_data_as_bytes ());
});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]