[dconf-editor] Maintain selection on search start.



commit 220be34ba2978b106487fc7cdd66476e98b83b6e
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Sun Feb 18 22:00:12 2018 +0100

    Maintain selection on search start.

 editor/browser-stack.vala   |   18 ++++-------
 editor/browser-view.vala    |    2 +-
 editor/dconf-window.vala    |    2 +
 editor/registry-search.vala |    4 +-
 editor/registry-view.vala   |   68 ++++++++++++++++++++++---------------------
 5 files changed, 47 insertions(+), 47 deletions(-)
---
diff --git a/editor/browser-stack.vala b/editor/browser-stack.vala
index 7151c65..ce0d2db 100644
--- a/editor/browser-stack.vala
+++ b/editor/browser-stack.vala
@@ -64,12 +64,12 @@ class BrowserStack : Grid
     }
 
     public void select_row (string selected, string last_context)
-        requires (current_view == ViewType.FOLDER)
+        requires (current_view != ViewType.OBJECT)
     {
         if (selected == "")
-            folder_view.select_first_row ();
+            ((RegistryList) stack.get_visible_child ()).select_first_row ();
         else
-            folder_view.select_row_named (selected, last_context);
+            ((RegistryList) stack.get_visible_child ()).select_row_named (selected, last_context, 
current_view == ViewType.FOLDER);
     }
 
     public void prepare_object_view (Key key, bool is_parent)
@@ -179,19 +179,15 @@ class BrowserStack : Grid
 
     public bool up_pressed ()
     {
-        if (current_view == ViewType.FOLDER)
-            return folder_view.up_or_down_pressed (false);
-        if (current_view == ViewType.SEARCH)
-            return search_view.up_or_down_pressed (false);
+        if (current_view != ViewType.OBJECT)
+            return ((RegistryList) stack.get_visible_child ()).up_or_down_pressed (false);
         return false;
     }
 
     public bool down_pressed ()
     {
-        if (current_view == ViewType.FOLDER)
-            return folder_view.up_or_down_pressed (true);
-        if (current_view == ViewType.SEARCH)
-            return search_view.up_or_down_pressed (true);
+        if (current_view != ViewType.OBJECT)
+            return ((RegistryList) stack.get_visible_child ()).up_or_down_pressed (true);
         return false;
     }
 }
diff --git a/editor/browser-view.vala b/editor/browser-view.vala
index 0705b08..598297b 100644
--- a/editor/browser-view.vala
+++ b/editor/browser-view.vala
@@ -160,7 +160,7 @@ class BrowserView : Grid
     }
 
     public void select_row (string selected)
-        requires (current_view == ViewType.FOLDER)
+        requires (current_view != ViewType.OBJECT)
     {
         current_child.select_row (selected, last_context);
     }
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index 3486d8e..57da62e 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -599,7 +599,9 @@ class DConfWindow : ApplicationWindow
             browser_view.set_search_parameters (current_path, bookmarks_button.get_bookmarks ());
             reload_search_next = false;
         }
+        string selected_row = browser_view.get_selected_row_name ();
         update_current_path (ViewType.SEARCH, search_entry.text);
+        browser_view.select_row (selected_row);
     }
 
     private void reload_view ()
diff --git a/editor/registry-search.vala b/editor/registry-search.vala
index 720c37e..112a54c 100644
--- a/editor/registry-search.vala
+++ b/editor/registry-search.vala
@@ -42,7 +42,7 @@ class RegistrySearch : RegistryList
             select_first_row ();
     }
 
-    private void select_first_row ()
+    public override void select_first_row ()
     {
         ListBoxRow? row = key_list_box.get_row_at_index (0);
         if (row != null)
@@ -146,7 +146,7 @@ class RegistrySearch : RegistryList
         return true;
     }
 
-    public bool up_or_down_pressed (bool is_down)
+    public override bool up_or_down_pressed (bool is_down)
     {
         ListBoxRow? selected_row = key_list_box.get_selected_row ();
         uint n_items = list_model.get_n_items ();
diff --git a/editor/registry-view.vala b/editor/registry-view.vala
index a9c3fd6..270becd 100644
--- a/editor/registry-view.vala
+++ b/editor/registry-view.vala
@@ -18,7 +18,7 @@
 using Gtk;
 
 [GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/registry-view.ui")]
-class RegistryList : Grid, BrowsableView
+private abstract class RegistryList : Grid, BrowsableView
 {
     [GtkChild] protected ListBox key_list_box;
     [GtkChild] protected RegistryPlaceholder placeholder;
@@ -79,6 +79,37 @@ class RegistryList : Grid, BrowsableView
             return "";
     }
 
+    public abstract void select_first_row ();
+
+    public void select_row_named (string selected, string context, bool grab_focus)
+    {
+        check_resize ();
+        ListBoxRow? row = key_list_box.get_row_at_index (get_row_position (selected, context));
+        if (row != null)
+            scroll_to_row ((!) row, grab_focus);
+    }
+    private int get_row_position (string selected, string context)
+    {
+        uint position = 0;
+        uint fallback = 0;
+        while (position < list_model.get_n_items ())
+        {
+            SettingObject object = (SettingObject) list_model.get_object (position);
+            if (object.full_name == selected)
+            {
+                if (object is Directory
+                 || context == ".dconf" && object is DConfKey // theorical?
+                 || object is GSettingsKey && ((GSettingsKey) object).schema_id == context)
+                    return (int) position;
+                fallback = position;
+            }
+            position++;
+        }
+        return (int) fallback; // selected row may have been removed or context could be ""
+    }
+
+    public abstract bool up_or_down_pressed (bool is_down);
+
     /*\
     * * Keyboard calls
     \*/
@@ -192,40 +223,11 @@ class RegistryView : RegistryList
         return false;
     }
 
-    public void select_row_named (string selected, string context)
+    public override void select_first_row ()
     {
-        bool grab_focus = true;     // unused, for now
-        check_resize ();
-        ListBoxRow? row = key_list_box.get_row_at_index (get_row_position (selected, context));
-        if (row == null)
-            assert_not_reached ();
-        scroll_to_row ((!) row, grab_focus);
-    }
-    public void select_first_row ()
-    {
-        bool grab_focus = true;     // unused, for now
         ListBoxRow? row = key_list_box.get_row_at_index (0);
         if (row != null)
-            scroll_to_row ((!) row, grab_focus);
-    }
-    private int get_row_position (string selected, string context)
-    {
-        uint position = 0;
-        uint fallback = 0;
-        while (position < list_model.get_n_items ())
-        {
-            SettingObject object = (SettingObject) list_model.get_object (position);
-            if (object.full_name == selected)
-            {
-                if (object is Directory
-                 || context == ".dconf" && object is DConfKey // theorical?
-                 || object is GSettingsKey && ((GSettingsKey) object).schema_id == context)
-                    return (int) position;
-                fallback = position;
-            }
-            position++;
-        }
-        return (int) fallback; // selected row may have been removed or context could be ""
+            scroll_to_row ((!) row, true);
     }
 
     /*\
@@ -327,7 +329,7 @@ class RegistryView : RegistryList
         return false;
     }
 
-    public bool up_or_down_pressed (bool is_down)
+    public override bool up_or_down_pressed (bool is_down)
     {
         ListBoxRow? selected_row = key_list_box.get_selected_row ();
         uint n_items = list_model.get_n_items ();


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