[dconf-editor] Rework first row selection.



commit 50089e81ef7b18daf593d7215e2de73511f4c6f5
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Sat Jan 5 16:12:21 2019 +0100

    Rework first row selection.
    
    Now that the first row of the keys list is a navigation helper,
    it feels good to select it, when there is no logical selection.

 editor/browser-content.vala |  3 ++-
 editor/browser-stack.vala   | 24 +++++++++++++-----------
 editor/browser-view.vala    |  7 +++++--
 editor/browser-window.vala  |  2 +-
 editor/registry-list.vala   |  3 ++-
 editor/registry-search.vala |  2 +-
 editor/registry-view.vala   | 17 +++++------------
 7 files changed, 29 insertions(+), 29 deletions(-)
---
diff --git a/editor/browser-content.vala b/editor/browser-content.vala
index 3495dd8..42f2f1b 100644
--- a/editor/browser-content.vala
+++ b/editor/browser-content.vala
@@ -30,7 +30,8 @@ private interface BrowserContent : Widget, AdaptativeWidget
     \*/
 
     internal abstract string get_selected_row_name ();
-    internal abstract void select_row (string selected, uint16 last_context_id, bool grab_focus_if_needed);
+    internal abstract void select_row_named (string selected, uint16 last_context_id, bool 
grab_focus_if_needed);
+    internal abstract void select_first_row ();
     internal abstract void row_grab_focus ();
     /*\
     * * popovers
diff --git a/editor/browser-stack.vala b/editor/browser-stack.vala
index 4ebb22c..b630a73 100644
--- a/editor/browser-stack.vala
+++ b/editor/browser-stack.vala
@@ -93,20 +93,22 @@ private class BrowserStack : Grid, AdaptativeWidget, BrowserContent
         stack.set_transition_type (is_ancestor && current_view != ViewType.SEARCH ? 
StackTransitionType.CROSSFADE : StackTransitionType.NONE);
     }
 
-    internal void select_row (string selected, uint16 last_context_id, bool grab_focus_if_needed)
+    internal void select_row_named (string selected, uint16 last_context_id, bool grab_focus_if_needed)
         requires (ViewType.displays_objects_list (current_view))
+        requires (selected != "")
     {
-        if (selected == "")
-        {
-            if (current_view == ViewType.SEARCH)
-                ((RegistrySearch) stack.get_visible_child ()).select_first_row ();
-            else if (current_view == ViewType.FOLDER)
-                ((RegistryView) stack.get_visible_child ()).select_first_row (grab_focus_if_needed);
-            else
-                assert_not_reached ();
-        }
+        ((RegistryList) stack.get_visible_child ()).select_row_named (selected, last_context_id, 
(current_view == ViewType.FOLDER) && grab_focus_if_needed);
+    }
+
+    internal void select_first_row ()
+        requires (ViewType.displays_objects_list (current_view))
+    {
+        if (current_view == ViewType.SEARCH)
+            ((RegistrySearch) stack.get_visible_child ()).select_first_row ();
+        else if (current_view == ViewType.FOLDER)
+            ((RegistryView) stack.get_visible_child ()).select_first_row ();
         else
-            ((RegistryList) stack.get_visible_child ()).select_row_named (selected, last_context_id, 
(current_view == ViewType.FOLDER) && grab_focus_if_needed);
+            assert_not_reached ();
     }
 
     internal void prepare_object_view (string full_name, uint16 context_id, Variant properties, bool 
is_parent)
diff --git a/editor/browser-view.vala b/editor/browser-view.vala
index c01d558..3fd8574 100644
--- a/editor/browser-view.vala
+++ b/editor/browser-view.vala
@@ -138,10 +138,13 @@ private class BrowserView : BaseView, AdaptativeWidget
         hide_reload_warning ();
     }
 
-    internal void select_row (string selected)
+    internal void select_row (string selected_or_empty)
         requires (ViewType.displays_objects_list (current_view))
     {
-        browser_content.select_row (selected, last_context_id, !is_in_in_window_mode ());
+        if (selected_or_empty == "")
+            browser_content.select_first_row ();
+        else
+            browser_content.select_row_named (selected_or_empty, last_context_id, !is_in_in_window_mode ());
     }
 
     internal void prepare_object_view (string full_name, uint16 context_id, Variant properties, bool 
is_parent)
diff --git a/editor/browser-window.vala b/editor/browser-window.vala
index e8e2917..40d2898 100644
--- a/editor/browser-window.vala
+++ b/editor/browser-window.vala
@@ -19,7 +19,7 @@ using Gtk;
 
 private abstract class BrowserWindow : BaseWindow
 {
-    private const string root_path = "/";   // TODO allow changing that
+    protected const string root_path    = "/";   // TODO allow changing that
 
     protected string    current_path    = root_path;
     protected ViewType  current_type    = ViewType.FOLDER;
diff --git a/editor/registry-list.vala b/editor/registry-list.vala
index 5e38392..c6d4b8d 100644
--- a/editor/registry-list.vala
+++ b/editor/registry-list.vala
@@ -70,12 +70,13 @@ private abstract class RegistryList : Grid, BrowsableView, AdaptativeWidget
             });
     }
 
-    protected void select_row_and_if_true_grab_focus (ListBoxRow row, bool grab_focus)
+    private void select_row_and_if_true_grab_focus (ListBoxRow row, bool grab_focus)
     {
         key_list_box.select_row (row);
         if (grab_focus)
             row.grab_focus ();
     }
+    internal abstract void select_first_row ();
 
     private enum ScrollToRowBehaviour {
         CENTER,
diff --git a/editor/registry-search.vala b/editor/registry-search.vala
index aba7c94..fb85ffd 100644
--- a/editor/registry-search.vala
+++ b/editor/registry-search.vala
@@ -35,7 +35,7 @@ private class RegistrySearch : RegistryList
     * * Simple public calls
     \*/
 
-    internal void select_first_row ()
+    internal override void select_first_row ()
     {
         if (old_term != null)   //happens when pasting an invalid path
             _select_first_row (key_list_box, (!) old_term);
diff --git a/editor/registry-view.vala b/editor/registry-view.vala
index 31cf1cd..e0ff379 100644
--- a/editor/registry-view.vala
+++ b/editor/registry-view.vala
@@ -90,29 +90,22 @@ private class RegistryView : RegistryList
         return false;
     }
 
-    internal void select_first_row (bool grab_focus_if_needed)
+    internal override void select_first_row ()
     {
         uint n_items = list_model.get_n_items ();
         if (n_items == 0)
             assert_not_reached ();
 
         ListBoxRow? row;
-        if (n_items == 1)
-            row = key_list_box.get_row_at_index (0);
-        else if (n_items == 2)
+        if (n_items == 2)
             row = key_list_box.get_row_at_index (1);
         else
-        {
-            SimpleSettingObject sso = (SimpleSettingObject) list_model.get_object (n_items - 1);
+            row = key_list_box.get_row_at_index (0);
 
-            if (ModelUtils.is_folder_context_id (sso.context_id)) // if do not contain at least one key
-                row = key_list_box.get_row_at_index (1);
-            else
-                row = key_list_box.get_row_at_index (0);
-        }
         if (row == null)
             assert_not_reached ();
-        select_row_and_if_true_grab_focus ((!) row, grab_focus_if_needed);
+        key_list_box.select_row ((!) row);
+        ((!) row).grab_focus ();
     }
 
     /*\


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