[PATCH] Don't set lazy icon position during directory load



The attached patch prevents Nautilus from setting lazy icon positions
during directory load. The original code was invented to make the icon
of volumes that were mounted by the logged in user not overlap with
existing items. However that had the side-effect that during directory
(re)load the icons are placed according to the placement grid which
doesn't neccessarily match the base column width on the desktop.

This patch ensures that during directory re(load) no placement grid is
applied to volume icons, it also ensures that the private "loading"
variable of the directory view is used instead of the private "loading"
icon view variable which was used uninitialized. It also fixes a former
inconsistency where the third parameter to nautilus_icon_container_add
was not used consistently.

Unfortunately, it also causes a regression (let's call it a trade-off).
Volumes that the user already saw on his desktop (and therefore are
assigned a position), but that were mounted again when the user was not
showing the desktop (i.e. in between two sessions), and that are again
shown during login are now placed where they were before. I don't think
it is common to unmount a volume during a session, reuse the old
position and remount it after the session, though, so this shouldn't be
too bad.

After all the pain I had with this issue, the actual solution was found
in a tavern. Hail to the beer :).

-- 
Christian Neumair <chris gnome-de org>
Index: src/file-manager/fm-directory-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-directory-view.c,v
retrieving revision 1.740
diff -u -p -r1.740 fm-directory-view.c
--- src/file-manager/fm-directory-view.c	22 Mar 2006 02:59:21 -0000	1.740
+++ src/file-manager/fm-directory-view.c	25 Mar 2006 20:44:57 -0000
@@ -3299,6 +3300,21 @@ fm_directory_view_end_loading (FMDirecto
 }
 
 /**
+ * fm_directory_view_get_loading:
+ * @view: an #FMDirectoryView.
+ *
+ * Return value: #gboolean inicating whether @view is currently loaded.
+ * 
+ **/
+gboolean
+fm_directory_view_get_loading (FMDirectoryView *view)
+{
+	g_return_val_if_fail (FM_IS_DIRECTORY_VIEW (view), FALSE);
+
+	return view->details->loading;
+}
+
+/**
  * fm_directory_view_bump_zoom_level:
  *
  * bump the current zoom level by invoking the relevant subclass through the slot
Index: src/file-manager/fm-directory-view.h
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-directory-view.h,v
retrieving revision 1.143
diff -u -p -r1.143 fm-directory-view.h
--- src/file-manager/fm-directory-view.h	12 Dec 2005 16:59:11 -0000	1.143
+++ src/file-manager/fm-directory-view.h	25 Mar 2006 20:44:58 -0000
@@ -368,6 +368,8 @@ void                fm_directory_view_cl
 void                fm_directory_view_begin_loading                    (FMDirectoryView  *view);
 void                fm_directory_view_end_loading                      (FMDirectoryView  *view);
 
+gboolean            fm_directory_view_get_loading                      (FMDirectoryView  *view);
+
 /* Hooks for subclasses to call. These are normally called only by 
  * FMDirectoryView and its subclasses 
  */
Index: src/file-manager/fm-icon-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-icon-view.c,v
retrieving revision 1.321
diff -u -p -r1.321 fm-icon-view.c
--- src/file-manager/fm-icon-view.c	18 Mar 2006 07:27:37 -0000	1.321
+++ src/file-manager/fm-icon-view.c	25 Mar 2006 20:45:02 -0000
@@ -106,8 +106,6 @@ struct FMIconViewDetails
 
 	guint react_to_icon_change_idle_id;
 
-	gboolean loading;
-
 	const SortCriterion *sort;
 	gboolean sort_reversed;
 
@@ -518,6 +516,28 @@ fm_icon_view_remove_file (FMDirectoryVie
 	}
 }
 
+static gboolean
+file_has_lazy_position (FMDirectoryView *view,
+			NautilusFile *file)
+{
+	gboolean lazy_position;
+
+	/* For volumes (i.e. cdrom icon) we use lazy positioning so that when
+	 * an old cdrom gets re-mounted in a place that now has another
+	 * icon we don't overlap that one. We don't do this in general though,
+	 * as it can cause icons moving around.
+	 */
+	lazy_position = nautilus_file_has_volume (file);
+	if (lazy_position && fm_directory_view_get_loading (view)) {
+		/* if volumes are loaded during directory load, don't mark them
+		 * as lazy. This is wrong for files that were mounted during user
+		 * log-off, but it is right for files that were mounted during login. */
+		lazy_position = FALSE;
+	}
+
+	return lazy_position;
+}
+
 static void
 fm_icon_view_add_file (FMDirectoryView *view, NautilusFile *file, NautilusDirectory *directory)
 {
@@ -535,18 +555,13 @@ fm_icon_view_add_file (FMDirectoryView *
 	}
 
 	/* Reset scroll region for the first icon added when loading a directory. */
-	if (icon_view->details->loading && nautilus_icon_container_is_empty (icon_container)) {
+	if (fm_directory_view_get_loading (view) && nautilus_icon_container_is_empty (icon_container)) {
 		nautilus_icon_container_reset_scroll_region (icon_container);
 	}
-	
-	/* For volumes (i.e. cdrom icon) we use lazy positioning so that when
-	 * an old cdrom gets re-mounted in a place that now has another
-	 * icon we don't overlap that one. We don't do this in general though,
-	 * as it can cause icons moving around.
-	 */
+
 	if (nautilus_icon_container_add (icon_container,
 					 NAUTILUS_ICON_CONTAINER_ICON_DATA (file),
-					 nautilus_file_has_volume (file))) {
+					 file_has_lazy_position (view, file)))  {
 		nautilus_file_ref (file);
 	}
 }
@@ -2070,7 +2086,7 @@ fm_icon_view_screen_changed (GtkWidget *
 			} else {
 				if (nautilus_icon_container_add (icon_container,
 								 NAUTILUS_ICON_CONTAINER_ICON_DATA (file),
-								 NAUTILUS_IS_DESKTOP_ICON_FILE (file))) {
+								 file_has_lazy_position (view, file))) {
 					nautilus_file_ref (file);
 				}
 			}


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