[dconf-editor] Add a hint for maybe types.



commit e1bb1ecc931bba40c1a25ddb47e458da331bb45f
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Sun Oct 4 16:25:40 2015 +0200

    Add a hint for maybe types.

 editor/dconf-view.vala |   52 +++++++++++++++++++++++++++++++++++------------
 editor/key-editor.ui   |    2 +
 2 files changed, 40 insertions(+), 14 deletions(-)
---
diff --git a/editor/dconf-view.vala b/editor/dconf-view.vala
index 97f44a3..1305137 100644
--- a/editor/dconf-view.vala
+++ b/editor/dconf-view.vala
@@ -21,6 +21,7 @@ private abstract class KeyEditorDialog : Dialog
 {
     protected Key key;
     protected bool custom_value_is_valid { get; set; default = true; }
+    protected KeyEditorChild key_editor_child;
 
     public KeyEditorDialog ()
     {
@@ -31,18 +32,26 @@ private abstract class KeyEditorDialog : Dialog
     private void response_apply_cb () { on_response_apply (); this.destroy (); }
     protected abstract void on_response_apply ();
 
-    protected KeyEditorChild create_child ()
+    protected void create_child (Grid custom_value_grid)
     {
         switch (key.type_string)
         {
             case "<enum>":
-                return new KeyEditorChildEnum (key);
+                KeyEditorChildEnum _key_editor_child = new KeyEditorChildEnum (key);
+                key_editor_child = (KeyEditorChild) _key_editor_child;
+                custom_value_grid.add (_key_editor_child);
+                return;
             case "b":
-                return new KeyEditorChildBool (key.value.get_boolean ());
+                KeyEditorChildBool _key_editor_child = new KeyEditorChildBool (key.value.get_boolean ());
+                key_editor_child = (KeyEditorChild) _key_editor_child;
+                custom_value_grid.add (_key_editor_child);
+                break;
             case "s":
-                KeyEditorChildString key_editor_child = new KeyEditorChildString (key.value.get_string ());
+                KeyEditorChildString _key_editor_child = new KeyEditorChildString (key.value.get_string ());
+                key_editor_child = (KeyEditorChild) _key_editor_child;
                 key_editor_child.child_activated.connect (response_apply_cb);
-                return key_editor_child;
+                custom_value_grid.add (_key_editor_child);
+                break;
             case "y":
             case "n":
             case "q":
@@ -51,14 +60,29 @@ private abstract class KeyEditorDialog : Dialog
             case "x":
             case "t":
             case "d":
-                KeyEditorChildNumber key_editor_child = new KeyEditorChildNumber (key);
+                KeyEditorChildNumber _key_editor_child = new KeyEditorChildNumber (key);
+                key_editor_child = (KeyEditorChild) _key_editor_child;
                 key_editor_child.child_activated.connect (response_apply_cb);
-                return key_editor_child;
+                custom_value_grid.add (_key_editor_child);
+                break;
             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; });
+                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; });
+                key_editor_child = (KeyEditorChild) _key_editor_child;
                 key_editor_child.child_activated.connect (response_apply_cb);
-                return key_editor_child;
+                custom_value_grid.add (_key_editor_child);
+                break;
+        }
+
+        if ("m" in key.type_string)     /* warning: "<enum>" has an "m" in it */
+        {
+            /* Translators: neither the "nothing" keyword nor the "m" type should be translated; a "maybe 
type" is a type of variant that is nullable. */
+            Label label = new Label ("<i>" + _("Use the keyword “nothing” so set a maybe type (beginning 
with “m”) to its null value." + "</i>"));
+            label.visible = true;
+            label.use_markup = true;
+            label.max_width_chars = 55;
+            label.wrap = true;
+            custom_value_grid.add (label);
         }
     }
 
@@ -120,12 +144,12 @@ private class KeyEditorNoSchema : KeyEditorDialog       // TODO add type informa
         if (this.use_header_bar == 1)        // TODO else..?
             ((HeaderBar) this.get_header_bar ()).subtitle = key.parent.full_name;       // TODO 
get_header_bar() is [transfer none]
 
-        custom_value_grid.add (create_child ());
+        create_child (custom_value_grid);
     }
 
     protected override void on_response_apply ()
     {
-        Variant variant = ((KeyEditorChild) custom_value_grid.get_child_at (0, 0)).get_variant ();
+        Variant variant = key_editor_child.get_variant ();
         if (key.value != variant)
             key.value = variant;
     }
@@ -154,7 +178,7 @@ private class KeyEditor : KeyEditorDialog
         if (this.use_header_bar == 1)        // TODO else..?
             ((HeaderBar) this.get_header_bar ()).subtitle = key.parent.full_name;       // TODO 
get_header_bar() is [transfer none]
 
-        custom_value_grid.add (create_child ());
+        create_child (custom_value_grid);
 
         // infos
 
@@ -178,7 +202,7 @@ private class KeyEditor : KeyEditorDialog
     {
         if (!custom_value_switch.active)
         {
-            Variant variant = ((KeyEditorChild) custom_value_grid.get_child_at (0, 0)).get_variant ();
+            Variant variant = key_editor_child.get_variant ();
             if (key.is_default || key.value != variant)
                 key.value = variant;
         }
diff --git a/editor/key-editor.ui b/editor/key-editor.ui
index 9150c3b..b324d3b 100644
--- a/editor/key-editor.ui
+++ b/editor/key-editor.ui
@@ -235,6 +235,8 @@
             <property name="visible">True</property>
             <property name="hexpand">True</property>
             <property name="margin-top">6</property><!-- TODO better -->
+            <property name="orientation">vertical</property>
+            <property name="row-spacing">6</property>
             <property name="sensitive" bind-source="custom_value_switch" bind-property="active" 
bind-flags="sync-create|invert-boolean"/>
           </object>
         </child>


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