[dconf-editor] Use a GAction for recursivereset.



commit 1d061062c895a96848c09a10b065b04a9c6b118c
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Tue Jan 9 15:57:46 2018 +0100

    Use a GAction for recursivereset.

 editor/browser-view.vala     |   20 +-------------------
 editor/dconf-window.vala     |   23 +++++++++++++++++------
 editor/key-list-box-row.vala |   35 ++++++++++++++++++-----------------
 editor/registry-search.vala  |   11 ++++++-----
 editor/registry-view.vala    |   11 ++++++-----
 5 files changed, 48 insertions(+), 52 deletions(-)
---
diff --git a/editor/browser-view.vala b/editor/browser-view.vala
index 57c960a..f4b0333 100644
--- a/editor/browser-view.vala
+++ b/editor/browser-view.vala
@@ -344,25 +344,7 @@ class BrowserView : Grid
     * * Delay mode actions
     \*/
 
-    public void reset (bool recursively)
-    {
-        SettingsModel model = modifications_handler.model;
-        reset_objects (model.get_children (current_directory), recursively);
-    }
-
-    public void reset_directory (Directory parent, bool recursively)
-    {
-        SettingsModel model = modifications_handler.model;
-        enter_delay_mode ();
-        GLib.ListStore? objects = model.get_children (parent);
-        if (objects != null)
-        {
-            reset_generic ((!) objects, recursively);
-            revealer.warn_if_no_planned_changes ();
-        }
-    }
-
-    private void reset_objects (GLib.ListStore? objects, bool recursively)
+    public void reset_objects (GLib.ListStore? objects, bool recursively)
     {
         enter_delay_mode ();
         reset_generic (objects, recursively);
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index 1f91666..d3a79da 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -26,7 +26,7 @@ class DConfWindow : ApplicationWindow
         { "open-path-with-selection", open_path_with_selection, "(ss)" },
         { "reload", reload },
 
-        { "reset-recursive", reset_recursively },
+        { "reset-recursive", reset_recursively, "s" },
         { "reset-visible", reset_visible },
         { "enter-delay-mode", enter_delay_mode }
     };
@@ -374,8 +374,9 @@ class DConfWindow : ApplicationWindow
         else
         {
             section = new GLib.Menu ();
+            Variant variant = new Variant.string (current_path);
             section.append (_("Reset visible keys"), "ui.reset-visible");
-            section.append (_("Reset view recursively"), "ui.reset-recursive");
+            section.append (_("Reset view recursively"), "ui.reset-recursive(" + variant.print (false) + 
")");
             section.freeze ();
             menu.append_section (null, section);
         }
@@ -419,14 +420,20 @@ class DConfWindow : ApplicationWindow
         reload_view (true);
     }
 
-    private void reset_recursively (/* SimpleAction action, Variant? path_variant */)
+    private void reset_recursively (SimpleAction action, Variant? path_variant)
+        requires (path_variant != null)
     {
-        browser_view.reset (true);
+        reset_path (((!) path_variant).get_string (), true);
     }
 
     private void reset_visible (/* SimpleAction action, Variant? path_variant */)
     {
-        browser_view.reset (false);
+        reset_path (current_path, false);
+    }
+
+    private void reset_path (string path, bool recursively)
+    {
+        browser_view.reset_objects (model.get_children (model.get_directory (path)), recursively);
     }
 
     private void enter_delay_mode (/* SimpleAction action, Variant? path_variant */)
@@ -578,7 +585,11 @@ class DConfWindow : ApplicationWindow
                     if (info_button.active || bookmarks_button.active)
                         return false;
                     browser_view.discard_row_popover ();
-                    browser_view.set_to_default ();
+                    string? selected_row = browser_view.get_selected_row_name ();
+                    if (selected_row != null && ((!) selected_row).has_suffix ("/"))
+                        reset_path ((!) selected_row, true);
+                    else
+                        browser_view.set_to_default ();
                     return true;
                 default:
                     break;  // TODO make <ctrl>v work; https://bugzilla.gnome.org/show_bug.cgi?id=762257 is 
WONTFIX
diff --git a/editor/key-list-box-row.vala b/editor/key-list-box-row.vala
index 8ee2592..baef1c0 100644
--- a/editor/key-list-box-row.vala
+++ b/editor/key-list-box-row.vala
@@ -76,8 +76,6 @@ private class ListBoxRowHeader : Grid
 
 private abstract class ClickableListBoxRow : EventBox
 {
-    public signal void on_delete_call ();
-
     public signal void on_popover_disappear ();
     public ulong on_popover_disappear_handler = 0;  // used by registry-search
 
@@ -196,7 +194,7 @@ private class FolderListBoxRow : ClickableListBoxRow
         popover.new_copy_action (get_text ());
 
         popover.new_section ();
-        popover.new_action ("recursivereset", () => on_delete_call ());
+        popover.new_gaction ("recursivereset", "ui.reset-recursive(" + variant.print (false) + ")");
 
         return true;
     }
