diff --git a/thunar/thunar-standard-view.c b/thunar/thunar-standard-view.c index 04b3287ec4d4070aaf2193e098937fb207cdea6c..f671f05082519fa479fd53c6250b1233110a43aa 100644 --- a/thunar/thunar-standard-view.c +++ b/thunar/thunar-standard-view.c @@ -323,6 +323,9 @@ struct _ThunarStandardViewPrivate gfloat scroll_to_row_align; gfloat scroll_to_col_align; + /* selected_files support */ + GList *selected_files; + /* Tree path for restoring the selection after selecting and * deleting an item */ GtkTreePath *selection_before_delete; @@ -710,6 +713,9 @@ thunar_standard_view_finalize (GObject *object) if (G_UNLIKELY (standard_view->priv->scroll_to_file != NULL)) g_object_unref (G_OBJECT (standard_view->priv->scroll_to_file)); + /* release the selected_files list (if any) */ + thunar_file_list_free (standard_view->priv->selected_files); + /* release our reference on the provider factory */ g_object_unref (G_OBJECT (standard_view->priv->provider_factory)); @@ -960,41 +966,57 @@ thunar_standard_view_set_selected_files (ThunarComponent *component, GList *paths; GList *lp; - /* verify that we have a valid model */ - if (G_UNLIKELY (standard_view->model == NULL)) - return; - - /* unselect all previously selected files */ - (*THUNAR_STANDARD_VIEW_GET_CLASS (standard_view)->unselect_all) (standard_view); + /* release the previous selected files list (if any) */ + if (G_UNLIKELY (standard_view->priv->selected_files != NULL)) + { + thunar_file_list_free (standard_view->priv->selected_files); + standard_view->priv->selected_files = NULL; + } - /* determine the tree paths for the given files */ - paths = thunar_list_model_get_paths_for_files (standard_view->model, selected_files); - if (G_LIKELY (paths != NULL)) + /* check if we're still loading */ + if (thunar_view_get_loading (THUNAR_VIEW (standard_view))) { - /* determine the first path */ - for (first_path = paths->data, lp = paths; lp != NULL; lp = lp->next) - { - /* check if this path is located before the current first_path */ - if (gtk_tree_path_compare (lp->data, first_path) < 0) - first_path = lp->data; - } + /* remember a copy of the list for later */ + standard_view->priv->selected_files = thunar_file_list_copy (selected_files); + } + else + { + /* verify that we have a valid model */ + if (G_UNLIKELY (standard_view->model == NULL)) + return; - /* place the cursor on the first selected path (must be first for GtkTreeView) */ - (*THUNAR_STANDARD_VIEW_GET_CLASS (standard_view)->set_cursor) (standard_view, first_path, FALSE); + /* unselect all previously selected files */ + (*THUNAR_STANDARD_VIEW_GET_CLASS (standard_view)->unselect_all) (standard_view); - /* select the given tree paths paths */ - for (first_path = paths->data, lp = paths; lp != NULL; lp = lp->next) + /* determine the tree paths for the given files */ + paths = thunar_list_model_get_paths_for_files (standard_view->model, selected_files); + if (G_LIKELY (paths != NULL)) { - /* select the path */ - (*THUNAR_STANDARD_VIEW_GET_CLASS (standard_view)->select_path) (standard_view, lp->data); - } + /* determine the first path */ + for (first_path = paths->data, lp = paths; lp != NULL; lp = lp->next) + { + /* check if this path is located before the current first_path */ + if (gtk_tree_path_compare (lp->data, first_path) < 0) + first_path = lp->data; + } - /* scroll to the first path (previously determined) */ - (*THUNAR_STANDARD_VIEW_GET_CLASS (standard_view)->scroll_to_path) (standard_view, first_path, FALSE, 0.0f, 0.0f); + /* place the cursor on the first selected path (must be first for GtkTreeView) */ + (*THUNAR_STANDARD_VIEW_GET_CLASS (standard_view)->set_cursor) (standard_view, first_path, FALSE); - /* release the tree paths */ - g_list_foreach (paths, (GFunc) gtk_tree_path_free, NULL); - g_list_free (paths); + /* select the given tree paths paths */ + for (first_path = paths->data, lp = paths; lp != NULL; lp = lp->next) + { + /* select the path */ + (*THUNAR_STANDARD_VIEW_GET_CLASS (standard_view)->select_path) (standard_view, lp->data); + } + + /* scroll to the first path (previously determined) */ + (*THUNAR_STANDARD_VIEW_GET_CLASS (standard_view)->scroll_to_path) (standard_view, first_path, FALSE, 0.0f, 0.0f); + + /* release the tree paths */ + g_list_foreach (paths, (GFunc) gtk_tree_path_free, NULL); + g_list_free (paths); + } } } @@ -1187,6 +1209,7 @@ thunar_standard_view_set_loading (ThunarStandardView *standard_view, { ThunarFile *file; GList *new_files_path_list; + GList *selected_files; loading = !!loading; @@ -1229,6 +1252,20 @@ thunar_standard_view_set_loading (ThunarStandardView *standard_view, thunar_g_file_list_free (new_files_path_list); } + /* check if we're done loading */ + if (!loading) + { + /* remember and reset the file list */ + selected_files = standard_view->priv->selected_files; + standard_view->priv->selected_files = NULL; + + /* and try setting the selected files again */ + thunar_component_set_selected_files (THUNAR_COMPONENT (standard_view), selected_files); + + /* cleanup */ + thunar_file_list_free (selected_files); + } + /* notify listeners */ g_object_freeze_notify (G_OBJECT (standard_view)); g_object_notify (G_OBJECT (standard_view), "loading");