[dconf-editor] Use GAction for default1.



commit a298fdb21b5462710cf6c8fe33c21b939f5f840d
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Fri Jan 26 15:18:03 2018 +0100

    Use GAction for default1.

 editor/browser-view.vala          |   13 ++++++++++++-
 editor/dconf-model.vala           |   12 ++++++++----
 editor/key-list-box-row.vala      |   18 ++++++------------
 editor/modifications-handler.vala |   10 +++++++++-
 editor/registry-info.vala         |    2 +-
 5 files changed, 36 insertions(+), 19 deletions(-)
---
diff --git a/editor/browser-view.vala b/editor/browser-view.vala
index 20d83d3..4fbf885 100644
--- a/editor/browser-view.vala
+++ b/editor/browser-view.vala
@@ -89,7 +89,8 @@ class BrowserView : Grid
     private const GLib.ActionEntry [] action_entries =
     {
         { "dismiss-change", dismiss_change, "s" },
-        { "refresh-folder", refresh_folder }
+        { "refresh-folder", refresh_folder },
+        { "set-to-default", set_to_default, "(ss)" }
     };
 
     private void dismiss_change (SimpleAction action, Variant? path_variant)
@@ -106,6 +107,16 @@ class BrowserView : Grid
         hide_reload_warning ();
     }
 
+    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);
+        invalidate_popovers ();
+    }
+
     /*\
     * * Views
     \*/
diff --git a/editor/dconf-model.vala b/editor/dconf-model.vala
index 54be7b3..ff0e6f7 100644
--- a/editor/dconf-model.vala
+++ b/editor/dconf-model.vala
@@ -413,12 +413,16 @@ public class SettingsModel : Object
         }
     }
 
-    public void set_key_to_default (GSettingsKey key)
+    public void set_key_to_default (string full_name, string schema_id)
     {
-        GLib.Settings settings = key.settings;
-        settings.reset (key.name);
+        SettingObject? key = get_key (full_name, schema_id);
+        if (key == null && !(key is GSettingsKey))
+            return; // TODO better
+
+        GLib.Settings settings = ((GSettingsKey) (!) key).settings;
+        settings.reset (((!) key).name);
         if (settings.backend.get_type ().name () == "GDelayedSettingsBackend") // Workaround for 
https://bugzilla.gnome.org/show_bug.cgi?id=791290
-            settings.backend.changed (key.full_name, null);
+            settings.backend.changed (full_name, null);
         // Alternative workaround: key.value_changed ();
     }
 
diff --git a/editor/key-list-box-row.vala b/editor/key-list-box-row.vala
index e7f308f..95e81b8 100644
--- a/editor/key-list-box-row.vala
+++ b/editor/key-list-box-row.vala
@@ -420,7 +420,7 @@ private class KeyListBoxRowEditable : KeyListBoxRow
             boolean_switch_toggled_handler = ((!) boolean_switch).notify ["active"].connect (() => {
                     bool boolean = ((!) boolean_switch).get_active ();
                     if (boolean == key.default_value.get_boolean ())
-                        model.set_key_to_default (key);
+                        model.set_key_to_default (key.full_name, key.schema_id);
                     else
                         model.set_key_value (key, new Variant.boolean (boolean));
                 });
@@ -562,18 +562,12 @@ private class KeyListBoxRowEditable : KeyListBoxRow
             popover.new_gaction ("dismiss", "bro.dismiss-change(" + variant_s.print (false) + ")");
 
             if (planned_value != null)
-                popover.new_action ("default1", () => {
-                        destroy_popover ();
-                        set_key_value (null);
-                    });
+                popover.new_gaction ("default1", "bro.set-to-default(" + variant_ss.print (false) + ")");
         }
         else if (!model.is_key_default (key))
         {
             popover.new_section ();
-            popover.new_action ("default1", () => {
-                    destroy_popover ();
-                    set_key_value (null);
-                });
+            popover.new_gaction ("default1", "bro.set-to-default(" + variant_ss.print (false) + ")");
         }
         return true;
     }
@@ -623,9 +617,6 @@ private class ContextPopover : Popover
 
         switch (action_action)
         {
-            case "default1":
-                /* Translators: "reset key value" action in the right-click menu on the list of keys */
-                current_section.append (_("Set to default"), group_dot_action);     return;
             case "default2":
                 new_multi_default_action (group_dot_action);                        return;
             default:
@@ -641,6 +632,9 @@ private class ContextPopover : Popover
             /* Translators: "open key-editor page" action in the right-click menu on the list of keys */
             case "customize":       action_text = _("Customize…");          break;
 
+            /* Translators: "reset key value" action in the right-click menu on the list of keys */
+            case "default1":        action_text = _("Set to default");      break;
+
             /* Translators: "open key-editor page" action in the right-click menu on the list of keys, when 
key is hard-conflicting */
             case "detail":          action_text = _("Show details…");       break;
 
diff --git a/editor/modifications-handler.vala b/editor/modifications-handler.vala
index c16e972..6b75ee5 100644
--- a/editor/modifications-handler.vala
+++ b/editor/modifications-handler.vala
@@ -173,7 +173,7 @@ class ModificationsHandler : Object
         else if (new_value != null)
             model.set_key_value (key, (!) new_value);
         else if (key is GSettingsKey)
-            model.set_key_to_default ((GSettingsKey) key);
+            model.set_key_to_default (((GSettingsKey) key).full_name, ((GSettingsKey) key).schema_id);
         else if (behaviour != Behaviour.UNSAFE)
         {
             mode = ModificationsMode.DELAYED;   // call only once delayed_changes_changed()
@@ -196,6 +196,14 @@ class ModificationsHandler : Object
             model.erase_key (full_name);
     }
 
+    public void set_to_default (string full_name, string schema_id)
+    {
+        if (get_current_delay_mode ())
+            add_delayed_setting (full_name, null);
+        else
+            model.set_key_to_default (full_name, schema_id);
+    }
+
     public bool key_has_planned_change (string key_path)
     {
         if (keys_awaiting_hashtable.contains (key_path))
diff --git a/editor/registry-info.vala b/editor/registry-info.vala
index f34edeb..9633343 100644
--- a/editor/registry-info.vala
+++ b/editor/registry-info.vala
@@ -209,7 +209,7 @@ class RegistryInfo : Grid, BrowsableView
                     {
                         if (custom_value_switch.get_active ())
                         {
-                            model.set_key_to_default ((GSettingsKey) key);
+                            model.set_key_to_default (((GSettingsKey) key).full_name, ((GSettingsKey) 
key).schema_id);
                             SignalHandler.block (key_editor_child, value_has_changed_handler);
                             key_editor_child.reload (model.get_key_value (key));
                             //if (tmp_string == "<flags>")                      let's try to live without 
this...


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