[dconf-editor] Rework search exit.



commit 0bab99621e15bfea530a15f68100bbdadaf3ae59
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Fri Feb 16 15:28:33 2018 +0100

    Rework search exit.

 editor/browser-stack.vala |   48 +++++++-------------------------------------
 editor/browser-view.vala  |    5 ----
 editor/dconf-window.vala  |   23 +++++++++++++++++---
 editor/registry-view.vala |    6 -----
 4 files changed, 27 insertions(+), 55 deletions(-)
---
diff --git a/editor/browser-stack.vala b/editor/browser-stack.vala
index deac0ba..4ba1907 100644
--- a/editor/browser-stack.vala
+++ b/editor/browser-stack.vala
@@ -26,7 +26,6 @@ class BrowserStack : Grid
     [GtkChild] private RegistrySearch search_results_view;
 
     public ViewType current_view { get; private set; default = ViewType.FOLDER; }
-    private ViewType pre_search_view = ViewType.SEARCH; // means "not in search"
 
     public bool small_keys_list_rows
     {
@@ -63,8 +62,7 @@ class BrowserStack : Grid
     {
         browse_view.set_key_model (key_model);
 
-        stack.set_transition_type (is_ancestor && pre_search_view == ViewType.SEARCH ? 
StackTransitionType.CROSSFADE : StackTransitionType.NONE);
-        pre_search_view = ViewType.SEARCH;
+        stack.set_transition_type (is_ancestor && current_view != ViewType.SEARCH ? 
StackTransitionType.CROSSFADE : StackTransitionType.NONE);
     }
 
     public void select_row (string selected, string last_context)
@@ -81,54 +79,24 @@ class BrowserStack : Grid
     {
         properties_view.populate_properties_list_box (key);
 
-        stack.set_transition_type (is_parent && pre_search_view == ViewType.SEARCH ? 
StackTransitionType.CROSSFADE : StackTransitionType.NONE);
-        pre_search_view = ViewType.SEARCH;
-    }
-
-    public void hide_search_view ()
-    {
-        if (pre_search_view != ViewType.SEARCH)
-        {
-            stack.set_transition_type (StackTransitionType.NONE);
-            current_view = pre_search_view;
-            pre_search_view = ViewType.SEARCH;
-
-            if (current_view == ViewType.FOLDER)
-            {
-                stack.set_visible_child (browse_view);
-                browse_view.focus_selected_row ();
-            }
-            else if (current_view == ViewType.OBJECT)
-                stack.set_visible_child (properties_view);
-            else
-                assert_not_reached ();
-        }
-        search_results_view.stop_search ();
+        stack.set_transition_type (is_parent && current_view != ViewType.SEARCH ? 
StackTransitionType.CROSSFADE : StackTransitionType.NONE);
     }
 
     public void set_path (ViewType type, string path)
     {
+        if (current_view == ViewType.SEARCH && type != ViewType.SEARCH)
+            search_results_view.stop_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 // (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);
-            }
+            stack.set_transition_type (StackTransitionType.NONE);
+            stack.set_visible_child (search_results_view);
         }
     }
 
diff --git a/editor/browser-view.vala b/editor/browser-view.vala
index c56c052..9f6eb3a 100644
--- a/editor/browser-view.vala
+++ b/editor/browser-view.vala
@@ -171,11 +171,6 @@ class BrowserView : Grid
         last_context = (key is GSettingsKey) ? ((GSettingsKey) key).schema_id : ".dconf";
     }
 
-    public void hide_search_view ()
-    {
-        current_child.hide_search_view ();
-    }
-
     public void set_path (ViewType type, string path)
     {
         current_child.set_path (type, path);
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index a7ba330..8fb3b31 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -37,7 +37,9 @@ class DConfWindow : ApplicationWindow
 {
     private ViewType current_type = ViewType.FOLDER;
     private string current_path = "/";
+    private ViewType saved_type = ViewType.FOLDER;
     private string saved_view = "/";
+    private string saved_selection = "";
 
     private SettingsModel model = new SettingsModel ();
     private ModificationsHandler modifications_handler;
@@ -602,10 +604,19 @@ class DConfWindow : ApplicationWindow
 
     private void update_current_path (ViewType type, string path)
     {
-        current_type = type;
-        current_path = path;
         if (type != ViewType.SEARCH)
+        {
+            saved_type = type;
             saved_view = path;
+        }
+        else if (current_type == ViewType.FOLDER)
+            saved_selection = browser_view.get_selected_row_name ();
+        else if (current_type == ViewType.OBJECT)
+            saved_selection = "";
+
+        current_type = type;
+        current_path = path;
+
         browser_view.set_path (type, path);
         bookmarks_button.set_path (type, path);
         pathbar.set_path (type, path);
@@ -679,14 +690,18 @@ class DConfWindow : ApplicationWindow
     [GtkCallback]
     private void search_cancelled ()
     {
+        if (!search_bar.search_mode_enabled)
+            return;
         hide_search_view ();
     }
 
     private void hide_search_view ()
     {
         reload_search_action.set_enabled (false);
-        current_path = saved_view;
-        browser_view.hide_search_view ();
+        if (saved_type == ViewType.FOLDER)
+            request_folder_path (saved_view, saved_selection);
+        else
+            update_current_path (saved_type, strdup (saved_view));
         reload_search_next = true;
     }
 
diff --git a/editor/registry-view.vala b/editor/registry-view.vala
index a44b197..864c609 100644
--- a/editor/registry-view.vala
+++ b/editor/registry-view.vala
@@ -182,12 +182,6 @@ class RegistryView : RegistryList
         return false;
     }
 
-    public void focus_selected_row ()
-    {
-        ListBoxRow? selected_row = key_list_box.get_selected_row ();
-        if (selected_row != null)
-            ((!) selected_row).grab_focus ();
-    }
     public void select_row_named (string selected, string context, bool grab_focus)
     {
         check_resize ();


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