[dconf-editor] Use GAction for set_key_value().



commit 9047cfa4d69bd16bc7073b9069573ed3a1af8889
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Thu Feb 8 06:14:52 2018 +0100

    Use GAction for set_key_value().

 editor/browser-view.vala     |   34 ++++++++++++++++++++++++++--------
 editor/key-list-box-row.vala |   36 ++++++++++++++++++++++++++++++++----
 editor/registry-search.vala  |    2 --
 editor/registry-view.vala    |    2 --
 4 files changed, 58 insertions(+), 16 deletions(-)
---
diff --git a/editor/browser-view.vala b/editor/browser-view.vala
index 135d4d1..13ea1a1 100644
--- a/editor/browser-view.vala
+++ b/editor/browser-view.vala
@@ -91,7 +91,9 @@ class BrowserView : Grid
         { "empty", empty , "*" },
 
         { "refresh-folder", refresh_folder },
-        { "set-to-default", set_to_default, "(ss)" },
+
+        { "set-key-value",  set_key_value,  "(ssv)" },
+        { "set-to-default", set_to_default, "(ss)"  },  // see also ui.erase(s)
 
         { "toggle-dconf-key-switch",     toggle_dconf_key_switch,     "(sb)"   },
         { "toggle-gsettings-key-switch", toggle_gsettings_key_switch, "(ssbb)" }
@@ -106,13 +108,29 @@ class BrowserView : Grid
         hide_reload_warning ();
     }
 
+    private void set_key_value (SimpleAction action, Variant? value_variant)
+        requires (value_variant != null)
+    {
+        string full_name;
+        string context;
+        Variant key_value_request;
+        ((!) value_variant).@get ("(ssv)", out full_name, out context, out key_value_request);
+
+        if (modifications_handler.get_current_delay_mode ())
+            modifications_handler.add_delayed_setting (full_name, key_value_request);
+        else if (context == ".dconf")
+            modifications_handler.set_dconf_key_value (full_name, key_value_request);
+        else
+            modifications_handler.set_gsettings_key_value (full_name, context, key_value_request);
+    }
+
     private void set_to_default (SimpleAction action, Variant? path_variant)
         requires (path_variant != null)
     {
         string full_name;
-        string context;
-        ((!) path_variant).@get ("(ss)", out full_name, out context);
-        modifications_handler.set_to_default (full_name, context);
+        string schema_id;
+        ((!) path_variant).@get ("(ss)", out full_name, out schema_id);
+        modifications_handler.set_to_default (full_name, schema_id);
         invalidate_popovers ();
     }
 
@@ -136,15 +154,15 @@ class BrowserView : Grid
             assert_not_reached ();
 
         string full_name;
-        string context;
+        string schema_id;
         bool key_value_request;
         bool key_default_value;
-        ((!) value_variant).@get ("(ssbb)", out full_name, out context, out key_value_request, out 
key_default_value);
+        ((!) value_variant).@get ("(ssbb)", out full_name, out schema_id, out key_value_request, out 
key_default_value);
 
         if (key_value_request == key_default_value)
-            modifications_handler.set_to_default (full_name, context);
+            modifications_handler.set_to_default (full_name, schema_id);
         else
