From 8f177facdc2187d85295697cde9004ed283e8c6a Mon Sep 17 00:00:00 2001
From: Alexander Schwinn <alexxcons@xfce.org>
Date: Tue, 19 May 2020 01:14:24 +0200
Subject: [PATCH] re-enable file-selection after create/rename (Issue #293)

---
 thunar/thunar-launcher.c      | 27 +++++++++++++++++++++++----
 thunar/thunar-standard-view.c | 29 +++++++++++++++++++++--------
 thunar/thunar-view.c          | 17 +++++++++++++++++
 thunar/thunar-view.h          |  6 ++++++
 thunar/thunar-window.c        |  9 ++++++++-
 5 files changed, 75 insertions(+), 13 deletions(-)

diff --git a/thunar/thunar-launcher.c b/thunar/thunar-launcher.c
index e8dadae87..210c77155 100644
--- a/thunar/thunar-launcher.c
+++ b/thunar/thunar-launcher.c
@@ -70,6 +70,7 @@ enum
   PROP_SELECTED_FILES,
   PROP_UI_MANAGER,
   PROP_WIDGET,
+  PROP_SELECT_FILES_CLOSURE,
   N_PROPERTIES
 };
 
@@ -193,6 +194,7 @@ struct _ThunarLauncher
   ThunarFile             *single_folder;
   ThunarFile             *parent_folder;
 
+  GClosure               *select_files_closure;
 
   ThunarPreferences      *preferences;
 
@@ -302,6 +304,18 @@ thunar_launcher_class_init (ThunarLauncherClass *klass)
                            GTK_TYPE_WIDGET,
                            EXO_PARAM_WRITABLE);
 
+  /**
+   * ThunarLauncher:select-files-closure:
+   *
+   * The #GClosure which will be called if the selected file should be updated after a launcher operation
+   **/
+  launcher_props[PROP_SELECT_FILES_CLOSURE] =
+     g_param_spec_pointer ("select-files-closure",
+                           "select-files-closure",
+                           "select-files-closure",
+                           G_PARAM_WRITABLE
+                           | G_PARAM_CONSTRUCT_ONLY);
+
   /* Override ThunarNavigator's properties */
   g_iface = g_type_default_interface_peek (THUNAR_TYPE_NAVIGATOR);
   launcher_props[PROP_CURRENT_DIRECTORY] =
@@ -362,6 +376,7 @@ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
 G_GNUC_END_IGNORE_DEPRECATIONS
 
   launcher->selected_files = NULL;
+  launcher->select_files_closure = NULL;
 
   /* grab a reference on the preferences */
   launcher->preferences = thunar_preferences_get ();
@@ -462,6 +477,10 @@ thunar_launcher_set_property (GObject      *object,
       thunar_launcher_set_widget (launcher, g_value_get_object (value));
       break;
 
+    case PROP_SELECT_FILES_CLOSURE:
+      launcher->select_files_closure = g_value_get_pointer (value);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -1879,7 +1898,7 @@ thunar_launcher_action_make_link (ThunarLauncher *launcher)
    */
   application = thunar_application_get ();
   thunar_application_link_into (application, launcher->widget, g_files,
-                                thunar_file_get_file (launcher->current_directory), NULL);
+                                thunar_file_get_file (launcher->current_directory), launcher->select_files_closure);
   g_object_unref (G_OBJECT (application));
   g_list_free (g_files);
 }
@@ -1908,7 +1927,7 @@ thunar_launcher_action_duplicate (ThunarLauncher *launcher)
        */
       application = thunar_application_get ();
       thunar_application_copy_into (application, launcher->widget, selected_files,
-                                    thunar_file_get_file (launcher->current_directory), NULL);
+                                    thunar_file_get_file (launcher->current_directory), launcher->select_files_closure);
       g_object_unref (G_OBJECT (application));
 
       /* clean up */
@@ -2099,7 +2118,7 @@ thunar_launcher_action_create_folder (ThunarLauncher *launcher)
 
       /* launch the operation */
       application = thunar_application_get ();
