diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c index 761700e..e9e4847 100644 --- a/thunar/thunar-file.c +++ b/thunar/thunar-file.c @@ -1819,7 +1819,19 @@ thunar_file_launch (ThunarFile *file, return succeed; } +void +thunar_file_rename_notify (ThunarFile *file, + GFile *renamed_file) +{ + _thunar_return_if_fail (THUNAR_IS_FILE (file)); + /* notify the file is renamed */ + if (renamed_file) + thunar_file_monitor_moved (file, renamed_file); + + /* emit the file changed signal */ + thunar_file_changed (file); +} /** * thunar_file_rename: @@ -1836,6 +1848,10 @@ thunar_file_launch (ThunarFile *file, * should first check whether the file is available, using the * thunar_file_is_renameable() method. * + * @renamed_file_out must be non-NULL when @called_from_job is %TRUE. + * thunar_file_rename_notify must be called in the context of the main thread + * if the return value is %TRUE. + * * Return value: %TRUE on success, else %FALSE. **/ gboolean @@ -1843,7 +1859,8 @@ thunar_file_rename (ThunarFile *file, const gchar *name, GCancellable *cancellable, gboolean called_from_job, - GError **error) + GError **error, + GFile **renamed_file_out) { GKeyFile *key_file; GError *err = NULL; @@ -1934,16 +1951,20 @@ thunar_file_rename (ThunarFile *file, /* check if we succeeded */ if (renamed_file != NULL) { - /* notify the file is renamed */ - thunar_file_monitor_moved (file, renamed_file); - - g_object_unref (G_OBJECT (renamed_file)); - if (!called_from_job) { + /* notify the file is renamed */ + thunar_file_monitor_moved (file, renamed_file); + + g_object_unref (G_OBJECT (renamed_file)); + /* emit the file changed signal */ thunar_file_changed (file); } + else + { + *renamed_file_out = renamed_file; + } return TRUE; } diff --git a/thunar/thunar-file.h b/thunar/thunar-file.h index cfc3d05..8a8a0ee 100644 --- a/thunar/thunar-file.h +++ b/thunar/thunar-file.h @@ -149,11 +149,15 @@ gboolean thunar_file_launch (ThunarFile const gchar *startup_id, GError **error); +void thunar_file_rename_notify (ThunarFile *file, + GFile *renamed_file); + gboolean thunar_file_rename (ThunarFile *file, const gchar *name, GCancellable *cancellable, gboolean called_from_job, - GError **error); + GError **error, + GFile **renamed_file_out); GdkDragAction thunar_file_accepts_drop (ThunarFile *file, GList *path_list, diff --git a/thunar/thunar-io-jobs.c b/thunar/thunar-io-jobs.c index 9d904f9..8928dc1 100644 --- a/thunar/thunar-io-jobs.c +++ b/thunar/thunar-io-jobs.c @@ -1240,24 +1240,29 @@ thunar_io_jobs_list_directory (GFile *directory) return thunar_simple_job_launch (_thunar_io_jobs_ls, 1, G_TYPE_FILE, directory); } - - static gboolean -_thunar_io_jobs_rename_notify (ThunarFile *file) +_thunar_io_jobs_rename_notify (GArray *param_values) { - _thunar_return_val_if_fail (THUNAR_IS_FILE (file), FALSE); + ThunarFile *file; + GFile *renamed_file; + + _thunar_return_val_if_fail (param_values != NULL, FALSE); + _thunar_return_val_if_fail (param_values->len == 3, FALSE); + _thunar_return_val_if_fail (G_VALUE_HOLDS (&g_array_index (param_values, GValue, 0), THUNAR_TYPE_FILE), FALSE); + _thunar_return_val_if_fail (G_VALUE_HOLDS (&g_array_index (param_values, GValue, 2), G_TYPE_OBJECT), FALSE); + + /* determine the file and display name */ + file = g_value_get_object (&g_array_index (param_values, GValue, 0)); + renamed_file = g_value_get_object (&g_array_index (param_values, GValue, 2)); /* tell the associated folder that the file was renamed */ thunarx_file_info_renamed (THUNARX_FILE_INFO (file)); - /* emit the file changed signal */ - thunar_file_changed (file); + thunar_file_rename_notify(file, renamed_file); return FALSE; } - - static gboolean _thunar_io_jobs_rename (ThunarJob *job, GArray *param_values, @@ -1266,6 +1271,8 @@ _thunar_io_jobs_rename (ThunarJob *job, const gchar *display_name; ThunarFile *file; GError *err = NULL; + GFile *renamed_file = NULL; + GValue value = { 0, }; _thunar_return_val_if_fail (THUNAR_IS_JOB (job), FALSE); _thunar_return_val_if_fail (param_values != NULL, FALSE); @@ -1282,11 +1289,14 @@ _thunar_io_jobs_rename (ThunarJob *job, display_name = g_value_get_string (&g_array_index (param_values, GValue, 1)); /* try to rename the file */ - if (thunar_file_rename (file, display_name, exo_job_get_cancellable (EXO_JOB (job)), TRUE, &err)) + if (thunar_file_rename (file, display_name, exo_job_get_cancellable (EXO_JOB (job)), TRUE, &err, &renamed_file)) { - exo_job_send_to_mainloop (EXO_JOB (job), - (GSourceFunc) _thunar_io_jobs_rename_notify, - g_object_ref (file), g_object_unref); + g_value_init (&value, G_TYPE_OBJECT); + g_value_take_object (&value, renamed_file); + g_array_append_val (param_values, value); + exo_job_send_to_mainloop (EXO_JOB (job), + (GSourceFunc) _thunar_io_jobs_rename_notify, + g_array_ref (param_values), (GDestroyNotify) g_array_unref); } /* abort on errors or cancellation */ diff --git a/thunar/thunar-renamer-progress.c b/thunar/thunar-renamer-progress.c index 73abd7e..748fff0 100644 --- a/thunar/thunar-renamer-progress.c +++ b/thunar/thunar-renamer-progress.c @@ -171,7 +171,7 @@ thunar_renamer_progress_next_idle (gpointer user_data) oldname = g_strdup (thunar_file_get_display_name (pair->file)); /* try to rename the file */ - if (!thunar_file_rename (pair->file, pair->name, NULL, FALSE, &error)) + if (!thunar_file_rename (pair->file, pair->name, NULL, FALSE, &error, NULL)) { /* determine the toplevel widget */ toplevel = (GtkWindow *) gtk_widget_get_toplevel (GTK_WIDGET (renamer_progress));