[dconf-editor] Use set_path for search.



commit 87a2e88d497a2a96720073974f898ddbeb2ca672
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Fri Feb 16 13:46:57 2018 +0100

    Use set_path for search.

 editor/bookmarks.vala     |    4 +++-
 editor/browser-stack.vala |   34 ++++++++++++++++++----------------
 editor/browser-view.vala  |    6 ------
 editor/dconf-window.vala  |   12 +++++++++---
 editor/pathbar.vala       |    5 +++--
 5 files changed, 33 insertions(+), 28 deletions(-)
---
diff --git a/editor/bookmarks.vala b/editor/bookmarks.vala
index 968dcbd..7b96160 100644
--- a/editor/bookmarks.vala
+++ b/editor/bookmarks.vala
@@ -54,8 +54,10 @@ public class Bookmarks : MenuButton
     \*/
 
     public void set_path (ViewType type, string path)
-        requires (type != ViewType.SEARCH)
     {
+        if (type == ViewType.SEARCH)
+            return;
+
         if (current_path != path)
             current_path = path;
         update_icon_and_switch ();
diff --git a/editor/browser-stack.vala b/editor/browser-stack.vala
index 28956b5..deac0ba 100644
--- a/editor/browser-stack.vala
+++ b/editor/browser-stack.vala
@@ -85,18 +85,6 @@ class BrowserStack : Grid
         pre_search_view = ViewType.SEARCH;
     }
 
-    public void show_search_view (string term)
-    {
-        search_results_view.start_search (term);
-        if (pre_search_view == ViewType.SEARCH)
-        {
-            stack.set_transition_type (StackTransitionType.NONE);
-            pre_search_view = current_view;
-            current_view = ViewType.SEARCH;
-            stack.set_visible_child (search_results_view);
-        }
-    }
-
     public void hide_search_view ()
     {
         if (pre_search_view != ViewType.SEARCH)
@@ -119,15 +107,29 @@ class BrowserStack : Grid
     }
 
     public void set_path (ViewType type, string path)
-        requires (type != ViewType.SEARCH)
     {
-        current_view = type;
         if (type == ViewType.FOLDER)
+        {
+            current_view = type;
             stack.set_visible_child (browse_view);
+        }
         else if (type == ViewType.OBJECT)
+        {
+            current_view = type;
             stack.set_visible_child (properties_view);
-        else
-            assert_not_reached ();
+        }
+        else // (type == ViewType.SEARCH)
+        {
+            search_results_view.start_search (path);
+            if (pre_search_view == ViewType.SEARCH)
+            {
+                stack.set_transition_type (StackTransitionType.NONE);
+                pre_search_view = current_view;
+
+                current_view = type;
+                stack.set_visible_child (search_results_view);
+            }
+        }
     }
 
     public string? get_copy_text ()
diff --git a/editor/browser-view.vala b/editor/browser-view.vala
index 9c79499..c56c052 100644
--- a/editor/browser-view.vala
+++ b/editor/browser-view.vala
@@ -171,18 +171,12 @@ class BrowserView : Grid
         last_context = (key is GSettingsKey) ? ((GSettingsKey) key).schema_id : ".dconf";
     }
 
-    public void show_search_view (string term)
-    {
-        current_child.show_search_view (term);
-    }
-
     public void hide_search_view ()
     {
         current_child.hide_search_view ();
     }
 
     public void set_path (ViewType type, string path)
-        requires (type != ViewType.SEARCH)
     {
         current_child.set_path (type, path);
         modifications_handler.path_changed ();
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index 6113a72..984af21 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -37,6 +37,7 @@ class DConfWindow : ApplicationWindow
 {
     private ViewType current_type = ViewType.FOLDER;
     private string current_path = "/";
+    private string saved_view = "/";
 
     private SettingsModel model = new SettingsModel ();
     private ModificationsHandler modifications_handler;
@@ -342,7 +343,7 @@ class DConfWindow : ApplicationWindow
         settings.disconnect (small_bookmarks_rows_handler);
 
         settings.delay ();
-        settings.set_string ("saved-view", current_path);
+        settings.set_string ("saved-view", saved_view);
         settings.set_int ("window-width", window_width);
         settings.set_int ("window-height", window_height);
         settings.set_boolean ("window-is-maximized", window_is_maximized);
@@ -600,10 +601,11 @@ class DConfWindow : ApplicationWindow
     \*/
 
     private void update_current_path (ViewType type, string path)
-        requires (type != ViewType.SEARCH)
     {
         current_type = type;
         current_path = path;
+        if (type != ViewType.SEARCH)
+            saved_view = path;
         browser_view.set_path (type, path);
         bookmarks_button.set_path (type, path);
         pathbar.set_path (type, path);
@@ -612,6 +614,9 @@ class DConfWindow : ApplicationWindow
 
     private void update_hamburger_menu ()
     {
+        if (search_bar.search_mode_enabled)
+            return;
+
         GLib.Menu section;
 
         GLib.Menu menu = new GLib.Menu ();
@@ -668,7 +673,7 @@ class DConfWindow : ApplicationWindow
         }
         if (reload_search_next)
             set_search_parameters ();
-        browser_view.show_search_view (search_entry.text);
+        update_current_path (ViewType.SEARCH, search_entry.text);
     }
 
     [GtkCallback]
@@ -680,6 +685,7 @@ class DConfWindow : ApplicationWindow
     private void hide_search_view ()
     {
         reload_search_action.set_enabled (false);
+        current_path = saved_view;
         browser_view.hide_search_view ();
         reload_search_next = true;
     }
diff --git a/editor/pathbar.vala b/editor/pathbar.vala
index fd1ff06..02545ab 100644
--- a/editor/pathbar.vala
+++ b/editor/pathbar.vala
@@ -34,9 +34,10 @@ public class PathBar : Box
     \*/
 
     public void set_path (ViewType type, string path)
-        requires (path [0] == '/')
-//        requires (type != ViewType.SEARCH)    // FIXME makes the app crash at startup, for no reason
     {
+        if (type == ViewType.SEARCH)
+            return;
+
         activate_item (root_button, path == "/");
 
         complete_path = "";


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