@@ -205,6 +203,8 @@ private class FolderListBoxRow : ClickableListBoxRow
 [GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/key-list-box-row.ui")]
 private abstract class KeyListBoxRow : ClickableListBoxRow
 {
+    public signal void on_delete_call ();
+
     [GtkChild] private Grid key_name_and_value_grid;
     [GtkChild] private Label key_name_label;
     [GtkChild] protected Label key_value_label;
@@ -629,9 +629,6 @@ private class ContextPopover : Popover
             case "unerase":
                 /* Translators: "dismiss change" action in the right-click menu on a key without schema 
planned to be erased */
                 current_section.append (_("Do not erase"), group_dot_action);       return;
-            case "recursivereset":
-                /* Translators: "reset recursively" action in the right-click menu on a folder */
-                current_section.append (_("Reset recursively"), group_dot_action);  return;
             default:
                 assert_not_reached ();
         }
@@ -639,20 +636,24 @@ private class ContextPopover : Popover
 
     public void new_gaction (string action_name, string action_action)
     {
+        string action_text;
         switch (action_name)
         {
-            case "customize":
-                /* Translators: "open key-editor dialog" action in the right-click menu on the list of keys 
*/
-                current_section.append (_("Customize…"), action_action);            return;
-            case "open":
-                /* Translators: "open folder" action in the right-click menu on a folder */
-                current_section.append (_("Open"), action_action);                  return;
-            case "open_parent":
-                /* Translators: "open parent folder" action in the right-click menu on a folder in a search 
result */
-                current_section.append (_("Open parent folder"), action_action);    return;
-            default:
-                assert_not_reached ();
+            /* Translators: "open key-editor page" action in the right-click menu on the list of keys */
+            case "customize":       action_text = _("Customize…");          break;
+
+            /* Translators: "open folder" action in the right-click menu on a folder */
+            case "open":            action_text = _("Open");                break;
+
+            /* Translators: "open parent folder" action in the right-click menu on a folder in a search 
result */
+            case "open_parent":     action_text = _("Open parent folder");  break;
+
+            /* Translators: "reset recursively" action in the right-click menu on a folder */
+            case "recursivereset":  action_text = _("Reset recursively");   break;
+
+            default: assert_not_reached ();
         }
+        current_section.append (action_text, action_action);
     }
 
     public void new_copy_action (string text)
diff --git a/editor/registry-search.vala b/editor/registry-search.vala
index 35cf1ef..2fe6945 100644
--- a/editor/registry-search.vala
+++ b/editor/registry-search.vala
@@ -142,12 +142,10 @@ class RegistrySearch : Grid, BrowsableView
         else
             parent_path = SettingsModel.get_base_path (full_name);
         bool is_local_result = parent_path == main_window.current_path;
-        ulong on_delete_call_handler;
 
         if (setting_object is Directory)
         {
             row = new FolderListBoxRow (setting_object.name, setting_object.full_name, 
setting_object.parent_path, !is_local_result);
-            on_delete_call_handler = row.on_delete_call.connect (() => browser_view.reset_directory 
((Directory) setting_object, true));
         }
         else
         {
@@ -160,7 +158,7 @@ class RegistrySearch : Grid, BrowsableView
             KeyListBoxRow key_row = (KeyListBoxRow) row;
             key_row.small_keys_list_rows = _small_keys_list_rows;
 
-            on_delete_call_handler = row.on_delete_call.connect (() => modifications_handler.set_key_value 
(key, null));
+            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));
 
@@ -171,6 +169,7 @@ 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);
                 });
         }
@@ -178,7 +177,6 @@ class RegistrySearch : Grid, BrowsableView
         ulong button_press_event_handler = row.button_press_event.connect (on_button_pressed);
 
         row.destroy.connect (() => {
-                row.disconnect (on_delete_call_handler);
                 row.disconnect (button_press_event_handler);
             });
 
@@ -342,7 +340,10 @@ class RegistrySearch : Grid, BrowsableView
         if (selected_row == null)
             return;
 
-        ((ClickableListBoxRow) ((!) selected_row).get_child ()).on_delete_call ();
+        if (!(((!) selected_row).get_child () is KeyListBoxRow))
+            assert_not_reached ();
+
+        ((KeyListBoxRow) ((!) selected_row).get_child ()).on_delete_call ();
     }
 
     public void discard_row_popover ()
diff --git a/editor/registry-view.vala b/editor/registry-view.vala
index fa26813..266fed1 100644
--- a/editor/registry-view.vala
+++ b/editor/registry-view.vala
@@ -175,12 +175,10 @@ class RegistryView : Grid, BrowsableView
     {
         ClickableListBoxRow row;
         SettingObject setting_object = (SettingObject) item;
-        ulong on_delete_call_handler;
 
         if (setting_object is Directory)
         {
             row = new FolderListBoxRow (setting_object.name, setting_object.full_name, 
setting_object.parent_path);
-            on_delete_call_handler = row.on_delete_call.connect (() => browser_view.reset_directory 
((Directory) setting_object, true));
         }
         else
         {
@@ -193,7 +191,7 @@ class RegistryView : Grid, BrowsableView
             KeyListBoxRow key_row = (KeyListBoxRow) row;
             key_row.small_keys_list_rows = _small_keys_list_rows;
 
-            on_delete_call_handler = row.on_delete_call.connect (() => modifications_handler.set_key_value 
(key, null));
+            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));
 
@@ -204,6 +202,7 @@ 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);
                 });
         }
@@ -211,7 +210,6 @@ class RegistryView : Grid, BrowsableView
         ulong button_press_event_handler = row.button_press_event.connect (on_button_pressed);
 
         row.destroy.connect (() => {
-                row.disconnect (on_delete_call_handler);
                 row.disconnect (button_press_event_handler);
             });
 
@@ -358,7 +356,10 @@ class RegistryView : Grid, BrowsableView
         if (selected_row == null)
             return;
 
-        ((ClickableListBoxRow) ((!) selected_row).get_child ()).on_delete_call ();
+        if (!(((!) selected_row).get_child () is KeyListBoxRow))
+            assert_not_reached ();
+
+        ((KeyListBoxRow) ((!) selected_row).get_child ()).on_delete_call ();
     }
 
     public void discard_row_popover ()


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