[dconf-editor] Rework "need reload" detection



commit 125a144b58ce5ad5a7653040bce2e8fc6bddcd90
Author: Davi da Silva Böger <dsboger gmail com>
Date:   Tue Dec 12 18:28:54 2017 -0200

    Rework "need reload" detection
    
    Actually compare the content of the current view with fresh content from
    the model. Does not rely on comparing coinciding paths, as that does not
    give enough information to decide (notably it is not possible to know
    from DConf.Client if a path notified as changed has been created or not).
    
    If the view is stale, either reload directly (when it is known that the
    changes are from inside Dconf Editor) or show the "need reload" infobar.
    
    Remove a forced reload in RegistryView when a DConfKey is "ghosted".

 editor/browser-view.vala    |   48 +++++++++++++++++++++++++++++++++++++-----
 editor/dconf-window.vala    |   16 +-------------
 editor/registry-info.vala   |   12 +++++++++-
 editor/registry-search.vala |    7 ++++++
 editor/registry-view.vala   |   19 +++++++++++++++++
 5 files changed, 80 insertions(+), 22 deletions(-)
---
diff --git a/editor/browser-view.vala b/editor/browser-view.vala
index ab2f43b..99a6ef4 100644
--- a/editor/browser-view.vala
+++ b/editor/browser-view.vala
@@ -380,14 +380,50 @@ class BrowserView : Grid, PathElement
     }
 
     [GtkCallback]
-    public void reload ()
+    private void reload ()
     {
-        string? saved_selection = browse_view.get_selected_row_name ();
-        Directory? directory = window.model.get_directory (current_path);
-        if (directory == null)
-            request_path (current_path); // rely on fallback detection
+        if (current_view_is_browse_view ())
+        {
+            string? saved_selection = browse_view.get_selected_row_name ();
+            Directory? directory = window.model.get_directory (current_path);
+            if (directory == null)
+                request_path (current_path); // rely on fallback detection
+            else
+                set_directory ((!) directory, saved_selection);
+        }
+        else if (current_view_is_properties_view ())
+            request_path (current_path); // TODO better
+        else if (current_view_is_search_results_view ())
+        {
+            hide_reload_warning ();
+            search_results_view.reload_search ();
+        }
+    }
+
+    public void check_reload (bool internal_changes)
+    {
+        if (current_view_is_properties_view ())
+        {
+            Key? fresh_key = (Key?) modifications_handler.model.get_object (current_path);
+            if (fresh_key != null && !properties_view.check_reload ((!) fresh_key, 
modifications_handler.model.get_key_value ((!) fresh_key)))
+                return;
+        }
+        else if (current_view_is_browse_view ())
+        {
+            Directory? fresh_dir = (Directory?) modifications_handler.model.get_directory (current_path);
+            GLib.ListStore? fresh_key_model = modifications_handler.model.get_children (fresh_dir);
+            if (fresh_key_model != null)
+            {
+                sorting_options.sort_key_model ((!) fresh_key_model); // RegistryView.check_reload assumes 
the same order as the current view for faster comparison
+                if (!browse_view.check_reload ((!) fresh_dir, (!) fresh_key_model))
+                    return;
+            }
+        } // search_results_view always reloads
+
+        if (internal_changes)
+            reload ();
         else
-            set_directory ((!) directory, saved_selection);
+            show_hard_reload_warning ();
     }
 }
 
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index 3869fec..cd489bc 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -82,21 +82,7 @@ class DConfWindow : ApplicationWindow
         modifications_handler = new ModificationsHandler (model);
         browser_view.modifications_handler = modifications_handler;
         model.paths_changed.connect ((_model, modified_path_specs, internal_changes) => {
-                bool current_path_modified = false;
-                bool is_key_path = SettingsModel.is_key_path (current_path);
-                string[] current_path_segments = is_key_path ? SettingsModel.to_segments 
(SettingsModel.get_parent_path (current_path)) : SettingsModel.to_segments (current_path);
-                modified_path_specs.foreach ((path_spec) => {
-                        string[] spec_segments = SettingsModel.to_segments (path_spec);
-                        if (SettingsModel.match_prefix (spec_segments, current_path_segments) && 
spec_segments.length == current_path_segments.length)
-                            current_path_modified = true;
-                    });
-                if (current_path_modified)
-                {
-                    if (internal_changes)
-                        browser_view.reload ();
-                    else
-                        browser_view.show_hard_reload_warning ();
-                }
+                browser_view.check_reload (internal_changes);
             });
 
         if (!disable_warning && settings.get_boolean ("show-warning"))
