[dconf-editor] Correctly update popovers with radio-choice.



commit e72482823e16e9a360812e48ce3cef6da25bfd8e
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Thu Jun 23 14:35:30 2016 +0200

    Correctly update popovers with radio-choice.

 editor/dconf-view.vala       |   48 ++++++++++++++++++++++++-----------------
 editor/key-list-box-row.vala |   30 ++++++++++++++++++-------
 2 files changed, 49 insertions(+), 29 deletions(-)
---
diff --git a/editor/dconf-view.vala b/editor/dconf-view.vala
index 17e0d6a..0342dfa 100644
--- a/editor/dconf-view.vala
+++ b/editor/dconf-view.vala
@@ -135,29 +135,28 @@ public interface KeyEditorChild : Widget
 private class KeyEditorChildEnum : MenuButton, KeyEditorChild
 {
     private Variant variant;
+    private GLib.Action action;
 
     public KeyEditorChildEnum (Key key)
         requires (key.type_string == "<enum>")
     {
-        this.variant = key.value;
-
         this.visible = true;
         this.hexpand = true;
         this.halign = Align.END;
         this.use_popover = true;
         this.width_request = 100;
-        this.label = variant.get_type () == VariantType.STRING ? variant.get_string () : variant.print 
(false);
 
         ContextPopover popover = new ContextPopover ();
-        popover.create_buttons_list (key, false, false);
+        action = popover.create_buttons_list (key, false, false);
         popover.set_relative_to (this);
+
         popover.value_changed.connect ((gvariant) => {
-                variant = gvariant;
-                this.label = gvariant.get_type () == VariantType.STRING ? gvariant.get_string () : 
gvariant.print (false);
+                reload (gvariant);
                 popover.closed ();
 
                 value_has_changed (true);
             });
+        reload (key.value);
         this.set_popover ((Popover) popover);
     }
 
@@ -165,6 +164,13 @@ private class KeyEditorChildEnum : MenuButton, KeyEditorChild
     {
         return variant;
     }
+
+    private void reload (Variant gvariant)
+    {
+        variant = gvariant;
+        label = gvariant.get_type () == VariantType.STRING ? gvariant.get_string () : gvariant.print (false);
+        action.change_state (new Variant.maybe (null, new Variant.maybe (VariantType.STRING, gvariant)));
+    }
 }
 
 private class KeyEditorChildFlags : Grid, KeyEditorChild
@@ -213,37 +219,28 @@ private class KeyEditorChildFlags : Grid, KeyEditorChild
 private class KeyEditorChildNullableBool : MenuButton, KeyEditorChild
 {
     private Variant variant;
+    private Variant? maybe_variant;
 
     public KeyEditorChildNullableBool (Key key)
         requires (key.type_string == "mb")
     {
-        this.variant = key.value;
-        Variant? maybe_variant = variant.get_maybe ();
-
         this.visible = true;
         this.hexpand = true;
         this.halign = Align.END;
         this.use_popover = true;
         this.width_request = 100;
-        if (maybe_variant == null)
-            this.label = Key.cool_boolean_text_value (null);
-        else
-            this.label = Key.cool_boolean_text_value (((!) maybe_variant).get_boolean ());
 
         ContextPopover popover = new ContextPopover ();
-        popover.create_buttons_list (key, false, false);
+        GLib.Action action = popover.create_buttons_list (key, false, false);
         popover.set_relative_to (this);
+
         popover.value_changed.connect ((gvariant) => {
-                variant = gvariant;
-                maybe_variant = gvariant.get_maybe ();
-                if (maybe_variant == null)
-                    this.label = Key.cool_boolean_text_value (null);
-                else
-                    this.label = Key.cool_boolean_text_value (((!) maybe_variant).get_boolean ());
+                reload (gvariant);
                 popover.closed ();
 
                 value_has_changed (true);
             });
+        reload (key.value);
         this.set_popover ((Popover) popover);
     }
 
@@ -251,6 +248,17 @@ private class KeyEditorChildNullableBool : MenuButton, KeyEditorChild
     {
         return variant;
     }
+
+    private void reload (Variant gvariant)
+    {
+        variant = gvariant;
+        maybe_variant = variant.get_maybe ();
+
+        if (maybe_variant == null)
+            label = Key.cool_boolean_text_value (null);
+        else
+            label = Key.cool_boolean_text_value (((!) maybe_variant).get_boolean ());
+    }
 }
 
 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
