summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXiang Fan <sfanxiang@gmail.com>2019-02-14 14:52:59 +0800
committerCarlos Soriano <csoriano1618+gnome@gmail.com>2019-02-19 09:50:50 +0000
commit335fbbc28f80bc77b79311450a16522a7ae6b337 (patch)
treeee1a6bb6126b0beb6202e7fe49042a0722d71a9a
parentd860b290115953ca1789d0e0d47749aac79b82d0 (diff)
downloadnautilus-335fbbc28f80bc77b79311450a16522a7ae6b337.tar.gz
nautilus-list-view: Clear selection and cursor in clear()
When the current cursor's row gets deleted, GTK will move the cursor to the next row, and when setting the cursor it also selects the new cursor's row, thereby triggering selection signals. The new cursor will soon be deleted again and the loop repeats. Since clear() removes all entries, those selections are useless but they take up most of the time in clear(). For example, when a search returns a large list, exiting from the search view would make nautilus hang. At the time simply removing the cursor solves the problem, but to be future-proof in case GTK does anything fancy with the current selection, this commit also removes the selection. Because GTK internally seeking the cursor takes time, only blocking the selection signal like everywhere else will not remove that overhead.
-rw-r--r--src/nautilus-list-view.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/nautilus-list-view.c b/src/nautilus-list-view.c
index e8a00f27c..9b7b7826b 100644
--- a/src/nautilus-list-view.c
+++ b/src/nautilus-list-view.c
@@ -2692,11 +2692,42 @@ static void
nautilus_list_view_clear (NautilusFilesView *view)
{
NautilusListView *list_view;
+ GtkTreeView *tree_view;
+ GtkTreeSelection *tree_selection;
+ GtkTreePath *path;
list_view = NAUTILUS_LIST_VIEW (view);
if (list_view->details->model != NULL)
{
+ tree_view = list_view->details->tree_view;
+
+ /* When the current cursor's row gets deleted, GTK will move the cursor to
+ * the next row, and when setting the cursor it also selects the new
+ * cursor's row, thereby triggering selection signals. The new cursor will
+ * soon be deleted again and the loop repeats.
+ *
+ * Since clear() removes all entries, those selections are useless but they
+ * take up most of the time in clear(). For example, when a search returns
+ * a large list, exiting from the search view would make nautilus hang.
+ *
+ * At the time the code is written simply removing the cursor solves the
+ * problem, but to be future-proof in case GTK does anything fancy with
+ * the current selection, we also remove the selection.
+ *
+ * Because GTK internally seeking the cursor takes time, only blocking the
+ * selection signal like everywhere else will not remove that overhead.
+ */
+
+ /* Clear the current selection */
+ tree_selection = gtk_tree_view_get_selection (tree_view);
+ gtk_tree_selection_unselect_all (tree_selection);
+
+ /* Clear the current cursor */
+ path = gtk_tree_path_new ();
+ gtk_tree_view_set_cursor (tree_view, path, NULL, FALSE);
+ gtk_tree_path_free (path);
+
nautilus_list_model_clear (list_view->details->model);
}
}