[dconf-editor] Move listbox creation logic in dconf-window.vala.



commit 349471c7c0425ab17e7feb9814f74e30b4432d25
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Sat May 14 09:08:54 2016 +0200

    Move listbox creation logic in dconf-window.vala.

 editor/dconf-model.vala  |    8 +++
 editor/dconf-view.vala   |  115 ++++------------------------------------------
 editor/dconf-window.vala |  103 ++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 120 insertions(+), 106 deletions(-)
---
diff --git a/editor/dconf-model.vala b/editor/dconf-model.vala
index 24530f1..379d963 100644
--- a/editor/dconf-model.vala
+++ b/editor/dconf-model.vala
@@ -359,11 +359,13 @@ public class DConfKey : Key
             get_min_and_max_string (out min, out max, type_string);
             properties = new Variant.parsed ("(false, [{'key-name', %s},
                                                        {'parent-path', %s},
+                                                       {'type-code', %s},
                                                        {'type-name', %s},
                                                        {'minimum', %s},
                                                        {'maximum', %s}])",
                                              name,
                                              ((!) parent).full_name,
+                                             type_string,
                                              key_to_description (type_string),
                                              min,
                                              max);
@@ -371,9 +373,11 @@ public class DConfKey : Key
         else
             properties = new Variant.parsed ("(false, [{'key-name', %s},
                                                        {'parent-path', %s},
+                                                       {'type-code', %s},
                                                        {'type-name', %s}])",
                                              name,
                                              ((!) parent).full_name,
+                                             type_string,
                                              key_to_description (type_string));
     }
 }
@@ -436,6 +440,7 @@ public class GSettingsKey : Key
 
             properties = new Variant.parsed ("(true, [{'key-name', %s},
                                                       {'parent-path', %s},
+                                                      {'type-code', %s},
                                                       {'type-name', %s},
                                                       {'schema-id', %s},
                                                       {'summary', %s},
@@ -445,6 +450,7 @@ public class GSettingsKey : Key
                                                       {'maximum', %s}])",
                                              name,
                                              ((!) parent).full_name,
+                                             type_string,
                                              key_to_description (type_string),
                                              schema_id,
                                              summary,
@@ -456,6 +462,7 @@ public class GSettingsKey : Key
         else
             properties = new Variant.parsed ("(true, [{'key-name', %s},
                                                       {'parent-path', %s},
+                                                      {'type-code', %s},
                                                       {'type-name', %s},
                                                       {'schema-id', %s},
                                                       {'summary', %s},
@@ -463,6 +470,7 @@ public class GSettingsKey : Key
                                                       {'default-value', %s}])",
                                              name,
                                              ((!) parent).full_name,
+                                             type_string,
                                              key_to_description (type_string),
                                              schema_id,
                                              summary,
diff --git a/editor/dconf-view.vala b/editor/dconf-view.vala
index 048645a..ae0544e 100644
--- a/editor/dconf-view.vala
+++ b/editor/dconf-view.vala
@@ -63,10 +63,9 @@ private class KeyEditor : Dialog
     [GtkChild] private InfoBar no_schema_warning;
     [GtkChild] private ListBox listbox;
 
-    // "protected" is for emiting "notify::custom-value-is-valid"; something like [CCode(notify = true)] 
seems to fail
-    protected bool custom_value_is_valid { get; set; default = true; }
+    public bool custom_value_is_valid { get; set; default = true; }
 
