[nautilus/wip/antoniof/view-focus-bugs: 2/2] list-base: Restore ability to move selection from sushi




commit 2cf7867a3b17d00475f53741961907de76e8d3c2
Author: António Fernandes <antoniof gnome org>
Date:   Sun Sep 11 17:56:34 2022 +0100

    list-base: Restore ability to move selection from sushi
    
    Sushi emits a SelectionEvent signal when the arrow keys are pressed.
    We listen to this signal to change selection in the view accordingly.
    
    Unfortunately, the new view widgets do not implement a "move-cursor"
    keybinding signal, so this is not working.
    
    Partially resolve this regression by implementing the selection move
    ourselves. This has a change in behaviour, however: up and down keys
    do not move up and down in a grid, but instead move to the previous
    and next items, respectively.

 src/nautilus-list-base.c | 38 +++++++++++++++++++++++++++++---------
 1 file changed, 29 insertions(+), 9 deletions(-)
---
diff --git a/src/nautilus-list-base.c b/src/nautilus-list-base.c
index f4673b9d3..75df65879 100644
--- a/src/nautilus-list-base.c
+++ b/src/nautilus-list-base.c
@@ -1597,17 +1597,37 @@ real_preview_selection_event (NautilusFilesView *files_view,
                               GtkDirectionType   direction)
 {
     NautilusListBase *self = NAUTILUS_LIST_BASE (files_view);
-    GtkMovementStep step;
-    gint count;
-    gboolean handled;
+    NautilusListBasePrivate *priv = nautilus_list_base_get_instance_private (self);
+    guint i;
+    gboolean rtl = (gtk_widget_get_direction (GTK_WIDGET (self)) == GTK_TEXT_DIR_RTL);
 
-    step = (direction == GTK_DIR_UP || direction == GTK_DIR_DOWN) ?
-           GTK_MOVEMENT_DISPLAY_LINES : GTK_MOVEMENT_VISUAL_POSITIONS;
-    count = (direction == GTK_DIR_RIGHT || direction == GTK_DIR_DOWN) ?
-            1 : -1;
+    i = get_first_selected_item (self);
+    if (direction == GTK_DIR_UP ||
+        direction == (rtl ? GTK_DIR_RIGHT : GTK_DIR_LEFT))
+    {
+        if (i == 0)
+        {
+            /* We are at the start of the list, can't move up. */
+            gtk_widget_error_bell (GTK_WIDGET (self));
+            return;
+        }
+
+        i--;
+    }
+    else
+    {
+        i++;
+
+        if (i >= g_list_model_get_n_items (G_LIST_MODEL (priv->model)))
+        {
+            /* We are at the end of the list, can't move down. */
+            gtk_widget_error_bell (GTK_WIDGET (self));
+            return;
+        }
+    }
 
-    g_signal_emit_by_name (nautilus_list_base_get_view_ui (self),
-                           "move-cursor", step, count, &handled);
+    gtk_selection_model_select_item (GTK_SELECTION_MODEL (priv->model), i, TRUE);
+    set_focus_item (self, g_list_model_get_item (G_LIST_MODEL (priv->model), i));
 }
 
 static void


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