Re: Icons are outside the nautilus window with "text beside icons"



Am Donnerstag, den 02.06.2005, 11:43 +0200 schrieb Alexander Larsson:
> On Wed, 2005-06-01 at 10:37 -0400, Michael Terry wrote:
> > Hello.  I have a patch I'd like reviewed for bug 159621, Icons are
> > outside the nautilus window with "text beside icons."  You can see it
> > here:  http://bugzilla.gnome.org/show_bug.cgi?id=159621.
> > 
> > The bug is that with the text beside icons option selected, if there are
> > short filenames in a folder, the files will appear cut off, partially
> > obscured to the left of the window.
> 
> I don't think that approach is right.
> 
> We're calculating the max size of the icon+text and use that as the grid
> size. Then we use the max text size to set things up so that the right
> size of the icon/left side of the text is aligned vertically.
> 
> This can be really wrong. Think of the case of a two-item directory, one
> item with a very wide icon but small text, one with a small icon but
> wide text. Say the *total* size of both icon+text are the same. This
> would mean we picked that size for grid size. But, to get the alignment
> right we really have to pick a grid size of max_icon_width +
> max_text_width. When that is done we really should use max_icon_width -
> icon_width as x_offset.

Proposed patch attached.

-- 
Christian Neumair <chris gnome-de org>
? libnautilus-private/.nautilus-icon-canvas-item.h.swp
? libnautilus-private/2
? libnautilus-private/2nautilus-icon-container.c
? libnautilus-private/nautilus-icon-container.ALA.c
? libnautilus-private/s
? libnautilus-private/volume
Index: libnautilus-private/nautilus-file.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-file.c,v
retrieving revision 1.370
diff -u -p -r1.370 nautilus-file.c
--- libnautilus-private/nautilus-file.c	22 Aug 2005 21:17:58 -0000	1.370
+++ libnautilus-private/nautilus-file.c	23 Aug 2005 14:28:26 -0000
@@ -810,7 +810,32 @@ nautilus_file_can_execute (NautilusFile 
 }
 
 /**
- * nautilus_file_is_desktop_directory:
+ * nautilus_file_is_template_directory:
+ * 
+ * Check whether this file is the template directory.
+ * 
+ * @file: The file to check.
+ * 
+ * Return value: TRUE if this is the physical desktop directory.
+ */
+gboolean
+nautilus_file_is_template_directory (NautilusFile *file)
+{
+	GnomeVFSURI *dir_vfs_uri;
+
+	dir_vfs_uri = file->details->directory->details->vfs_uri;
+
+	if (dir_vfs_uri == NULL ||
+	    strcmp (dir_vfs_uri->method_string, "file") != 0) {
+		return FALSE;
+	}
+
+	return ((strcmp (dir_vfs_uri->text, g_get_home_dir ()) == 0)
+		&& (strcmp (file->details->relative_uri, "Templates") == 0));
+}
+
+/**
+ * nautilus_file_is_desktop:
  * 
  * Check whether this file is the desktop directory.
  * 
@@ -2677,6 +2702,8 @@ nautilus_file_get_display_name_nocopy (N
 	
  	if (file->details->got_link_info && file->details->display_name != NULL) {
  		name = g_strdup (file->details->display_name);
+	} else if (nautilus_file_is_template_directory (file)) {
+		name = _("Templates");
 	} else {
 		name = nautilus_file_get_name (file);
 		if (name == NULL) {
Index: libnautilus-private/nautilus-file.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-file.h,v
retrieving revision 1.106
diff -u -p -r1.106 nautilus-file.h
--- libnautilus-private/nautilus-file.h	22 Aug 2005 21:17:58 -0000	1.106
+++ libnautilus-private/nautilus-file.h	23 Aug 2005 14:28:26 -0000
@@ -155,6 +155,7 @@ gboolean                nautilus_file_is
 gboolean                nautilus_file_is_in_desktop                     (NautilusFile                   *file);
 gboolean		nautilus_file_is_home				(NautilusFile                   *file);
 gboolean                nautilus_file_is_desktop_directory              (NautilusFile                   *file);
+gboolean                nautilus_file_is_template_directory             (NautilusFile                   *file);
 GnomeVFSResult          nautilus_file_get_file_info_result              (NautilusFile                   *file);
 gboolean                nautilus_file_get_directory_item_count          (NautilusFile                   *file,
 									 guint                          *count,
Index: libnautilus-private/nautilus-icon-container.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-icon-container.c,v
retrieving revision 1.393
diff -u -p -r1.393 nautilus-icon-container.c
--- libnautilus-private/nautilus-icon-container.c	12 Aug 2005 18:11:29 -0000	1.393
+++ libnautilus-private/nautilus-icon-container.c	23 Aug 2005 14:28:28 -0000
@@ -978,6 +978,7 @@ lay_down_icons_horizontal (NautilusIconC
 	double line_width;
 	gboolean gridded_layout;
 	double grid_width;
+	double max_text_width, max_icon_width;
 	int icon_width;
 	int i;
 
@@ -998,17 +999,23 @@ lay_down_icons_horizontal (NautilusIconC
 			 - container->details->top_margin
 			 - container->details->bottom_margin) / EEL_CANVAS (container)->pixels_per_unit;
 
+	max_icon_width = max_text_width = 0.0;
+
 	if (container->details->label_position == NAUTILUS_ICON_LABEL_POSITION_BESIDE) {
-		grid_width = 0.0;
 		/* Would it be worth caching these bounds for the next loop? */
 		for (p = icons; p != NULL; p = p->next) {
 			icon = p->data;
-			
-			eel_canvas_item_get_bounds (EEL_CANVAS_ITEM (icon->item),
-						    &bounds.x0, &bounds.y0,
-						    &bounds.x1, &bounds.y1);
-			grid_width = MAX (grid_width, ceil (bounds.x1 - bounds.x0) + ICON_PAD_LEFT + ICON_PAD_RIGHT);
+
+			icon_bounds = nautilus_icon_canvas_item_get_icon_rectangle (icon->item);
+			max_icon_width = MAX (max_icon_width, ceil (icon_bounds.x1 - icon_bounds.x0));
+
+			text_bounds = nautilus_icon_canvas_item_get_text_rectangle (icon->item);
+			max_text_width = MAX (max_text_width, ceil (text_bounds.x1 - text_bounds.x0 < 0
+								    ? MAX_TEXT_WIDTH_BESIDE
+								    : text_bounds.x1 - text_bounds.x0));
 		}
