[dconf-editor] Add 'weird-range' demo.



commit 11d90c988d97dc913e7f770fc05a18c6e5812d86
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Thu Jan 26 18:04:52 2017 +0100

    Add 'weird-range' demo.

 editor/ca.desrt.dconf-editor.gschema.xml |    6 ++++
 editor/dconf-view.vala                   |    6 ++--
 editor/registry-info.ui                  |   13 +++++++-
 editor/registry-info.vala                |   44 +++++++++++++++++++++++------
 4 files changed, 55 insertions(+), 14 deletions(-)
---
diff --git a/editor/ca.desrt.dconf-editor.gschema.xml b/editor/ca.desrt.dconf-editor.gschema.xml
index ba53509..f5feeb5 100644
--- a/editor/ca.desrt.dconf-editor.gschema.xml
+++ b/editor/ca.desrt.dconf-editor.gschema.xml
@@ -217,5 +217,11 @@ If you are not interacting with D-Bus, then there is no reason to make use of th
       <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>
+    <key name="weird-range" type="i">
+      <default>5</default>
+      <range min="5" max="5"/>
+      <summary>A 1-choice integer value</summary>
+      <description>A range could limit an integer key to only allow one value, 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 a3827c2..e5e7d0c 100644
--- a/editor/dconf-view.vala
+++ b/editor/dconf-view.vala
@@ -27,14 +27,14 @@ public interface KeyEditorChild : Widget
     public abstract void reload (Variant gvariant);
 }
 
-private class KeyEditorChildEnumSingle : Label, KeyEditorChild
+private class KeyEditorChildSingle : Label, KeyEditorChild
 {
     private Variant variant;
 
-    public KeyEditorChildEnumSingle (Variant key_value)
+    public KeyEditorChildSingle (Variant key_value, string text)
     {
         variant = key_value;
-        set_label (key_value.get_string ());
+        set_label (text);
         show ();
     }
 
diff --git a/editor/registry-info.ui b/editor/registry-info.ui
index 8f583b8..16e7245 100644
--- a/editor/registry-info.ui
+++ b/editor/registry-info.ui
@@ -38,7 +38,7 @@
       </object>
     </child>
     <child>
-      <object class="GtkRevealer" id="one_choice_enum_warning">
+      <object class="GtkRevealer" id="one_choice_warning_revealer">
         <property name="visible">True</property>
         <property name="reveal-child">False</property>
         <child>
@@ -48,7 +48,7 @@
             <child internal-child="content_area">
               <object class="GtkBox">
                 <child>
-                  <object class="GtkLabel">
+                  <object class="GtkLabel" id="one_choice_enum_warning">
                     <property name="visible">True</property>
                     <property name="hexpand">True</property>
                     <property name="max-width-chars">40</property>
@@ -56,6 +56,15 @@
                     <property name="label" translatable="yes">This enumeration offers only one choice. 
That’s probably an error of the application that installed this schema. If possible, please open a bug about 
it.</property>
                   </object>
                 </child>
+                <child>
+                  <object class="GtkLabel" id="one_choice_integer_warning">
+                    <property name="visible">True</property>
+                    <property name="hexpand">True</property>
+                    <property name="max-width-chars">40</property>
+                    <property name="wrap">True</property>
+                    <property name="label" translatable="yes">This integer key can only take one value. 
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>
diff --git a/editor/registry-info.vala b/editor/registry-info.vala
index 8530a66..c5cfafe 100644
--- a/editor/registry-info.vala
+++ b/editor/registry-info.vala
@@ -21,7 +21,9 @@ using Gtk;
 class RegistryInfo : Grid
 {
     [GtkChild] private Revealer no_schema_warning;
-    [GtkChild] private Revealer one_choice_enum_warning;
+    [GtkChild] private Revealer one_choice_warning_revealer;
+    [GtkChild] private Label one_choice_enum_warning;
+    [GtkChild] private Label one_choice_integer_warning;
     [GtkChild] private ListBox properties_list_box;
     [GtkChild] private Button erase_button;
 
@@ -109,8 +111,15 @@ class RegistryInfo : Grid
 
         add_separator ();
 
-        KeyEditorChild key_editor_child = create_child (key);
-        one_choice_enum_warning.set_reveal_child (key_editor_child is KeyEditorChildEnumSingle);
+        KeyEditorChild key_editor_child = create_child (key, has_schema);
+        bool is_key_editor_child_single = key_editor_child is KeyEditorChildSingle;
+        if (is_key_editor_child_single)
+        {
+            bool is_enum = tmp_string == "<enum>";
+            one_choice_integer_warning.visible = !is_enum;
+            one_choice_enum_warning.visible = is_enum;
+        }
+        one_choice_warning_revealer.set_reveal_child (is_key_editor_child_single);
 
         ulong value_has_changed_handler = key_editor_child.value_has_changed.connect ((is_valid) => {
                 if (revealer.should_delay_apply (tmp_string))
@@ -198,7 +207,7 @@ class RegistryInfo : Grid
             });
     }
 
-    private static KeyEditorChild create_child (Key key)
+    private static KeyEditorChild create_child (Key key, bool has_schema)
     {
         switch (key.type_string)
         {
@@ -206,20 +215,37 @@ class RegistryInfo : Grid
                 switch (((GSettingsKey) key).range_content.n_children ())
                 {
                     case 0:  assert_not_reached ();
-                    case 1:  return (KeyEditorChild) new KeyEditorChildEnumSingle (key.value);
+                    case 1:  return (KeyEditorChild) new KeyEditorChildSingle (key.value, 
key.value.get_string ());
                     default: return (KeyEditorChild) new KeyEditorChildEnum (key);
                 }
             case "<flags>":
                 return (KeyEditorChild) new KeyEditorChildFlags ((GSettingsKey) key);
             case "b":
                 return (KeyEditorChild) new KeyEditorChildBool (key.planned_change && (key.planned_value != 
null) ? ((!) key.planned_value).get_boolean () : key.value.get_boolean ());
-            case "y":
             case "n":
-            case "q":
             case "i":
+            case "h":
+            // TODO "x" is not working in spinbuttons (double-based)
+                Variant range = ((GSettingsKey) key).range_content;
+                if (has_schema
+                    && (((GSettingsKey) key).range_type == "range")
+                    && (Key.get_variant_as_int64 (range.get_child_value (0)) == Key.get_variant_as_int64 
(range.get_child_value (1)))
+                   )
+                    return (KeyEditorChild) new KeyEditorChildSingle (key.value, key.value.print (false));
+                else
+                    return (KeyEditorChild) new KeyEditorChildNumberInt (key);
+            case "y":
+            case "q":
             case "u":
-            case "h":   // TODO "x" and "t" are not working in spinbuttons (double-based)
-                return (KeyEditorChild) new KeyEditorChildNumberInt (key);
+            // TODO "t" is not working in spinbuttons (double-based)
+                Variant range = ((GSettingsKey) key).range_content;
+                if (has_schema
+                    && (((GSettingsKey) key).range_type == "range")
+                    && (Key.get_variant_as_uint64 (range.get_child_value (0)) == Key.get_variant_as_uint64 
(range.get_child_value (1)))
+                   )
+                    return (KeyEditorChild) new KeyEditorChildSingle (key.value, key.value.print (false));
+                else
+                    return (KeyEditorChild) new KeyEditorChildNumberInt (key);
             case "d":
                 return (KeyEditorChild) new KeyEditorChildNumberDouble (key);
             case "mb":


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