diff --git a/editor/key-list-box-row.vala b/editor/key-list-box-row.vala
index 001be5f..8607bcf 100644
--- a/editor/key-list-box-row.vala
+++ b/editor/key-list-box-row.vala
@@ -173,14 +173,16 @@ private class KeyListBoxRowEditableNoSchema : KeyListBoxRow
         if (key.type_string == "b" || key.type_string == "mb")
         {
             popover.new_section ();
-            popover.create_buttons_list (key, true, delayed_apply_menu);
+            GLib.Action action = popover.create_buttons_list (key, true, delayed_apply_menu);
 
             popover.change_dismissed.connect (() => {
-                    destroy_popover ();
+                    hide_right_click_popover ();
+                    action.change_state (new Variant.maybe (new VariantType ("m" + key.type_string), null));
                     change_dismissed ();
                 });
             popover.value_changed.connect ((gvariant) => {
-                    destroy_popover ();
+                    hide_right_click_popover ();
+                    action.change_state (new Variant.maybe (null, new Variant.maybe (new VariantType 
(key.type_string), gvariant)));
                     set_key_value (gvariant);
                 });
         }
@@ -229,15 +231,19 @@ private class KeyListBoxRowEditable : KeyListBoxRow
 
         if (key.type_string == "b" || key.type_string == "<enum>" || key.type_string == "mb")
         {
+            string real_type_string = key.value.get_type_string ();
+
             popover.new_section ();
-            popover.create_buttons_list (key, true, delayed_apply_menu);
+            GLib.Action action = popover.create_buttons_list (key, true, delayed_apply_menu);
 
             popover.change_dismissed.connect (() => {
-                    destroy_popover ();
+                    hide_right_click_popover ();
+                    action.change_state (new Variant.maybe (new VariantType ("m" + real_type_string), null));
                     change_dismissed ();
                 });
             popover.value_changed.connect ((gvariant) => {
-                    destroy_popover ();
+                    hide_right_click_popover ();
+                    action.change_state (new Variant.maybe (null, new Variant.maybe (new VariantType 
(real_type_string), gvariant)));
                     set_key_value (gvariant);
                 });
         }
@@ -420,7 +426,7 @@ private class ContextPopover : Popover
     * * Choices
     \*/
 
-    public void create_buttons_list (Key key, bool has_default_value, bool delayed_apply_menu)
+    public GLib.Action create_buttons_list (Key key, bool has_default_value, bool delayed_apply_menu)
     {
         set_group ("enum");
         const string ACTION_NAME = "choice";
@@ -432,13 +438,17 @@ private class ContextPopover : Popover
         string type_string = original_type.dup_string ();
 
         Variant? value_variant;
-        if (key.planned_change) // TODO report bug: if using ?: inside ?:, there's a "g_variant_ref: 
assertion 'value->ref_count > 0' failed"
+        if (!has_default_value) // TODO report bug: if using ?: inside ?:, there's a "g_variant_ref: 
assertion 'value->ref_count > 0' failed"
+            value_variant = key.planned_change && (key.planned_value != null) ? key.planned_value : 
key.value;
+        else if (key.planned_change)
             value_variant = key.planned_value;
         else
             value_variant = key.has_schema && ((GSettingsKey) key).is_default ? null : key.value;
         Variant variant = new Variant.maybe (original_type, value_variant);
         Variant nullable_variant = new Variant.maybe (nullable_type, delayed_apply_menu && 
!key.planned_change ? null : variant);
-        current_group.add_action (new SimpleAction.stateful (ACTION_NAME, nullable_nullable_type, 
nullable_variant));
+
+        GLib.Action action = (GLib.Action) new SimpleAction.stateful (ACTION_NAME, nullable_nullable_type, 
nullable_variant);
+        current_group.add_action (action);
 
         if (has_default_value)
         {
@@ -485,6 +495,8 @@ private class ContextPopover : Popover
             });
 
         finalize_menu ();
+
+        return action;
     }
 
     /*\


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