-      thunar_application_mkdir (application, launcher->widget, &path_list, NULL);
+      thunar_application_mkdir (application, launcher->widget, &path_list, launcher->select_files_closure);
       g_object_unref (G_OBJECT (application));
 
       /* release the path */
@@ -2423,7 +2442,7 @@ thunar_launcher_action_paste_into_folder (ThunarLauncher *launcher)
 
   /* paste files from the clipboard to the folder */
   clipboard = thunar_clipboard_manager_get_for_display (gtk_widget_get_display (launcher->widget));
-  thunar_clipboard_manager_paste_files (clipboard, thunar_file_get_file (folder_to_paste), launcher->widget, NULL);
+  thunar_clipboard_manager_paste_files (clipboard, thunar_file_get_file (folder_to_paste), launcher->widget, launcher->select_files_closure);
   g_object_unref (G_OBJECT (clipboard));
 }
 
diff --git a/thunar/thunar-standard-view.c b/thunar/thunar-standard-view.c
index 95ede0e85..36c1648a2 100644
--- a/thunar/thunar-standard-view.c
+++ b/thunar/thunar-standard-view.c
@@ -115,9 +115,9 @@ static void                 thunar_standard_view_unrealize                  (Gtk
 static void                 thunar_standard_view_grab_focus                 (GtkWidget                *widget);
 static gboolean             thunar_standard_view_draw                       (GtkWidget                *widget,
                                                                              cairo_t                  *cr);
-static GList               *thunar_standard_view_get_selected_files         (ThunarComponent          *component);
-static void                 thunar_standard_view_set_selected_files         (ThunarComponent          *component,
-                                                                             GList                    *selected_files);
+static GList               *thunar_standard_view_get_selected_files_component         (ThunarComponent          *component);
+static void                 thunar_standard_view_set_selected_files_component         (ThunarComponent          *component,
+                                                                                       GList                    *selected_files);
 static GtkUIManager        *thunar_standard_view_get_ui_manager             (ThunarComponent          *component);
 static void                 thunar_standard_view_set_ui_manager             (ThunarComponent          *component,
                                                                              GtkUIManager             *ui_manager);
@@ -161,6 +161,9 @@ static void                 thunar_standard_view_current_directory_destroy  (Thu
                                                                              ThunarStandardView       *standard_view);
 static void                 thunar_standard_view_current_directory_changed  (ThunarFile               *current_directory,
                                                                              ThunarStandardView       *standard_view);
+static GList               *thunar_standard_view_get_selected_files_view    (ThunarView               *view);
+static void                 thunar_standard_view_set_selected_files_view    (ThunarView               *view,
+                                                                             GList                    *selected_files);
 static void                 thunar_standard_view_action_select_all_files    (GtkAction                *action,
                                                                              ThunarStandardView       *standard_view);
 static void                 thunar_standard_view_action_select_by_pattern   (GtkAction                *action,
@@ -543,8 +546,8 @@ thunar_standard_view_class_init (ThunarStandardViewClass *klass)
 static void
 thunar_standard_view_component_init (ThunarComponentIface *iface)
 {
-  iface->get_selected_files = thunar_standard_view_get_selected_files;
-  iface->set_selected_files = thunar_standard_view_set_selected_files;
+  iface->get_selected_files = thunar_standard_view_get_selected_files_component;
+  iface->set_selected_files = thunar_standard_view_set_selected_files_component;
   iface->get_ui_manager = thunar_standard_view_get_ui_manager;
   iface->set_ui_manager = thunar_standard_view_set_ui_manager;
 }
@@ -573,6 +576,8 @@ thunar_standard_view_view_init (ThunarViewIface *iface)
   iface->reload = thunar_standard_view_reload;
   iface->get_visible_range = thunar_standard_view_get_visible_range;
   iface->scroll_to_file = thunar_standard_view_scroll_to_file;
+  iface->get_selected_files = thunar_standard_view_get_selected_files_view;
+  iface->set_selected_files = thunar_standard_view_set_selected_files_view;
 }
 
 
@@ -1087,16 +1092,24 @@ thunar_standard_view_draw (GtkWidget      *widget,
 
 
 static GList*
-thunar_standard_view_get_selected_files (ThunarComponent *component)
+thunar_standard_view_get_selected_files_component (ThunarComponent *component)
 {
   return THUNAR_STANDARD_VIEW (component)->priv->selected_files;
 }
 
 
 
+static GList*
+thunar_standard_view_get_selected_files_view (ThunarView *view)
+{
+  return THUNAR_STANDARD_VIEW (view)->priv->selected_files;
+}
+
+
+
 static void
-thunar_standard_view_set_selected_files (ThunarComponent *component,
-                                         GList           *selected_files)
+thunar_standard_view_set_selected_files_component (ThunarComponent *component,
+                                                   GList           *selected_files)
 {
   ThunarStandardView *standard_view = THUNAR_STANDARD_VIEW (component);
   GtkTreePath        *first_path = NULL;
diff --git a/thunar/thunar-view.c b/thunar/thunar-view.c
index d2a15616f..6f7e604ee 100644
--- a/thunar/thunar-view.c
+++ b/thunar/thunar-view.c
@@ -324,3 +324,20 @@ thunar_view_scroll_to_file (ThunarView *view,
 }
 
 
+
+GList*
+thunar_view_get_selected_files (ThunarView *view)
+{
+  _thunar_return_val_if_fail (THUNAR_IS_VIEW (view), NULL);
+  return (*THUNAR_VIEW_GET_IFACE (view)->get_selected_files) (view);
+}
+
+
+
+void
+thunar_view_set_selected_files (ThunarView *view,
+                                GList      *path_list)
+{
+  _thunar_return_if_fail (THUNAR_IS_VIEW (view));
+  (*THUNAR_VIEW_GET_IFACE (view)->set_selected_files) (view, path_list);
+}
diff --git a/thunar/thunar-view.h b/thunar/thunar-view.h
index 9aa62f3d4..3a6f6a049 100644
--- a/thunar/thunar-view.h
+++ b/thunar/thunar-view.h
@@ -64,6 +64,9 @@ struct _ThunarViewIface
                                          gboolean        use_align,
                                          gfloat          row_align,
                                          gfloat          col_align);
+  GList*          (*get_selected_files) (ThunarView     *view);
+  void            (*set_selected_files) (ThunarView     *view,
+                                         GList          *path_list);
 };
 
 GType           thunar_view_get_type            (void) G_GNUC_CONST;
@@ -93,6 +96,9 @@ void            thunar_view_scroll_to_file      (ThunarView     *view,
                                                  gboolean        use_align,
                                                  gfloat          row_align,
                                                  gfloat          col_align);
+GList*          thunar_view_get_selected_files  (ThunarView     *view);
+void            thunar_view_set_selected_files  (ThunarView     *view,
+                                                 GList          *path_list);
 
 G_END_DECLS;
 
diff --git a/thunar/thunar-window.c b/thunar/thunar-window.c
index 29464ea1a..dbfcb7490 100644
--- a/thunar/thunar-window.c
+++ b/thunar/thunar-window.c
@@ -1022,7 +1022,14 @@ static void
 thunar_window_select_files (ThunarWindow *window,
                             GList        *files_to_selected)
 {
-  // TODO: Select Files
+  GList *thunarFiles = NULL;
+
+  _thunar_return_if_fail (THUNAR_IS_WINDOW (window));
+
+  for (GList *lp = files_to_selected; lp != NULL; lp = lp->next)
+      thunarFiles = g_list_append (thunarFiles, thunar_file_get (G_FILE (files_to_selected->data), NULL));
+  thunar_view_set_selected_files (THUNAR_VIEW (window->view), thunarFiles);
+  g_list_free_full (thunarFiles, g_object_unref);
 }
 
 
-- 
GitLab