[dconf-editor] Unduplicate stuff.



commit 5d8f365156c7f48e5338534a221a905956ceabbc
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Wed Dec 19 22:28:42 2018 +0100

    Unduplicate stuff.

 editor/model-utils.vala     |   5 +++
 editor/registry-search.vala | 103 ++++++++++++++++----------------------------
 2 files changed, 42 insertions(+), 66 deletions(-)
---
diff --git a/editor/model-utils.vala b/editor/model-utils.vala
index 39c90b8..ba6776d 100644
--- a/editor/model-utils.vala
+++ b/editor/model-utils.vala
@@ -182,6 +182,11 @@ namespace ModelUtils
         return path.slice (0, path.last_index_of_char ('/') + 1);
     }
 
+    internal static string get_name_or_empty (string path)
+    {
+        return path.slice (path.last_index_of_char ('/') + 1, path.length);
+    }
+
     internal static string get_name (string path)
     {
         if (path.length <= 1)
diff --git a/editor/registry-search.vala b/editor/registry-search.vala
index 7028580..342af4c 100644
--- a/editor/registry-search.vala
+++ b/editor/registry-search.vala
@@ -220,53 +220,56 @@ private class RegistrySearch : RegistryList
 
                 insert_first_row ((!) current_path_if_search_mode, fallback_context_id, ref list_model);
 
-                post_local = 1;
-                paths_search (model, term, ref list_model, ref post_local);
+                local_search (model, sorting_options, (!) current_path_if_search_mode, 
ModelUtils.get_name_or_empty (term), ref list_model);
+                post_local = (int) list_model.get_n_items ();
 
                 key_list_box.bind_model (list_model, new_list_box_row);
                 _select_first_row (key_list_box, term);
             }
             model.keys_value_push ();
         }
-        else if (old_term_is_term_prefix)
+        else
         {
-            pause_global_search (ref search_source);
-            refine_local_results (term, ref list_model, ref post_local, ref post_bookmarks, ref 
post_folders);
-            refine_bookmarks_results (term, post_local, ref list_model, ref post_bookmarks, ref 
post_folders);
-            if ((!) old_term == "")
-                start_global_search ((!) current_path_if_search_mode, term);
-            else
+            if (old_term_is_term_prefix)
             {
-                refine_global_results (term, post_bookmarks, ref list_model, ref post_folders);
-                resume_global_search ((!) current_path_if_search_mode, term); // update search term
-            }
+                pause_global_search (ref search_source);
+                refine_local_results (term, ref list_model, ref post_local, ref post_bookmarks, ref 
post_folders);
+                refine_bookmarks_results (term, post_local, ref list_model, ref post_bookmarks, ref 
post_folders);
+                if ((!) old_term == "")
+                    start_global_search ((!) current_path_if_search_mode, term);
+                else
+                {
+                    refine_global_results (term, post_bookmarks, ref list_model, ref post_folders);
+                    resume_global_search ((!) current_path_if_search_mode, term); // update search term
+                }
 
-            ensure_selection (key_list_box, term);
+                ensure_selection (key_list_box, term);
 
-            model.keys_value_push ();
-        }
-        else
-        {
-            search_is_path_search = false;
+                model.keys_value_push ();
+            }
+            else
+            {
+                search_is_path_search = false;
 
-            model.clean_watched_keys ();
-            stop_global_search ();
+                model.clean_watched_keys ();
+                stop_global_search ();
 
-            insert_first_row ((!) current_path_if_search_mode, fallback_context_id, ref list_model);
+                insert_first_row ((!) current_path_if_search_mode, fallback_context_id, ref list_model);
 
-            local_search    (model, sorting_options, ModelUtils.get_base_path ((!) 
current_path_if_search_mode), term, ref list_model);
-            post_local      = (int) list_model.get_n_items ();
-            post_bookmarks  = post_local;
-            bookmark_search (model, (!) current_path_if_search_mode, term, bookmarks, ref list_model, ref 
post_bookmarks);
-            post_folders    = post_bookmarks;
+                local_search    (model, sorting_options, ModelUtils.get_base_path ((!) 
current_path_if_search_mode), term, ref list_model);
+                post_local      = (int) list_model.get_n_items ();
+                post_bookmarks  = post_local;
+                bookmark_search (model, (!) current_path_if_search_mode, term, bookmarks, ref list_model, 
ref post_bookmarks);
+                post_folders    = post_bookmarks;
 
-            key_list_box.bind_model (list_model, new_list_box_row);
-            _select_first_row (key_list_box, term);
+                key_list_box.bind_model (list_model, new_list_box_row);
+                _select_first_row (key_list_box, term);
 
-            model.keys_value_push ();
+                model.keys_value_push ();
 
-            if (term != "")
-                start_global_search ((!) current_path_if_search_mode, term);
+                if (term != "")
+                    start_global_search ((!) current_path_if_search_mode, term);
+            }
         }
         old_term = term;
     }
@@ -369,13 +372,13 @@ private class RegistrySearch : RegistryList
     private static void local_search (SettingsModel model, SortingOptions sorting_options, string 
current_path, string term, ref GLib.ListStore list_model)
         requires (ModelUtils.is_folder_path (current_path))
     {
-        SettingComparator comparator = sorting_options.get_comparator ();
-        GLib.CompareDataFunc compare = (a, b) => comparator.compare ((SimpleSettingObject) a, 
(SimpleSettingObject) b);
-
         Variant? key_model = model.get_children (current_path, true, false); // here to update watched keys 
even coming from RegistryInfo
         if (key_model == null)
             return;
 
+        SettingComparator comparator = sorting_options.get_comparator ();
+        GLib.CompareDataFunc compare = (a, b) => comparator.compare ((SimpleSettingObject) a, 
(SimpleSettingObject) b);
+
         VariantIter iter = new VariantIter ((!) key_model);
         uint16 context_id;
         string name;
@@ -389,38 +392,6 @@ private class RegistrySearch : RegistryList
         }
     }
 
-    private static void paths_search (SettingsModel model, string term, ref GLib.ListStore list_model, ref 
int post_local)
-    {
-        string base_path = ModelUtils.get_base_path (term);
-
-        Variant? key_model = model.get_children (base_path, true, false);
-        if (key_model == null)
-            return;
-
-        uint16 context_id;
-        string name;
-
-        int post_subfolders = post_local;
-        VariantIter iter = new VariantIter ((!) key_model);
-        while (iter.next ("(qs)", out context_id, out name))
-        {
-            bool is_folder = context_id == ModelUtils.folder_context_id;
-            string full_name = ModelUtils.recreate_full_name (base_path, name, is_folder);
-            if (term in full_name)
-            {
-                SimpleSettingObject sso = new SimpleSettingObject.from_full_name (context_id, name, 
full_name);
-                if (is_folder)
-                {
-                    list_model.insert (post_subfolders, sso);
-                    post_subfolders++;
-                }
-                else
-                    list_model.insert (post_local, sso);
-                post_local++;
-            }
-        }
-    }
-
     private static void bookmark_search (SettingsModel model, string current_path, string term, string [] 
bookmarks, ref GLib.ListStore list_model, ref int post_bookmarks)
     {
         foreach (string bookmark in bookmarks)


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