diff --git a/thunar/thunar-tree-view.c b/thunar/thunar-tree-view.c index 2d26da0..72fbae6 100644 --- a/thunar/thunar-tree-view.c +++ b/thunar/thunar-tree-view.c @@ -169,6 +169,12 @@ static GClosure *thunar_tree_view_new_files_closure (T static void thunar_tree_view_new_files (ThunarJob *job, GList *path_list, ThunarTreeView *view); +static void thunar_tree_view_new_folder_release (ThunarTreeView *view); +static void thunar_tree_view_new_folder_parent_notify (ThunarFolder *parent_folder, + GParamSpec *pspec, + ThunarTreeView *view); +static void thunar_tree_view_change_to_new_folder (ThunarTreeView *view, + GFile *path); static gboolean thunar_tree_view_visible_func (ThunarTreeModel *model, ThunarFile *file, gpointer user_data); @@ -222,6 +228,14 @@ struct _ThunarTreeView * open newly created directories once done. */ GClosure *new_files_closure; + + /* In case the parent folder was reloading in the "new-files" closure therefore we couldn't + * select the new folder, these contain the path of the new folder, a ThunarFolder for + * the parent folder, and a signal id we connected to wait for loading to finish. + */ + GFile *new_folder_path; + ThunarFolder *new_folder_parent; + gulong new_folder_signal_id; /* the currently pressed mouse button, set in the * button-press-event handler if the associated @@ -473,6 +487,10 @@ thunar_tree_view_finalize (GObject *object) g_closure_unref (view->new_files_closure); } + /* drop any existing pending new folder */ + if (view->new_folder_path) + thunar_tree_view_new_folder_release (view); + (*G_OBJECT_CLASS (thunar_tree_view_parent_class)->finalize) (object); } @@ -2160,22 +2178,118 @@ thunar_tree_view_new_files (ThunarJob *job, GList *path_list, ThunarTreeView *view) { - ThunarFile *file; + GFile *path; + GFile *parent_path; + ThunarFile *parent_file; + ThunarFolder *parent_folder; + _thunar_return_if_fail ((view->new_folder_path == NULL) == (view->new_folder_parent == NULL)); + + /* drop any existing pending new folder */ + if (view->new_folder_path) + thunar_tree_view_new_folder_release (view); + /* check if we have exactly one new path */ if (G_UNLIKELY (path_list == NULL || path_list->next != NULL)) - return; - - /* determine the file for the first path */ - file = thunar_file_cache_lookup (path_list->data); - if (G_LIKELY (file != NULL && thunar_file_is_directory (file))) + goto fail0; + + /* get new folder path */ + path = path_list->data; + + /* get parent path */ + if ((parent_path = g_file_get_parent (path)) == NULL) + goto fail0; + + /* get a ThunarFile for the parent */ + if ((parent_file = thunar_file_cache_lookup (parent_path)) == NULL) + goto fail1; + + /* get the ThunarFolder for the parent */ + parent_folder = thunar_folder_get_for_file (parent_file); + + if (thunar_folder_get_loading (parent_folder)) { - /* change to the newly created folder */ - thunar_navigator_change_directory (THUNAR_NAVIGATOR (view), file); + /* remeber the new folder path and parent ThunarFile */ + view->new_folder_path = g_file_dup (path); + view->new_folder_parent = parent_folder; + + /* be notified when the folder is done loading */ + view->new_folder_signal_id = g_signal_connect (parent_folder, "notify::loading", G_CALLBACK (thunar_tree_view_new_folder_parent_notify), view); } + else + { + /* parent is loaded, change to new folder */ + thunar_tree_view_change_to_new_folder (view, path); + + /* release parent */ + g_object_unref (parent_folder); + } + + g_object_unref (parent_file); +fail1: + g_object_unref (parent_path); +fail0:; +} + + + +static void +thunar_tree_view_new_folder_release (ThunarTreeView *view) +{ + _thunar_return_if_fail ((view->new_folder_path == NULL) == (view->new_folder_parent == NULL)); + _thunar_return_if_fail (view->new_folder_path != NULL); + + /* disconnect signal */ + g_signal_handler_disconnect (view->new_folder_parent, view->new_folder_signal_id); + + /* drop new folder path */ + g_object_unref (view->new_folder_path); + view->new_folder_path = NULL; + + /* drop new folder parent */ + g_object_unref (view->new_folder_parent); + view->new_folder_parent = NULL; +} + + + +static void +thunar_tree_view_new_folder_parent_notify (ThunarFolder *parent_folder, + GParamSpec *pspec, + ThunarTreeView *view) +{ + _thunar_return_if_fail (THUNAR_IS_FOLDER (parent_folder)); + _thunar_return_if_fail (THUNAR_IS_TREE_VIEW (view)); + _thunar_return_if_fail (parent_folder == view->new_folder_parent); + _thunar_return_if_fail ((view->new_folder_path == NULL) == (view->new_folder_parent == NULL)); + + /* finished loading? */ + if (thunar_folder_get_loading (view->new_folder_parent)) + return; + + /* parent is loaded, change to new folder */ + thunar_tree_view_change_to_new_folder (view, view->new_folder_path); + + /* drop new folder path and parent */ + thunar_tree_view_new_folder_release (view); +} + + + +static void +thunar_tree_view_change_to_new_folder (ThunarTreeView *view, + GFile *path) +{ + ThunarFile *file; + + /* lookup file in cache */ + if ((file = thunar_file_cache_lookup (path)) == NULL) + return; + + /* change to this folder */ + thunar_navigator_change_directory (THUNAR_NAVIGATOR (view), file); - if (file != NULL) - g_object_unref (file); + g_object_unref (file); }