From e1e9b662ce8b685bfa1c1f012709749955a7d49d Mon Sep 17 00:00:00 2001 From: weyfonk Date: Tue, 13 Sep 2016 10:40:50 +0100 Subject: [PATCH] Detailed view: focus nearest file after deletion (Bug 9870) This commit fixes bug #9870: when deleting files in detailed list view, the focus would go back to the first element of the list, thus scrolling back to the top, which made this view poorly usable when dealing with large amounts of files. The selection is now backed up in thunar-standard-view.c --- thunar/thunar-standard-view.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/thunar/thunar-standard-view.c b/thunar/thunar-standard-view.c index 6b078e3..aeb5e01 100644 --- a/thunar/thunar-standard-view.c +++ b/thunar/thunar-standard-view.c @@ -2505,9 +2505,32 @@ thunar_standard_view_unlink_selection (ThunarStandardView *standard_view, gboolean permanently) { ThunarApplication *application; + GList *paths; + GList *lp; + GtkTreePath *first_selected_path; _thunar_return_if_fail (THUNAR_IS_STANDARD_VIEW (standard_view)); + /* Get tree paths of all selected files */ + paths = thunar_list_model_get_paths_for_files (standard_view->model, + standard_view->priv->selected_files); + + /* determine the path of the first selected file */ + for (first_selected_path = paths->data, lp = paths; lp != NULL; lp = lp->next) + { + /* check if this path is located before the current first_selected_path */ + if (gtk_tree_path_compare (lp->data, first_selected_path) < 0) + first_selected_path = lp->data; + } + + /* Remember the first selected path to be removed so that the selection can be restored + * after the deletion. If the first row of the view is removed, select the first row + * after the selection; otherwise, select the row before that one */ + if (G_UNLIKELY (!gtk_tree_path_prev (first_selected_path))) + { + first_selected_path = gtk_tree_path_new_first (); + } + /* delete the selected files */ application = thunar_application_get (); thunar_application_unlink_files (application, GTK_WIDGET (standard_view), @@ -2515,7 +2538,8 @@ thunar_standard_view_unlink_selection (ThunarStandardView *standard_view, permanently); g_object_unref (G_OBJECT (application)); - /* do not select new files */ + /* do not select new files, but place the cursor on the selected path */ + (*THUNAR_STANDARD_VIEW_GET_CLASS (standard_view)->set_cursor) (standard_view, first_selected_path, FALSE); thunar_component_set_selected_files (THUNAR_COMPONENT (standard_view), NULL); } -- 2.9.3