Re: [PATCH] Bug 327691 =?windows-1252?Q?=96_URI-bar_location?= =?windows-1252?Q?_persists_after_deletion?=





Why can't you just use the NautilusFile machinery to figure out when a
file is deleted? I.e. Add a monitor and watch the "changed" signal, then
looking at nautilus_file_is_gone().
Here is an improved way to handle the updating of the path bar based on file changed and deletion. In the words of The Dude, my thinking has become very uptight about this matter.
Too many years away from the code.

This patch technically addresses the bug, but the navigation arrows will still be incorrect. I don't see a bug specifically for that issue. It would surprise me if there wasn't one, but
maybe no one has noticed.  I am thinking about that issue now.

Thanks!

Gene

Index: src/nautilus-pathbar.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-pathbar.c,v
retrieving revision 1.7
diff -p -u -r1.7 nautilus-pathbar.c
--- src/nautilus-pathbar.c	8 Dec 2006 09:49:39 -0000	1.7
+++ src/nautilus-pathbar.c	13 Dec 2006 07:32:33 -0000
@@ -305,8 +305,14 @@ nautilus_path_bar_finalize (GObject *obj
 		g_object_unref (path_bar->desktop_icon);
 		path_bar->desktop_icon = NULL;
 	}
+	
+	/* Clean up file changed signal handler */
+	if (path_bar->path_file != NULL) {
+		g_signal_handler_disconnect (G_OBJECT (path_bar->path_file), path_bar->file_changed_handler_id);
+		nautilus_file_unref (path_bar->path_file);
+	}
 
-        G_OBJECT_CLASS (nautilus_path_bar_parent_class)->finalize (object);
+	G_OBJECT_CLASS (nautilus_path_bar_parent_class)->finalize (object);
 }
 
 /* Removes the settings signal handler.  It's safe to call multiple times */
@@ -1512,7 +1518,6 @@ get_display_name_for_folder (const char 
 	return name;
 }
 
-
 static gboolean
 nautilus_path_bar_update_path (NautilusPathBar *path_bar, const char *file_path)
 {
@@ -1571,6 +1576,19 @@ nautilus_path_bar_update_path (NautilusP
         return result;
 }
 
+static void
+file_changed_callback (NautilusFile *file, gpointer callback_data)
+{
+	NautilusPathBar *path_bar;
+	
+	/* Remove the item from the path bar if is in the trash or was deleted */
+	if (nautilus_file_is_gone (file) || nautilus_file_is_in_trash (file)) {
+		path_bar = NAUTILUS_PATH_BAR (callback_data);
+		nautilus_path_bar_clear_buttons (path_bar);
+		nautilus_path_bar_set_path (path_bar, path_bar->last_path);
+	}
+}
+
 gboolean
 nautilus_path_bar_set_path (NautilusPathBar *path_bar, const char *file_path)
 {
@@ -1582,11 +1600,32 @@ nautilus_path_bar_set_path (NautilusPath
         if (nautilus_path_bar_check_parent_path (path_bar, file_path)) {
                 return TRUE;
 	}
-
+	
+	/* Stop observing the previous path */
+	if (path_bar->path_file != NULL) {
+		g_signal_handler_disconnect (G_OBJECT (path_bar->path_file), path_bar->file_changed_handler_id);
+	
+		/* Free up the previous file reference */
+		nautilus_file_unref (path_bar->path_file);
+		path_bar->path_file = NULL;
+	}
+	
+	/* Get the file for the path */
+	path_bar->path_file = nautilus_file_get (file_path);
+	g_assert (path_bar->path_file != NULL);
+			
+	/* Watch the new path so that we can be notified when the file is moved or deleted. */
+	path_bar->file_changed_handler_id = g_signal_connect (path_bar->path_file,
+														  "changed",
+		 												  G_CALLBACK (file_changed_callback), 
+		 												  path_bar);
+		 												  
+	/* Cache the parent path so we can set it in case of file move or deletion */ 	
+	path_bar->last_path = nautilus_file_get_parent_uri (path_bar->path_file);
+	
+	 													
 	return nautilus_path_bar_update_path (path_bar, file_path);
 }
-
-
 
 /**
  * _nautilus_path_bar_up:
Index: src/nautilus-pathbar.h
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-pathbar.h,v
retrieving revision 1.2
diff -p -u -r1.2 nautilus-pathbar.h
--- src/nautilus-pathbar.h	8 Jul 2006 08:38:17 -0000	1.2
+++ src/nautilus-pathbar.h	13 Dec 2006 07:32:33 -0000
@@ -60,6 +60,9 @@ struct _NautilusPathBar
 	guint slider_visible : 1;
 	guint need_timer : 1;
 	guint ignore_click : 1;
+	NautilusFile *path_file;
+	guint file_changed_handler_id;
+	char *last_path;
 };
 
 struct _NautilusPathBarClass


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]