[dconf-editor] Introduce KeyEditorChildEnumSingle.
- From: Arnaud Bonatti <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dconf-editor] Introduce KeyEditorChildEnumSingle.
- Date: Sat, 13 Aug 2016 16:31:55 +0000 (UTC)
commit 711db65bb68faf88d05d7157bd11fd5ad7e639dc
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Sat Aug 13 18:29:45 2016 +0200
Introduce KeyEditorChildEnumSingle.
editor/ca.desrt.dconf-editor.gschema.xml | 8 ++++++++
editor/dconf-view.vala | 19 +++++++++++++++++++
editor/key-list-box-row.vala | 2 +-
editor/registry-info.ui | 26 ++++++++++++++++++++++++++
editor/registry-info.vala | 9 ++++++++-
5 files changed, 62 insertions(+), 2 deletions(-)
---
diff --git a/editor/ca.desrt.dconf-editor.gschema.xml b/editor/ca.desrt.dconf-editor.gschema.xml
index f9c8d02..0071b49 100644
--- a/editor/ca.desrt.dconf-editor.gschema.xml
+++ b/editor/ca.desrt.dconf-editor.gschema.xml
@@ -83,6 +83,9 @@
<value value="8" nick="Yellow"/>
<value value="1" nick="Green"/>
</flags>
+ <enum id="ca.desrt.dconf-editor.DemoWeirdEnum">
+ <value value="0" nick="only-choice"/>
+ </enum>
<schema id="ca.desrt.dconf-editor.Demo" path="/ca/desrt/dconf-editor/demo/">
<key name="boolean" type="b">
<default>true</default>
@@ -209,5 +212,10 @@ If you are not interacting with D-Bus, then there is no reason to make use of th
<summary>A nullable string, type "ms"</summary>
<description>GSettings allows nullable types, that are similar to other types but could take a
"nothing" value. A nullable string can take any string as value, including the empty string "''", or can be
NULL (nothing).</description>
</key>
+ <key name="weird-enum" enum="ca.desrt.dconf-editor.DemoWeirdEnum">
+ <default>'only-choice'</default>
+ <summary>A 1-choice enumeration</summary>
+ <description>An enumeration could contain only one item, but that's probably an error. Dconf Editor
warns you in that case.</description>
+ </key>
</schema>
</schemalist>
diff --git a/editor/dconf-view.vala b/editor/dconf-view.vala
index 2e8aa70..cb7872f 100644
--- a/editor/dconf-view.vala
+++ b/editor/dconf-view.vala
@@ -27,6 +27,25 @@ public interface KeyEditorChild : Widget
public abstract void reload (Variant gvariant);
}
+private class KeyEditorChildEnumSingle : Label, KeyEditorChild
+{
+ private Variant variant;
+
+ public KeyEditorChildEnumSingle (Variant key_value)
+ {
+ variant = key_value;
+ set_label (key_value.get_string ());
+ show ();
+ }
+
+ public Variant get_variant ()
+ {
+ return variant;
+ }
+
+ public void reload (Variant gvariant) {}
+}
+
private class KeyEditorChildEnum : MenuButton, KeyEditorChild
{
private Variant variant;
diff --git a/editor/key-list-box-row.vala b/editor/key-list-box-row.vala
index dba517f..f207646 100644
--- a/editor/key-list-box-row.vala
+++ b/editor/key-list-box-row.vala
@@ -534,7 +534,7 @@ private class ContextPopover : Popover
case "<enum>": // defined by the schema
Variant range = ((GSettingsKey) key).range_content;
uint size = (uint) range.n_children ();
- if (size == 0) // TODO special case also 1?
+ if (size == 0 || (size == 1 && !has_default_value))
assert_not_reached ();
for (uint index = 0; index < size; index++)
current_section.append (range.get_child_value (index).print (false),
@"$group_dot_action(@mms '" + range.get_child_value (index).get_string () + "')"); // TODO use int
settings.get_enum ()
diff --git a/editor/registry-info.ui b/editor/registry-info.ui
index 01751b1..93c7cc7 100644
--- a/editor/registry-info.ui
+++ b/editor/registry-info.ui
@@ -39,6 +39,32 @@
</object>
</child>
<child>
+ <object class="GtkRevealer" id="one_choice_enum_warning">
+ <property name="visible">True</property>
+ <property name="reveal-child">False</property>
+ <child>
+ <object class="GtkInfoBar">
+ <property name="visible">True</property>
+ <property name="message-type">warning</property>
+ <child internal-child="content_area">
+ <object class="GtkBox">
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="hexpand">True</property>
+ <property name="max-width-chars">40</property>
+ <property name="use-markup">True</property>
+ <property name="wrap">True</property>
+ <property name="label" translatable="yes"><b>This enumeration offers only one
choice.</b> That's probably an error of the application that installed this schema. If possible,
please open a bug about it.</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<child>
diff --git a/editor/registry-info.vala b/editor/registry-info.vala
index df6ee42..a939ac3 100644
--- a/editor/registry-info.vala
+++ b/editor/registry-info.vala
@@ -21,6 +21,7 @@ using Gtk;
class RegistryInfo : Grid
{
[GtkChild] private Revealer no_schema_warning;
+ [GtkChild] private Revealer one_choice_enum_warning;
[GtkChild] private ListBox properties_list_box;
[GtkChild] private Button erase_button;
@@ -110,6 +111,7 @@ class RegistryInfo : Grid
add_separator ();
KeyEditorChild key_editor_child = create_child (key);
+ one_choice_enum_warning.set_reveal_child (key_editor_child is KeyEditorChildEnumSingle);
ulong value_has_changed_handler = key_editor_child.value_has_changed.connect ((is_valid) => {
if (revealer.should_delay_apply (tmp_string))
@@ -201,7 +203,12 @@ class RegistryInfo : Grid
switch (key.type_string)
{
case "<enum>":
- return (KeyEditorChild) new KeyEditorChildEnum (key);
+ switch (((GSettingsKey) key).range_content.n_children ())
+ {
+ case 0: assert_not_reached ();
+ case 1: return (KeyEditorChild) new KeyEditorChildEnumSingle (key.value);
+ default: return (KeyEditorChild) new KeyEditorChildEnum (key);
+ }
case "<flags>":
return (KeyEditorChild) new KeyEditorChildFlags ((GSettingsKey) key);
case "b":
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]