diff --git a/editor/registry-info.vala b/editor/registry-info.vala
index f859850..7cd684d 100644
--- a/editor/registry-info.vala
+++ b/editor/registry-info.vala
@@ -30,6 +30,8 @@ class RegistryInfo : Grid, BrowsableView
 
     public ModificationsHandler modifications_handler { private get; set; }
 
+    private Variant? current_key_info;
+
     /*\
     * * Cleaning
     \*/
@@ -66,6 +68,7 @@ class RegistryInfo : Grid, BrowsableView
 
         bool has_schema;
         unowned Variant [] dict_container;
+        current_key_info = key.properties;
         key.properties.get ("(ba{ss})", out has_schema, out dict_container);
 
         multiple_schemas_warning_revealer.set_reveal_child (has_schema && warning_multiple_schemas);
@@ -99,7 +102,7 @@ class RegistryInfo : Grid, BrowsableView
         Label label = new Label (get_current_value_text (has_schema && 
modifications_handler.model.is_key_default ((GSettingsKey) key), key));
         ulong key_value_changed_handler = key.value_changed.connect (() => {
                 if (!has_schema && modifications_handler.model.is_key_ghost ((DConfKey) key))
-                    ((BrowserView) DConfWindow._get_parent (DConfWindow._get_parent (this))).request_path 
(parent_path);
+                    label.set_text (_("Key erased."));
                 else
                     label.set_text (get_current_value_text (has_schema && 
modifications_handler.model.is_key_default ((GSettingsKey) key), key));
             });
@@ -348,6 +351,13 @@ class RegistryInfo : Grid, BrowsableView
         context.add_class ("warning-label");
         return (Widget) label;
     }
+
+    public bool check_reload (Key fresh_key, Variant fresh_value)
+    {
+        if (current_key_info == null) // should not happen?
+            return true;
+        return !((!) current_key_info).equal (fresh_key.properties); // TODO compare fresh_value with editor 
value?
+    }
 }
 
 [GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/property-row.ui")]
diff --git a/editor/registry-search.vala b/editor/registry-search.vala
index 5754168..0adc0d3 100644
--- a/editor/registry-search.vala
+++ b/editor/registry-search.vala
@@ -611,4 +611,11 @@ class RegistrySearch : Grid, PathElement, BrowsableView
         ListBoxRowHeader header = new ListBoxRowHeader (before == null, label_text);
         row.set_header (header);
     }
+
+    public void reload_search ()
+    {
+        string term = old_term ?? "";
+        stop_search ();
+        start_search (term);
+    }
 }
diff --git a/editor/registry-view.vala b/editor/registry-view.vala
index dc95ddd..94895df 100644
--- a/editor/registry-view.vala
+++ b/editor/registry-view.vala
@@ -76,6 +76,25 @@ class RegistryView : Grid, PathElement, BrowsableView
         key_list_box.bind_model (key_model, new_list_box_row);
     }
 
+    public bool check_reload (Directory fresh_dir, GLib.ListStore fresh_key_model)
+    {
+        if (key_model == null) // should not happen?
+            return true;
+        if (((!) key_model).get_n_items () != fresh_key_model.get_n_items ())
+            return true;
+        for (uint i = 0; i < ((!) key_model).get_n_items (); i++)
+        {
+            SettingObject setting_object = (SettingObject) ((!) key_model).get_item (i);
+            SettingObject fresh_setting_object = (SettingObject) fresh_key_model.get_item (i);
+            if (setting_object.get_type () != fresh_setting_object.get_type ())
+                return true;
+            if (setting_object.name != fresh_setting_object.name)
+                return true;
+            // TODO compare other visible info (i.e. key summary and value)
+        }
+        return false;
+    }
+
     public void show_multiple_schemas_warning (bool multiple_schemas_warning_needed)
     {
         multiple_schemas_warning_revealer.set_reveal_child (multiple_schemas_warning_needed);


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