-            modifications_handler.set_gsettings_key_value (full_name, context, new Variant.boolean 
(key_value_request));
+            modifications_handler.set_gsettings_key_value (full_name, schema_id, new Variant.boolean 
(key_value_request));
     }
 
     /*\
diff --git a/editor/key-list-box-row.vala b/editor/key-list-box-row.vala
index 8b8d360..5c5b8d6 100644
--- a/editor/key-list-box-row.vala
+++ b/editor/key-list-box-row.vala
@@ -224,7 +224,6 @@ private abstract class KeyListBoxRow : ClickableListBoxRow
         }
     }
 
-    public signal void set_key_value (Variant? new_value);
     public signal void change_dismissed ();
 
     public ModificationsHandler modifications_handler { protected get; construct; }
@@ -287,6 +286,35 @@ private abstract class KeyListBoxRow : ClickableListBoxRow
                 context.remove_class ("erase");
         }
     }
+
+    protected void set_key_value (bool has_schema, Variant? new_value)
+    {
+        ModelButton actionable = new ModelButton ();
+        actionable.visible = false;
+        Variant variant;
+        if (new_value == null)
+        {
+            if (has_schema)
+            {
+                variant = new Variant ("(ss)", abstract_key.full_name, ((GSettingsKey) 
abstract_key).schema_id);
+                actionable.set_detailed_action_name ("bro.set-to-default(" + variant.print (false) + ")");
+            }
+            else
+            {
+                variant = new Variant.string (abstract_key.full_name);
+                actionable.set_detailed_action_name ("ui.erase(" + variant.print (false) + ")");
+            }
+        }
+        else
+        {
+            variant = new Variant ("(ssv)", abstract_key.full_name, (has_schema ? ((GSettingsKey) 
abstract_key).schema_id : ".dconf"), (!) new_value);
+            actionable.set_detailed_action_name ("bro.set-key-value(" + variant.print (false) + ")");
+        }
+        ((Container) get_child ()).add (actionable);
+        actionable.clicked ();
+        ((Container) get_child ()).remove (actionable);
+        actionable.destroy ();
+    }
 }
 
 private class KeyListBoxRowEditableNoSchema : KeyListBoxRow
@@ -382,7 +410,7 @@ private class KeyListBoxRowEditableNoSchema : KeyListBoxRow
             popover.value_changed.connect ((gvariant) => {
                     hide_right_click_popover ();
                     action.change_state (new Variant.maybe (null, new Variant.maybe (new VariantType 
(key.type_string), gvariant)));
-                    set_key_value (gvariant);
+                    set_key_value (false, gvariant);
                 });
 
             if (!delayed_apply_menu)
@@ -534,7 +562,7 @@ private class KeyListBoxRowEditable : KeyListBoxRow
                     hide_right_click_popover ();
                     Variant key_value = model.get_key_value (key);
                     action.change_state (new Variant.maybe (null, new Variant.maybe (new VariantType 
(key_value.get_type_string ()), gvariant)));
-                    set_key_value (gvariant);
+                    set_key_value (true, gvariant);
                 });
         }
         else if (!delayed_apply_menu && !planned_change && key.type_string == "<flags>")
@@ -553,7 +581,7 @@ private class KeyListBoxRowEditable : KeyListBoxRow
                 });
             popover.destroy.connect (() => modifications_handler.disconnect 
(delayed_modifications_changed_handler));
 
-            popover.value_changed.connect ((gvariant) => set_key_value (gvariant));
+            popover.value_changed.connect ((gvariant) => set_key_value (true, gvariant));
         }
         else if (planned_change)
         {
diff --git a/editor/registry-search.vala b/editor/registry-search.vala
index bbc1ecc..172afbc 100644
--- a/editor/registry-search.vala
+++ b/editor/registry-search.vala
@@ -137,7 +137,6 @@ class RegistrySearch : Grid, BrowsableView
             key_row.small_keys_list_rows = _small_keys_list_rows;
 
             ulong on_delete_call_handler = key_row.on_delete_call.connect (() => 
modifications_handler.set_key_value (key, null));
-            ulong set_key_value_handler = key_row.set_key_value.connect ((variant) => { 
modifications_handler.set_key_value (key, variant); });
             ulong change_dismissed_handler = key_row.change_dismissed.connect (() => 
modifications_handler.dismiss_change (key.full_name));
 
             ulong delayed_modifications_changed_handler =
@@ -146,7 +145,6 @@ class RegistrySearch : Grid, BrowsableView
 
             row.destroy.connect (() => {
                     modifications_handler.disconnect (delayed_modifications_changed_handler);
-                    key_row.disconnect (set_key_value_handler);
                     key_row.disconnect (on_delete_call_handler);
                     key_row.disconnect (change_dismissed_handler);
                 });
diff --git a/editor/registry-view.vala b/editor/registry-view.vala
index 52f7035..eb7344f 100644
--- a/editor/registry-view.vala
+++ b/editor/registry-view.vala
@@ -184,7 +184,6 @@ class RegistryView : Grid, BrowsableView
             key_row.small_keys_list_rows = _small_keys_list_rows;
 
             ulong on_delete_call_handler = key_row.on_delete_call.connect (() => 
modifications_handler.set_key_value (key, null));
-            ulong set_key_value_handler = key_row.set_key_value.connect ((variant) => { 
modifications_handler.set_key_value (key, variant); });
             ulong change_dismissed_handler = key_row.change_dismissed.connect (() => 
modifications_handler.dismiss_change (key.full_name));
 
             ulong delayed_modifications_changed_handler =
@@ -193,7 +192,6 @@ class RegistryView : Grid, BrowsableView
 
             row.destroy.connect (() => {
                     modifications_handler.disconnect (delayed_modifications_changed_handler);
-                    key_row.disconnect (set_key_value_handler);
                     key_row.disconnect (on_delete_call_handler);
                     key_row.disconnect (change_dismissed_handler);
                 });


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