[dconf-editor] Use GAction for erase.



commit 6357314ff3a5c26b2443284e981f617003bcbb1d
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Fri Jan 26 16:39:42 2018 +0100

    Use GAction for erase.

 editor/dconf-model.vala           |   18 +++++++++++++++---
 editor/dconf-window.vala          |    9 +++++++++
 editor/key-list-box-row.vala      |   16 +++++-----------
 editor/modifications-handler.vala |   17 +++++++++++++++--
 4 files changed, 44 insertions(+), 16 deletions(-)
---
diff --git a/editor/dconf-model.vala b/editor/dconf-model.vala
index 5f54599..54be7b3 100644
--- a/editor/dconf-model.vala
+++ b/editor/dconf-model.vala
@@ -422,17 +422,29 @@ public class SettingsModel : Object
         // Alternative workaround: key.value_changed ();
     }
 
-    public void erase_key (DConfKey key)
+    public void erase_key (string full_name)
     {
+        SettingObject? key = get_key (full_name);
+
         try
         {
-            client.write_sync (key.full_name, null);
+            client.write_sync (full_name, null);
         }
         catch (Error error)
         {
             warning (error.message);
         }
-        key.value_changed ();
+
+        if (key == null)
+            warning ("Non-existing key erase request.");
+        else if (((!) key) is Key)
+        {
+            if (!(((!) key) is DConfKey))
+                warning ("Non-DConfKey key erase request.");
+            ((Key) (!) key).value_changed ();
+        }
+        else
+            assert_not_reached ();
     }
 
     public bool is_key_default (GSettingsKey key)
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index 5bfdb50..3ae5748 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -377,6 +377,8 @@ class DConfWindow : ApplicationWindow
         { "apply-delayed-settings", apply_delayed_settings },
         { "dismiss-delayed-settings", dismiss_delayed_settings },
 
+        { "erase", erase_dconf_key, "s" },  // here because needs a reload_view as we enter delay_mode
+
         { "copy-path", copy_path }
     };
 
@@ -463,6 +465,13 @@ class DConfWindow : ApplicationWindow
         invalidate_popovers ();
     }
 
+    private void erase_dconf_key (SimpleAction action, Variant? path_variant)
+        requires (path_variant != null)
+    {
+        modifications_handler.erase_dconf_key (((!) path_variant).get_string ());
+        invalidate_popovers ();
+    }
+
     private void copy_path (/* SimpleAction action, Variant? path_variant */)
     {
         browser_view.discard_row_popover ();
diff --git a/editor/key-list-box-row.vala b/editor/key-list-box-row.vala
index 5973065..e7f308f 100644
--- a/editor/key-list-box-row.vala
+++ b/editor/key-list-box-row.vala
@@ -382,10 +382,7 @@ private class KeyListBoxRowEditableNoSchema : KeyListBoxRow
             if (!delayed_apply_menu)
             {
                 popover.new_section ();
-                popover.new_action ("erase", () => {
-                        destroy_popover ();
-                        set_key_value (null);
-                    });
+                popover.new_gaction ("erase", "ui.erase(" + variant_s.print (false) + ")");
             }
         }
         else
@@ -401,10 +398,7 @@ private class KeyListBoxRowEditableNoSchema : KeyListBoxRow
             if (!planned_change || planned_value != null) // not &&
             {
                 popover.new_section ();
-                popover.new_action ("erase", () => {
-                        destroy_popover ();
-                        set_key_value (null);
-                    });
+                popover.new_gaction ("erase", "ui.erase(" + variant_s.print (false) + ")");
             }
         }
         return true;
@@ -634,9 +628,6 @@ private class ContextPopover : Popover
                 current_section.append (_("Set to default"), group_dot_action);     return;
             case "default2":
                 new_multi_default_action (group_dot_action);                        return;
-            case "erase":
-                /* Translators: "erase key" action in the right-click menu on a key without schema */
-                current_section.append (_("Erase key"), group_dot_action);          return;
             default:
                 assert_not_reached ();
         }
@@ -656,6 +647,9 @@ private class ContextPopover : Popover
             /* Translators: "dismiss change" action in the right-click menu on a key with pending changes */
             case "dismiss":         action_text = _("Dismiss change");      break;
 
+            /* Translators: "erase key" action in the right-click menu on a key without schema */
+            case "erase":           action_text = _("Erase key");           break;
+
             /* Translators: "open folder" action in the right-click menu on a folder */
             case "open":            action_text = _("Open");                break;
 
diff --git a/editor/modifications-handler.vala b/editor/modifications-handler.vala
index c5394de..c16e972 100644
--- a/editor/modifications-handler.vala
+++ b/editor/modifications-handler.vala
@@ -176,11 +176,24 @@ class ModificationsHandler : Object
             model.set_key_to_default ((GSettingsKey) key);
         else if (behaviour != Behaviour.UNSAFE)
         {
-            enter_delay_mode ();
+            mode = ModificationsMode.DELAYED;   // call only once delayed_changes_changed()
             add_delayed_setting (key.full_name, null);
         }
         else
-            model.erase_key ((DConfKey) key);
+            model.erase_key (((DConfKey) key).full_name);
+    }
+
+    public void erase_dconf_key (string full_name)
+    {
+        if (get_current_delay_mode ())
+            add_delayed_setting (full_name, null);
+        else if (behaviour != Behaviour.UNSAFE)
+        {
+            mode = ModificationsMode.DELAYED;   // call only once delayed_changes_changed()
+            add_delayed_setting (full_name, null);
+        }
+        else
+            model.erase_key (full_name);
     }
 
     public bool key_has_planned_change (string key_path)


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