-    public KeyEditor (bool has_schema, Variant dict, Key key)
+    public KeyEditor (bool has_schema, string name, string parent_path)
     {
         Object (use_header_bar: Gtk.Settings.get_default ().gtk_dialogs_use_header ? 1 : 0);
 
@@ -75,121 +74,27 @@ private class KeyEditor : Dialog
         else
             no_schema_warning.show ();
 
-        // TODO use VariantDict
-        string tmp_string;
+        this.title = name;
 
-        if (dict.lookup ("key-name",      "s", out tmp_string)) this.title = tmp_string;
-        else (assert_not_reached ());
-        if (dict.lookup ("parent-path",   "s", out tmp_string))
-        {
-            if (this.use_header_bar == 1)        // TODO else..?
-                ((HeaderBar) this.get_header_bar ()).subtitle = tmp_string;   // TODO get_header_bar() is 
[transfer none]
-        }
-        else (assert_not_reached ());
-
-        if (dict.lookup ("schema-id",     "s", out tmp_string)) add_row_from_label (_("Schema"),      
tmp_string);
-        if (dict.lookup ("summary",       "s", out tmp_string)) add_row_from_label (_("Summary"),     
tmp_string);
-        if (dict.lookup ("description",   "s", out tmp_string)) add_row_from_label (_("Description"), 
tmp_string);
-        /* Translators: as in datatype (integer, boolean, string, etc.) */
-        if (dict.lookup ("type-name",     "s", out tmp_string)) add_row_from_label (_("Type"),        
tmp_string);
-        else assert_not_reached ();
-        if (dict.lookup ("minimum",       "s", out tmp_string)) add_row_from_label (_("Minimum"),     
tmp_string);
-        if (dict.lookup ("maximum",       "s", out tmp_string)) add_row_from_label (_("Maximum"),     
tmp_string);
-        if (dict.lookup ("default-value", "s", out tmp_string)) add_row_from_label (_("Default"),     
tmp_string);
-
-        Widget key_editor_child = create_child (key);
-        if (has_schema)
-        {
-            Switch custom_value_switch = new Switch ();
-            custom_value_switch.width_request = 100; /* same request than for button_cancel/button_apply on 
scale 1; TODO better */
-            custom_value_switch.halign = Align.END;
-            custom_value_switch.hexpand = true;
-            custom_value_switch.show ();
-            add_row_from_widget (_("Use default value"), custom_value_switch, null);
-
-            custom_value_switch.bind_property ("active", key_editor_child, "sensitive", 
BindingFlags.SYNC_CREATE | BindingFlags.INVERT_BOOLEAN);
-
-            GSettingsKey gkey = (GSettingsKey) key;
-            custom_value_switch.set_active (gkey.is_default);
-            custom_value_switch.notify ["active"].connect (() => { button_apply.set_sensitive 
(custom_value_switch.get_active () ? true : custom_value_is_valid); });
-
-            this.response.connect ((dialog, response_id) => {
-                    if (response_id == ResponseType.APPLY)
-                    {
-                        if (!custom_value_switch.active)
-                        {
-                            Variant variant = ((KeyEditorChild) key_editor_child).get_variant ();
-                            if (key.value != variant)
-                                key.value = variant;
-                        }
-                        else if (!gkey.is_default)
-                            gkey.set_to_default ();
-                    }
-                    this.destroy ();
-                });
-        }
-        else
-        {
-            this.response.connect ((dialog, response_id) => {
-                    if (response_id == ResponseType.APPLY)
-                    {
-                        Variant variant = ((KeyEditorChild) key_editor_child).get_variant ();
-                        if (key.value != variant)
-                            key.value = variant;
-                    }
-                    this.destroy ();
-                });
-        }
-        add_row_from_widget (_("Custom value"), key_editor_child, key.type_string);
+        if (this.use_header_bar == 1)        // TODO else..?
+            ((HeaderBar) this.get_header_bar ()).subtitle = parent_path;   // TODO get_header_bar() is 
[transfer none]
 
         notify ["custom-value-is-valid"].connect (() => { button_apply.set_sensitive 
(custom_value_is_valid); });
     }
 
-    private Widget create_child (Key key)
+    public void switch_is_active (bool active)
     {
-        switch (key.type_string)
-        {
-            case "<enum>":
-                return (Widget) new KeyEditorChildEnum (key);
-            case "<flags>":
-                return (Widget) 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 (() => { response (ResponseType.APPLY); });
-                return (Widget) _key_editor_child;
-            case "y":
-            case "n":
-            case "q":
-            case "i":
-            case "u":
-            case "x":
-            case "t":
-            case "d":
-            case "h":
-                KeyEditorChildNumber _key_editor_child = new KeyEditorChildNumber (key);
-                _key_editor_child.child_activated.connect (() => { response (ResponseType.APPLY); });
-                return (Widget) _key_editor_child;
-            case "mb":
-                KeyEditorChildNullableBool _key_editor_child = new KeyEditorChildNullableBool (key);
-                return (Widget) _key_editor_child;
-            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) => { custom_value_is_valid = is_valid; });
-                _key_editor_child.child_activated.connect (() => { response (ResponseType.APPLY); });
-                return (Widget) _key_editor_child;
-        }
+        button_apply.set_sensitive (active ? true : custom_value_is_valid);
     }
 
-    private void add_row_from_label (string property_name, string property_value)
+    public void add_row_from_label (string property_name, string property_value)
     {
         listbox.add (new PropertyRow.from_label (property_name, property_value));
     }
 