+
+		grid_width = max_icon_width + max_text_width + ICON_PAD_LEFT + ICON_PAD_RIGHT;
 	} else {
 		grid_width = STANDARD_ICON_GRID_WIDTH;
 	}
@@ -1093,7 +1100,7 @@ lay_down_icons_horizontal (NautilusIconC
 
 		if (container->details->label_position == NAUTILUS_ICON_LABEL_POSITION_BESIDE) {
 			if (gridded_layout) {
-				position->x_offset = icon_width - ((icon_bounds.x1 - icon_bounds.x0) + MAX_TEXT_WIDTH_BESIDE);
+				position->x_offset = max_icon_width + ICON_PAD_LEFT + ICON_PAD_RIGHT - (icon_bounds.x1 - icon_bounds.x0);
 			} else {
 				position->x_offset = icon_width - ((icon_bounds.x1 - icon_bounds.x0) + (text_bounds.x1 - text_bounds.x0));
 			}
@@ -5152,7 +5159,7 @@ finish_adding_icon (NautilusIconContaine
 static void
 finish_adding_new_icons (NautilusIconContainer *container)
 {
-	GList *p, *new_icons, *no_position_icons;
+	GList *p, *new_icons, *no_position_icons, *semi_position_icons;
 	NautilusIcon *icon;
 	double bottom;
 
@@ -5161,16 +5168,61 @@ finish_adding_new_icons (NautilusIconCon
 
 	/* Position most icons (not unpositioned manual-layout icons). */
 	new_icons = g_list_reverse (new_icons);
-	no_position_icons = NULL;
+	no_position_icons = semi_position_icons = NULL;
 	for (p = new_icons; p != NULL; p = p->next) {
 		icon = p->data;
 		if (!assign_icon_position (container, icon)) {
 			no_position_icons = g_list_prepend (no_position_icons, icon);
+		} else if (!container->details->auto_layout &&
+			   icon->has_lazy_position) {
+			semi_position_icons = g_list_prepend (semi_position_icons, icon);
 		}
 		finish_adding_icon (container, icon);
 	}
 	g_list_free (new_icons);
 
+	if (semi_position_icons != NULL) {
+		PlacementGrid *grid;
+
+		g_assert (!container->details->auto_layout);
+
+		semi_position_icons = g_list_reverse (semi_position_icons);
+
+		grid = placement_grid_new (container, TRUE);
+
+		for (p = container->details->icons; p != NULL; p = p->next) {
+			icon = p->data;
+
+			if (icon_is_positioned (icon) && !icon->has_lazy_position) {
+				placement_grid_mark_icon (grid, icon);
+			}
+		}
+
+		for (p = semi_position_icons; p != NULL; p = p->next) {
+			NautilusIcon *icon;
+			int x, y;
+
+			icon = p->data;
+			x = icon->x;
+			y = icon->y;
+
+			find_empty_location (container, grid, 
+					     icon, x, y, &x, &y);
+
+			icon_set_position (icon, x, y);
+
+			placement_grid_mark_icon (grid, icon);
+
+			/* ensure that next time we run this code, the formerly semi-positioned
+			 * icons are treated as being positioned. */
+			icon->has_lazy_position = FALSE;
+		}
+
+		placement_grid_free (grid);
+
+		g_list_free (semi_position_icons);
+	}
+
 	/* Position the unpositioned manual layout icons. */
 	if (no_position_icons != NULL) {
 		g_assert (!container->details->auto_layout);
@@ -5186,13 +5238,18 @@ finish_adding_new_icons (NautilusIconCon
  * nautilus_icon_container_add:
  * @container: A NautilusIconContainer
  * @data: Icon data.
+ * @has_lazy_position: Whether the saved icon position should only be used
+ * 		       if the previous icon position is free. If the position
+ * 		       is occupied, another position near the last one will
+ * 		       be used.
  * 
  * Add icon to represent @data to container.
  * Returns FALSE if there was already such an icon.
  **/
 gboolean
 nautilus_icon_container_add (NautilusIconContainer *container,
-			     NautilusIconData *data)
+			     NautilusIconData *data,
+			     gboolean has_lazy_position)
 {
 	NautilusIconContainerDetails *details;
 	NautilusIcon *icon;
@@ -5212,6 +5269,7 @@ nautilus_icon_container_add (NautilusIco
 	icon->data = data;
 	icon->x = ICON_UNPOSITIONED_VALUE;
 	icon->y = ICON_UNPOSITIONED_VALUE;
+	icon->has_lazy_position = has_lazy_position;
 	icon->scale_x = 1.0;
 	icon->scale_y = 1.0;
  	icon->item = NAUTILUS_ICON_CANVAS_ITEM
Index: libnautilus-private/nautilus-icon-container.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-icon-container.h,v
retrieving revision 1.87
diff -u -p -r1.87 nautilus-icon-container.h
--- libnautilus-private/nautilus-icon-container.h	5 Jul 2005 12:23:34 -0000	1.87
+++ libnautilus-private/nautilus-icon-container.h	23 Aug 2005 14:28:28 -0000
@@ -204,7 +204,8 @@ GtkWidget *       nautilus_icon_containe
 /* adding, removing, and managing icons */
 void              nautilus_icon_container_clear                         (NautilusIconContainer  *view);
 gboolean          nautilus_icon_container_add                           (NautilusIconContainer  *view,
-									 NautilusIconData       *data);
+									 NautilusIconData       *data,
+									 gboolean                has_lazy_position);
 void              nautilus_icon_container_layout_now                    (NautilusIconContainer *container);
 gboolean          nautilus_icon_container_remove                        (NautilusIconContainer  *view,
 									 NautilusIconData       *data);
Index: libnautilus-private/nautilus-icon-dnd.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-icon-dnd.c,v
retrieving revision 1.148
diff -u -p -r1.148 nautilus-icon-dnd.c
--- libnautilus-private/nautilus-icon-dnd.c	13 Jul 2005 08:17:29 -0000	1.148
+++ libnautilus-private/nautilus-icon-dnd.c	23 Aug 2005 14:28:29 -0000
@@ -844,7 +844,8 @@ handle_local_move (NautilusIconContainer
 			g_free (screen_string);
 
 			nautilus_icon_container_add (container,
-					NAUTILUS_ICON_CONTAINER_ICON_DATA (file));
+					NAUTILUS_ICON_CONTAINER_ICON_DATA (file),
+					FALSE);
 			
 			icon = nautilus_icon_container_get_icon_by_uri
 				(container, item->uri);
Index: libnautilus-private/nautilus-icon-private.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-icon-private.h,v
retrieving revision 1.77
diff -u -p -r1.77 nautilus-icon-private.h
--- libnautilus-private/nautilus-icon-private.h	6 Jul 2005 11:45:08 -0000	1.77
+++ libnautilus-private/nautilus-icon-private.h	23 Aug 2005 14:28:29 -0000
@@ -57,6 +57,7 @@ typedef struct {
 	/* Whether a monitor was set on this icon. */
 	eel_boolean_bit is_monitored : 1;
 
+	eel_boolean_bit has_lazy_position : 1;
 } NautilusIcon;
 
 

Attachment: signature.asc
Description: This is a digitally signed message part



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