[dconf-editor] Rework search init.



commit 2a51bdcef0ef1e849eea7750a419aeeb315ff776
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Fri Feb 16 12:22:19 2018 +0100

    Rework search init.

 editor/browser-stack.vala   |    8 ++++----
 editor/browser-view.vala    |    8 ++++----
 editor/dconf-window.vala    |   32 ++++++++++++++++++++------------
 editor/registry-search.vala |   13 ++++++++-----
 4 files changed, 36 insertions(+), 25 deletions(-)
---
diff --git a/editor/browser-stack.vala b/editor/browser-stack.vala
index e4aaaf9..28956b5 100644
--- a/editor/browser-stack.vala
+++ b/editor/browser-stack.vala
@@ -85,9 +85,9 @@ class BrowserStack : Grid
         pre_search_view = ViewType.SEARCH;
     }
 
-    public void show_search_view (string term, string current_path, string [] bookmarks, SortingOptions 
sorting_options)
+    public void show_search_view (string term)
     {
-        search_results_view.start_search (term, current_path, bookmarks, sorting_options);
+        search_results_view.start_search (term);
         if (pre_search_view == ViewType.SEARCH)
         {
             stack.set_transition_type (StackTransitionType.NONE);
@@ -187,9 +187,9 @@ class BrowserStack : Grid
     * * Reload
     \*/
 
-    public void reload_search (string current_path, string [] bookmarks, SortingOptions sorting_options)
+    public void set_search_parameters (string current_path, string [] bookmarks, SortingOptions 
sorting_options)
     {
-        search_results_view.reload_search (current_path, bookmarks, sorting_options);
+        search_results_view.set_search_parameters (current_path, bookmarks, sorting_options);
     }
 
     public bool check_reload_folder (GLib.ListStore fresh_key_model)
diff --git a/editor/browser-view.vala b/editor/browser-view.vala
index 6f9b55f..9c79499 100644
--- a/editor/browser-view.vala
+++ b/editor/browser-view.vala
@@ -171,9 +171,9 @@ class BrowserView : Grid
         last_context = (key is GSettingsKey) ? ((GSettingsKey) key).schema_id : ".dconf";
     }
 
-    public void show_search_view (string term, string current_path, string [] bookmarks)
+    public void show_search_view (string term)
     {
-        current_child.show_search_view (term, current_path, bookmarks, sorting_options);
+        current_child.show_search_view (term);
     }
 
     public void hide_search_view ()
@@ -203,10 +203,10 @@ class BrowserView : Grid
             info_bar.show_warning ("soft-reload-folder");
     }
 
-    public void reload_search (string current_path, string [] bookmarks)
+    public void set_search_parameters (string current_path, string [] bookmarks)
     {
         hide_reload_warning ();
-        current_child.reload_search (current_path, bookmarks, sorting_options);
+        current_child.set_search_parameters (current_path, bookmarks, sorting_options);
     }
 
     public bool check_reload (ViewType type, string path, bool show_infobar)
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index 736c4b5..6113a72 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -356,6 +356,7 @@ class DConfWindow : ApplicationWindow
     \*/
 
     private SimpleAction reload_search_action;
+    private bool reload_search_next = true;
 
     private void install_action_entries ()
     {
@@ -460,8 +461,7 @@ class DConfWindow : ApplicationWindow
 
     private void reload_search (/* SimpleAction action, Variant? path_variant */)
     {
-        reload_search_action.set_enabled (false);
-        browser_view.reload_search (current_path, bookmarks_button.get_bookmarks ());
+        set_search_parameters ();
     }
 
     private void reset_recursively (SimpleAction action, Variant? path_variant)
@@ -592,7 +592,7 @@ class DConfWindow : ApplicationWindow
         else if (browser_view.current_view == ViewType.OBJECT)
             request_object_path (current_path, "", false);
         else if (browser_view.current_view == ViewType.SEARCH)
-            browser_view.reload_search (current_path, bookmarks_button.get_bookmarks ());
+            browser_view.set_search_parameters (current_path, bookmarks_button.get_bookmarks ());
     }
 
     /*\
@@ -663,24 +663,32 @@ class DConfWindow : ApplicationWindow
     {
         if (!search_bar.search_mode_enabled)
         {
-            reload_search_action.set_enabled (false);
-            browser_view.hide_search_view ();
+            hide_search_view ();
             return;
         }
-        if (reload_search_action.get_enabled ())
-        {
-            reload_search_action.set_enabled (false);
-            browser_view.reload_search (current_path, bookmarks_button.get_bookmarks ());
-        }
-        // do not place in an "else"
-        browser_view.show_search_view (search_entry.text, current_path, bookmarks_button.get_bookmarks ());
+        if (reload_search_next)
+            set_search_parameters ();
+        browser_view.show_search_view (search_entry.text);
     }
 
     [GtkCallback]
     private void search_cancelled ()
     {
+        hide_search_view ();
+    }
+
+    private void hide_search_view ()
+    {
         reload_search_action.set_enabled (false);
         browser_view.hide_search_view ();
+        reload_search_next = true;
+    }
+
+    private void set_search_parameters ()
+    {
+        reload_search_action.set_enabled (false);
+        browser_view.set_search_parameters (current_path, bookmarks_button.get_bookmarks ());
+        reload_search_next = false;
     }
 
     /*\
diff --git a/editor/registry-search.vala b/editor/registry-search.vala
index dfde708..22e42c5 100644
--- a/editor/registry-search.vala
+++ b/editor/registry-search.vala
@@ -20,6 +20,8 @@ using Gtk;
 class RegistrySearch : RegistryList
 {
     private string current_path;
+    private string [] bookmarks;
+    private SortingOptions sorting_options;
 
     public ModificationsHandler modifications_handler { private get; set; }
 
@@ -229,10 +231,8 @@ class RegistrySearch : RegistryList
         old_term = null;
     }
 
-    public void start_search (string term, string _current_path, string [] bookmarks, SortingOptions 
sorting_options)
+    public void start_search (string term)
     {
-        current_path = _current_path;
-
         if (old_term != null && term == (!) old_term)
         {
             ensure_selection ();
@@ -457,10 +457,13 @@ class RegistrySearch : RegistryList
         row.set_header (header);
     }
 
-    public void reload_search (string current_path, string [] bookmarks, SortingOptions sorting_options)
+    public void set_search_parameters (string current_path, string [] bookmarks, SortingOptions 
sorting_options)
     {
         string term = old_term ?? "";
         stop_search ();
-        start_search (term, current_path, bookmarks, sorting_options);
+        this.current_path = current_path;
+        this.bookmarks = bookmarks;
+        this.sorting_options = sorting_options;
+        start_search (term);
     }
 }


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