-    private void add_row_from_widget (string property_name, Widget widget, string? type)
+    public void add_row_from_widget (string property_name, Widget widget, string? type)
     {
-        listbox.add (new PropertyRow.from_widgets (property_name, widget, type != null ? add_warning (type) 
: null));
+        listbox.add (new PropertyRow.from_widgets (property_name, widget, type != null ? add_warning ((!) 
type) : null));
     }
 
     private static Widget? add_warning (string type)
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index 6035555..317ab03 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -244,12 +244,113 @@ class DConfWindow : ApplicationWindow
         bool has_schema;
         unowned Variant [] dict_container;
         key.properties.get ("(ba{ss})", out has_schema, out dict_container);
+        Variant dict = dict_container [0];
+
+        // TODO use VariantDict
+        string tmp_string_1, tmp_string_2;
+
+        if (!dict.lookup ("key-name",     "s", out tmp_string_1)) assert_not_reached ();
+        if (!dict.lookup ("parent-path",  "s", out tmp_string_2)) assert_not_reached ();
+
+        KeyEditor key_editor = new KeyEditor (has_schema, tmp_string_1, tmp_string_2);
+
+        if (!dict.lookup ("type-code",    "s", out tmp_string_1)) assert_not_reached ();
+
+        if (dict.lookup ("schema-id",     "s", out tmp_string_2)) key_editor.add_row_from_label 
(_("Schema"),      tmp_string_2);
+        if (dict.lookup ("summary",       "s", out tmp_string_2)) key_editor.add_row_from_label 
(_("Summary"),     tmp_string_2);
+        if (dict.lookup ("description",   "s", out tmp_string_2)) key_editor.add_row_from_label 
(_("Description"), tmp_string_2);
+        /* Translators: as in datatype (integer, boolean, string, etc.) */
+        if (dict.lookup ("type-name",     "s", out tmp_string_2)) key_editor.add_row_from_label (_("Type"),  
      tmp_string_2);
+        else assert_not_reached ();
+        if (dict.lookup ("minimum",       "s", out tmp_string_2)) key_editor.add_row_from_label 
(_("Minimum"),     tmp_string_2);
+        if (dict.lookup ("maximum",       "s", out tmp_string_2)) key_editor.add_row_from_label 
(_("Maximum"),     tmp_string_2);
+        if (dict.lookup ("default-value", "s", out tmp_string_2)) key_editor.add_row_from_label 
(_("Default"),     tmp_string_2);
+
+        Widget key_editor_child = create_child (key_editor, key);
+        if (has_schema)
+        {
+            Switch custom_value_switch = new Switch ();
+            custom_value_switch.width_request = 100; /* same request than for button_cancel/button_apply on 
scale 1; TODO better */
+            custom_value_switch.halign = Align.END;
+            custom_value_switch.hexpand = true;
+            custom_value_switch.show ();
+            key_editor.add_row_from_widget (_("Use default value"), custom_value_switch, null);
+
+            custom_value_switch.bind_property ("active", key_editor_child, "sensitive", 
BindingFlags.SYNC_CREATE | BindingFlags.INVERT_BOOLEAN);
+
+            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 ()); });
+
+            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 ();
+                            if (key.value != variant)
+                                key.value = variant;
+                        }
+                        else if (!gkey.is_default)
+                            gkey.set_to_default ();
+                    }
+                    dialog.destroy ();
+                });
+        }
+        else
+        {
+            key_editor.response.connect ((dialog, response_id) => {
+                    if (response_id == ResponseType.APPLY)
+                    {
+                        Variant variant = ((KeyEditorChild) key_editor_child).get_variant ();
+                        if (key.value != variant)
+                            key.value = variant;
+                    }
+                    dialog.destroy ();
+                });
+        }
+        key_editor.add_row_from_widget (_("Custom value"), key_editor_child, tmp_string_1);
 
-        KeyEditor key_editor = new KeyEditor (has_schema, dict_container [0], key);
         key_editor.set_transient_for (this);
         key_editor.run ();
     }
 
+    private static Widget create_child (KeyEditor dialog, Key key)
+    {
+        switch (key.type_string)
+        {
+            case "<enum>":
+                return (Widget) new KeyEditorChildEnum (key);
+            case "<flags>":
+                return (Widget) 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;
+            case "y":
+            case "n":
+            case "q":
+            case "i":
+            case "u":
+            case "x":
+            case "t":
+            case "d":
+            case "h":
+                KeyEditorChildNumber key_editor_child = new KeyEditorChildNumber (key);
+                key_editor_child.child_activated.connect (() => { dialog.response (ResponseType.APPLY); });
+                return (Widget) key_editor_child;
+            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;
+        }
+    }
+
     private bool on_button_pressed (Widget widget, Gdk.EventButton event)
     {
         ListBoxRow list_box_row = (ListBoxRow) widget.get_parent ();


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