From 3b485c3d7c8b1705cde851863d796f1f01fe2e62 Mon Sep 17 00:00:00 2001
From: Alexander Schwinn <alexxcons@xfce.org>
Date: Sun, 14 Mar 2021 16:32:50 +0100
Subject: [PATCH] Reload current directory before selecting new files (Issue
 #524)

In order to make sure that all new files are added to the view before
selection.

Fixes #524
Fixes #287
Partly fixes #272
---
 thunar/thunar-window.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/thunar/thunar-window.c b/thunar/thunar-window.c
index 82301e5a3..7eec6e12d 100644
--- a/thunar/thunar-window.c
+++ b/thunar/thunar-window.c
@@ -921,14 +921,23 @@ static void
 thunar_window_select_files (ThunarWindow *window,
                             GList        *files_to_selected)
 {
-  GList *thunarFiles = NULL;
+  GList        *thunar_files = NULL;
+  ThunarFolder *thunar_folder;
 
   _thunar_return_if_fail (THUNAR_IS_WINDOW (window));
 
+  /* If possible, reload the current directory to make sure new files got added to the view */
+  thunar_folder = thunar_folder_get_for_file (window->current_directory);
+  if (thunar_folder != NULL)
+    {
+      thunar_folder_reload (thunar_folder, FALSE);
+      g_object_unref (thunar_folder);
+    }
+
   for (GList *lp = files_to_selected; lp != NULL; lp = lp->next)
-      thunarFiles = g_list_append (thunarFiles, thunar_file_get (G_FILE (lp->data), NULL));
-  thunar_view_set_selected_files (THUNAR_VIEW (window->view), thunarFiles);
-  g_list_free_full (thunarFiles, g_object_unref);
+    thunar_files = g_list_append (thunar_files, thunar_file_get (G_FILE (lp->data), NULL));
+  thunar_view_set_selected_files (THUNAR_VIEW (window->view), thunar_files);
+  g_list_free_full (thunar_files, g_object_unref);
 }
 
 
-- 
GitLab