diff --git a/thunar/thunar-standard-view.c b/thunar/thunar-standard-view.c index d06ed12850b023583b019094b875566505901f28..6b9a7633f9f8b8e74478bac681aadca9a1688180 100644 --- a/thunar/thunar-standard-view.c +++ b/thunar/thunar-standard-view.c @@ -2153,26 +2153,29 @@ thunar_standard_view_update_statusbar_text (ThunarStandardView *standard_view) -static void -thunar_standard_view_current_directory_destroy (ThunarFile *current_directory, - ThunarStandardView *standard_view) +/* + * Find a fallback directory we can navigate to if the directory gets + * deleted. It first tries the parent folders, and finally if none can + * be found, the home folder. If the home folder cannot be accessed, + * the error will be stored for use by the caller. + */ +static ThunarFile * +thunar_standard_view_get_fallback_directory (ThunarFile *directory, + GError *error) { ThunarFile *new_directory = NULL; GFile *path; GFile *tmp; - GError *error = NULL; - _thunar_return_if_fail (THUNAR_IS_STANDARD_VIEW (standard_view)); - _thunar_return_if_fail (THUNAR_IS_FILE (current_directory)); - _thunar_return_if_fail (standard_view->priv->current_directory == current_directory); + _thunar_return_if_fail (THUNAR_IS_FILE (directory)); - /* determine the path of the current directory */ - path = g_object_ref (thunar_file_get_file (current_directory)); + /* determine the path of the directory */ + path = g_object_ref (thunar_file_get_file (directory)); /* try to find a parent directory that still exists */ while (new_directory == NULL) { - /* check whether the current directory exists */ + /* check whether the directory exists */ if (g_file_query_exists (path, NULL)) { /* it does, try to load the file */ @@ -2210,26 +2213,43 @@ thunar_standard_view_current_directory_destroy (ThunarFile *current_dire path = thunar_g_file_new_for_home (); new_directory = thunar_file_get (path, &error); g_object_unref (path); - - if (G_UNLIKELY (new_directory == NULL)) - { - /* display an error to the user */ - thunar_dialogs_show_error (GTK_WIDGET (standard_view), error, _("Failed to open the home folder")); - g_error_free (error); - } } - if (G_LIKELY (new_directory != NULL)) - { - /* enter the new folder */ - thunar_navigator_change_directory (THUNAR_NAVIGATOR (standard_view), new_directory); + return new_directory; +} + + - /* if the view is not active, do this on our own */ - thunar_navigator_set_current_directory (THUNAR_NAVIGATOR (standard_view), new_directory); +static void +thunar_standard_view_current_directory_destroy (ThunarFile *current_directory, + ThunarStandardView *standard_view) +{ + GtkWidget *window; + ThunarFile *new_directory = NULL; + GError *error = NULL; + + _thunar_return_if_fail (THUNAR_IS_STANDARD_VIEW (standard_view)); + _thunar_return_if_fail (THUNAR_IS_FILE (current_directory)); + _thunar_return_if_fail (standard_view->priv->current_directory == current_directory); - /* release the file reference */ - g_object_unref (new_directory); + /* get a fallback directory (parents or home) we can navigate to */ + new_directory = thunar_standard_view_get_fallback_directory (current_directory, error); + if (G_UNLIKELY (new_directory == NULL)) + { + /* display an error to the user */ + thunar_dialogs_show_error (GTK_WIDGET (standard_view), error, _("Failed to open the home folder")); + g_error_free (error); + return; } + + /* let the parent window update all active and inactive views (tabs) */ + window = gtk_widget_get_toplevel (GTK_WIDGET (standard_view)); + thunar_window_update_directories (THUNAR_WINDOW (window), + current_directory, + new_directory); + + /* release the reference to the new directory */ + g_object_unref (new_directory); } diff --git a/thunar/thunar-window.c b/thunar/thunar-window.c index e8b8b9dc75b3d237bc32b5dd7fc2fe9b1278f9d9..a162f307af8c4261933c76dc857c4695840d5eb7 100644 --- a/thunar/thunar-window.c +++ b/thunar/thunar-window.c @@ -1790,6 +1790,50 @@ thunar_window_notebook_insert (ThunarWindow *window, +void +thunar_window_update_directories (ThunarWindow *window, + ThunarFile *old_directory, + ThunarFile *new_directory) +{ + GtkWidget *view; + ThunarFile *directory; + gint n; + gint n_pages; + gint active_page; + + _thunar_return_if_fail (THUNAR_IS_WINDOW (window)); + _thunar_return_if_fail (THUNAR_IS_FILE (old_directory)); + _thunar_return_if_fail (THUNAR_IS_FILE (new_directory)); + + n_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (window->notebook)); + if (G_UNLIKELY (n_pages == 0)) + return; + + active_page = gtk_notebook_get_current_page (GTK_NOTEBOOK (window->notebook)); + + for (n = 0; n < n_pages; n++) + { + /* get the view */ + view = gtk_notebook_get_nth_page (GTK_NOTEBOOK (window->notebook), n); + if (! THUNAR_IS_NAVIGATOR (view)) + continue; + + /* get the directory of the view */ + directory = thunar_navigator_get_current_directory (THUNAR_NAVIGATOR (view)); + if (! THUNAR_IS_FILE (directory)) + continue; + + /* if it matches the old directory, change to the new one */ + if (directory == old_directory) + if (n == active_page) + thunar_navigator_change_directory (THUNAR_NAVIGATOR (view), new_directory); + else + thunar_navigator_set_current_directory (THUNAR_NAVIGATOR (view), new_directory); + } +} + + + static void thunar_window_install_location_bar (ThunarWindow *window, GType type) diff --git a/thunar/thunar-window.h b/thunar/thunar-window.h index df3928afde6ef7fa2b64e41ae2945e6ba0e2188c..8906fcb7011d1dba320cb644546817d465aa0c49 100644 --- a/thunar/thunar-window.h +++ b/thunar/thunar-window.h @@ -53,6 +53,9 @@ gchar **thunar_window_get_directories (ThunarWindow *window, gboolean thunar_window_set_directories (ThunarWindow *window, gchar **uris, gint active_page); +void thunar_window_update_directories (ThunarWindow *window, + ThunarFile *old_directory, + ThunarFile *new_directory); G_END_DECLS;