[Xfce4-commits] [xfce/thunar] 04/06: Fix removal of a directory wrongly affecting the current tab (bug #10981)

noreply at xfce.org noreply at xfce.org
Sun May 3 15:00:16 CEST 2015


This is an automated email from the git hooks/post-receive script.

hjudt pushed a commit to branch master
in repository xfce/thunar.

commit 3b4b952e5931d413c08b633a12303c4144d11ac1
Author: Harald Judt <h.judt at gmx.at>
Date:   Sat May 2 14:06:01 2015 +0200

    Fix removal of a directory wrongly affecting the current tab (bug #10981)
    
    This fixes the following bug:
    
    1) Create two directories (a and b).
    2) Open them in tabs in a thunar window.
    3) Switch to the tab currently showing a and delete b from a terminal.
    
    Expected behaviour:
    Inactive tab showing b will switch to the parent directory.
    Active tab showing a will be unaffected.
    
    Actual behaviour:
    Inactive tab showing b will switch to the parent directory.
    Active tab showing a will not change the directory.
---
 thunar/thunar-standard-view.c |   70 ++++++++++++++++++++++++++---------------
 thunar/thunar-window.c        |   44 ++++++++++++++++++++++++++
 thunar/thunar-window.h        |    3 ++
 3 files changed, 92 insertions(+), 25 deletions(-)

diff --git a/thunar/thunar-standard-view.c b/thunar/thunar-standard-view.c
index d06ed12..6b9a763 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 e8b8b9d..a162f30 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 df3928a..8906fcb 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;
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list