[nautilus/antonioffix-menus-and-popovers: 10/14] list-view: Reveal the focused or last selected item
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/antonioffix-menus-and-popovers: 10/14] list-view: Reveal the focused or last selected item
- Date: Tue, 23 Jan 2018 16:34:10 +0000 (UTC)
commit b6ab0bcf0b16a2b721b996d7598b5a2630b4cfac
Author: António Fernandes <antoniof gnome org>
Date: Thu Jan 11 19:57:41 2018 +0000
list-view: Reveal the focused or last selected item
Currently we always reveal the first item on behalf of the
whole selection.
This may result in the revealed item being the last visible
row, hiding the presence of more other selected items bellow
it. Also, when selecting multiple items in their display order,
the first item may already be out of view, but there is no need
to scroll because the most recently selected item is probably
still focused and visible.
Instead, try to reveal the focused item, if it is part of the
selection, and fallback to the lowest sorted selected item
otherwise.
src/nautilus-list-view.c | 58 +++++++++++++++++++++++++-----------------------
1 file changed, 30 insertions(+), 28 deletions(-)
---
diff --git a/src/nautilus-list-view.c b/src/nautilus-list-view.c
index 1435890d1..1027ec21a 100644
--- a/src/nautilus-list-view.c
+++ b/src/nautilus-list-view.c
@@ -1092,23 +1092,18 @@ test_expand_row_callback (GtkTreeView *tree_view,
}
static void
-get_revealed_rectangle (NautilusFilesView *view,
- GdkRectangle *rect)
+get_revealed_rectangle (NautilusListView *list_view,
+ GtkTreePath *path,
+ GdkRectangle *rect)
{
- GtkTreeSelection *selection;
- GtkTreePath *path;
- GtkTreeModel *model;
GtkTreeView *tree_view;
- GList *list;
- NautilusListView *list_view;
- list_view = NAUTILUS_LIST_VIEW (view);
- tree_view = list_view->details->tree_view;
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (list_view->details->tree_view));
- model = GTK_TREE_MODEL (list_view->details->model);
- list = gtk_tree_selection_get_selected_rows (selection, &model);
- path = list->data;
- gtk_tree_view_get_cell_area (tree_view, path, list_view->details->file_name_column, rect);
+ tree_view = GTK_TREE_VIEW(list_view->details->tree_view);
+
+ gtk_tree_view_get_cell_area (tree_view,
+ path,
+ list_view->details->file_name_column,
+ rect);
gtk_tree_view_convert_bin_window_to_widget_coords (tree_view,
rect->x, rect->y,
&rect->x, &rect->y);
@@ -1119,8 +1114,6 @@ get_revealed_rectangle (NautilusFilesView *view,
rect->width = 0;
}
- g_list_free_full (list, (GDestroyNotify) gtk_tree_path_free);
-
/* FIXME Due to smooth scrolling, we get the cell area while the view is
* still scrolling (and still outside the view), not at the final position
* of the cell after scrolling.
@@ -1139,7 +1132,7 @@ get_revealed_rectangle (NautilusFilesView *view,
rect->y = CLAMP (rect->y,
header_height,
- gtk_widget_get_allocated_height (GTK_WIDGET (view)) - rect->height);
+ gtk_widget_get_allocated_height (GTK_WIDGET (list_view)) - rect->height);
}
}
@@ -1147,7 +1140,7 @@ static void
nautilus_list_view_reveal_selection (NautilusFilesView *view,
GdkRectangle *revealed_area)
{
- GList *selection;
+ g_autoptr (GList) selection = NULL;
g_return_if_fail (NAUTILUS_IS_LIST_VIEW (view));
@@ -1157,28 +1150,37 @@ nautilus_list_view_reveal_selection (NautilusFilesView *view,
if (selection != NULL)
{
NautilusListView *list_view;
- NautilusFile *file;
- GtkTreeIter iter;
+ GtkTreeView *tree_view;
+ GtkTreeSelection *tree_selection;
GtkTreePath *path;
list_view = NAUTILUS_LIST_VIEW (view);
- file = selection->data;
- if (nautilus_list_model_get_first_iter_for_file (list_view->details->model, file, &iter))
+ tree_view = GTK_TREE_VIEW (list_view->details->tree_view);
+ tree_selection = gtk_tree_view_get_selection (tree_view);
+
+ /* Get the path to the last focused item, if selected. Otherwise, get
+ * the path to the lowest sorted selected item.*/
+ gtk_tree_view_get_cursor (tree_view, &path, NULL);
+ if (!path || !gtk_tree_selection_path_is_selected (tree_selection, path))
{
- path = gtk_tree_model_get_path (GTK_TREE_MODEL (list_view->details->model), &iter);
+ GList *list;
- gtk_tree_view_scroll_to_cell (list_view->details->tree_view, path, NULL, FALSE, 0.0, 0.0);
+ list = gtk_tree_selection_get_selected_rows (tree_selection, NULL);
+ list = g_list_last (list);
+ path = g_steal_pointer(&list->data);
- gtk_tree_path_free (path);
+ g_list_free_full (list, (GDestroyNotify) gtk_tree_path_free);
}
+ gtk_tree_view_scroll_to_cell (tree_view, path, NULL, FALSE, 0.0, 0.0);
+
if (revealed_area)
{
- get_revealed_rectangle (view, revealed_area);
+ get_revealed_rectangle (list_view, path, revealed_area);
}
- }
- nautilus_file_list_free (selection);
+ gtk_tree_path_free (path);
+ }
}
static gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]