Index: src/file-manager/fm-icon-container.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-icon-container.c,v
retrieving revision 1.20
diff -u -p -r1.20 fm-icon-container.c
--- src/file-manager/fm-icon-container.c	16 May 2006 12:29:40 -0000	1.20
+++ src/file-manager/fm-icon-container.c	5 Nov 2006 12:57:57 -0000
@@ -22,6 +22,8 @@
    Author: Michael Meeks <michael@ximian.com>
 */
 #include <config.h>
+#include <stdlib.h>
+#include <string.h>
 
 #include <libgnome/gnome-macros.h>
 #include <glib/gi18n.h>
@@ -34,6 +36,7 @@
 #include <libnautilus-private/nautilus-file-attributes.h>
 #include <libnautilus-private/nautilus-thumbnails.h>
 #include <libnautilus-private/nautilus-desktop-icon-file.h>
+#include <libnautilus-private/nautilus-icon-private.h>
 
 #include "fm-icon-container.h"
 
@@ -43,6 +46,25 @@
 GNOME_CLASS_BOILERPLATE (FMIconContainer, fm_icon_container,
 			 NautilusIconContainer,
 			 nautilus_icon_container_get_type ())
+static void
+truncate_string(char** str_to_truncate, int max_length)
+{
+  char *tmp;
+  if (*str_to_truncate != NULL && max_length > 3)
+    {
+      if (strlen(*str_to_truncate) > max_length)
+	{
+	  tmp = malloc(max_length*sizeof(char)+1);
+	  strncpy(tmp, *str_to_truncate, max_length-3);
+	  tmp[max_length-3] = '.';
+	  tmp[max_length-2] = '.';
+	  tmp[max_length-1] = '.';
+	  tmp[max_length] = '\0';
+	  free(*str_to_truncate);
+	  *str_to_truncate = tmp;
+	}
+    }
+}
 
 static FMIconView *
 get_icon_view (NautilusIconContainer *container)
@@ -266,10 +288,14 @@ fm_icon_container_get_icon_text (Nautilu
 	char **text_array;
 	int i , slot_index;
 	char *attribute_string;
+	char *display_name;
 	FMIconView *icon_view;
 	NautilusFile *file;
+	NautilusIcon *icon;
 
-	file = NAUTILUS_FILE (data);
+	icon = (NautilusIcon *) data;
+
+	file = NAUTILUS_FILE (icon->data);
 
 	g_assert (NAUTILUS_IS_FILE (file));
 	g_assert (editable_text != NULL);
@@ -282,7 +308,14 @@ fm_icon_container_get_icon_text (Nautilu
 		*editable_text = NULL;
 	} else {
 		/* Strip the suffix for nautilus object xml files. */
-		*editable_text = nautilus_file_get_display_name (file);
+
+		display_name = nautilus_file_get_display_name (file);
+		if (container->details->truncate_displaynames)
+			{
+				if (icon != container->details->last_clicked_icon)
+					truncate_string(&display_name, container->details->truncation_length);
+			}
+		*editable_text = display_name;
 	}
 
 	if (NAUTILUS_IS_DESKTOP_ICON_FILE (file)) {
Index: src/file-manager/fm-icon-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-icon-view.c,v
retrieving revision 1.326
diff -u -p -r1.326 fm-icon-view.c
--- src/file-manager/fm-icon-view.c	31 Oct 2006 09:21:53 -0000	1.326
+++ src/file-manager/fm-icon-view.c	5 Nov 2006 12:58:03 -0000
@@ -72,6 +72,7 @@
 #include <libnautilus-private/nautilus-view-factory.h>
 #include <libnautilus-private/nautilus-clipboard.h>
 #include <libnautilus-private/nautilus-desktop-icon-file.h>
+#include <libnautilus-private/nautilus-icon-private.h>
 #include <locale.h>
 #include <signal.h>
 #include <stdio.h>
@@ -1078,6 +1079,31 @@ set_labels_beside_icons (FMIconView *ico
 }
 
 static void
+set_truncate_displaynames (FMIconView *icon_view)
+{
+	NautilusIconContainer *icon_container;
+	gboolean truncate_display_names_new;
+	icon_container = get_icon_container (icon_view);
+	truncate_display_names_new = eel_preferences_get_boolean (NAUTILUS_PREFERENCES_ICON_VIEW_TRUNCATE_DISPLAYNAMES);
+	icon_container->details->truncate_displaynames = truncate_display_names_new;
+	if (!truncate_display_names_new)
+		icon_container->details->last_clicked_icon = NULL;
+	nautilus_icon_container_request_update_all (icon_container);
+}
+
+static void
+set_truncation_length (FMIconView *icon_view)
+{
+	NautilusIconContainer *icon_container;
+	int truncation_length_new;
+	icon_container = get_icon_container (icon_view);
+	truncation_length_new = eel_preferences_get_integer (NAUTILUS_PREFERENCES_ICON_VIEW_TRUNCATION_LENGTH);
+	icon_container->details->truncation_length = truncation_length_new;
+	if (icon_container->details->truncate_displaynames)
+		nautilus_icon_container_request_update_all (icon_container);
+}
+
+static void
 fm_icon_view_begin_loading (FMDirectoryView *view)
 {
 	FMIconView *icon_view;
@@ -1095,6 +1121,9 @@ fm_icon_view_begin_loading (FMDirectoryV
 	nautilus_icon_container_set_allow_moves (NAUTILUS_ICON_CONTAINER (icon_container),
 						 fm_directory_view_get_allow_moves (view));
 
+	set_truncate_displaynames (icon_view);
+	set_truncation_length (icon_view);
+
 	/* kill any sound preview process that is ongoing */
 	preview_audio (icon_view, NULL, FALSE);
 
@@ -2424,6 +2453,30 @@ labels_beside_icons_changed_callback (gp
 }
 
 static void
+truncate_displaynames_changed_callback (gpointer callback_data)
+{
+	FMIconView *icon_view;
+	
+	g_return_if_fail (FM_IS_ICON_VIEW (callback_data));
+	
+	icon_view = FM_ICON_VIEW (callback_data);
+	
+	set_truncate_displaynames (icon_view);
+}
+
+static void
+truncation_length_changed_callback (gpointer callback_data)
+{
+	FMIconView *icon_view;
+	
+	g_return_if_fail (FM_IS_ICON_VIEW (callback_data));
+	
+	icon_view = FM_ICON_VIEW (callback_data);
+	
+	set_truncation_length (icon_view);	
+}
+
+static void
 fm_icon_view_sort_directories_first_changed (FMDirectoryView *directory_view)
 {
 	FMIconView *icon_view;
@@ -2706,6 +2759,8 @@ fm_icon_view_init (FMIconView *icon_view
 
 	create_icon_container (icon_view);
 
+
+
 	if (!setup_sound_preview) {
 		eel_preferences_add_auto_enum (NAUTILUS_PREFERENCES_PREVIEW_SOUND,
 					       &preview_sound_auto_value);
@@ -2735,7 +2790,12 @@ fm_icon_view_init (FMIconView *icon_view
 	eel_preferences_add_callback_while_alive (NAUTILUS_PREFERENCES_ICON_VIEW_LABELS_BESIDE_ICONS,
 						  labels_beside_icons_changed_callback,
 						  icon_view, G_OBJECT (icon_view));
-
+	eel_preferences_add_callback_while_alive (NAUTILUS_PREFERENCES_ICON_VIEW_TRUNCATE_DISPLAYNAMES,
+						  truncate_displaynames_changed_callback,
+						  icon_view, G_OBJECT (icon_view));
+	eel_preferences_add_callback_while_alive (NAUTILUS_PREFERENCES_ICON_VIEW_TRUNCATION_LENGTH,
+						  truncation_length_changed_callback,
+               	       				  icon_view, G_OBJECT (icon_view));
 	g_signal_connect_object (get_icon_container (icon_view), "handle_netscape_url",
 				 G_CALLBACK (icon_view_handle_netscape_url), icon_view, 0);
 	g_signal_connect_object (get_icon_container (icon_view), "handle_uri_list",
Index: libnautilus-private/nautilus-icon-private.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-icon-private.h,v
retrieving revision 1.83
diff -u -p -r1.83 nautilus-icon-private.h
--- libnautilus-private/nautilus-icon-private.h	15 May 2006 22:55:24 -0000	1.83
+++ libnautilus-private/nautilus-icon-private.h	5 Nov 2006 12:58:04 -0000
@@ -162,6 +162,11 @@ struct NautilusIconContainerDetails {
 	gboolean icon_selected_on_button_down;
 	NautilusIcon *double_click_icon[2]; /* Both clicks in a double click need to be on the same icon */
 
+	gboolean truncate_displaynames;
+	int truncation_length;
+
+	NautilusIcon *last_clicked_icon; /* Inidicates the icon, which is not truncated */
+
 	NautilusIcon *range_selection_base_icon;
 	
 	/* Renaming Details */
Index: libnautilus-private/nautilus-global-preferences.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-global-preferences.h,v
retrieving revision 1.134
diff -u -p -r1.134 nautilus-global-preferences.h
--- libnautilus-private/nautilus-global-preferences.h	21 Jun 2006 16:26:15 -0000	1.134
+++ libnautilus-private/nautilus-global-preferences.h	5 Nov 2006 12:58:04 -0000
@@ -61,6 +61,7 @@ G_BEGIN_DECLS
 #define NAUTILUS_PREFERENCES_SHOW_ADVANCED_PERMISSIONS		"preferences/show_advanced_permissions"
 #define NAUTILUS_PREFERENCES_DATE_FORMAT			"preferences/date_format"
 
+
 typedef enum
 {
 	NAUTILUS_DATE_FORMAT_LOCALE,
@@ -116,7 +117,8 @@ enum
 #define NAUTILUS_PREFERENCES_ICON_VIEW_DEFAULT_USE_MANUAL_LAYOUT	"icon_view/default_use_manual_layout"
 
 #define NAUTILUS_PREFERENCES_ICON_VIEW_LABELS_BESIDE_ICONS      	"icon_view/labels_beside_icons"
-
+#define NAUTILUS_PREFERENCES_ICON_VIEW_TRUNCATE_DISPLAYNAMES      "icon_view/truncate_displaynames" 
+#define NAUTILUS_PREFERENCES_ICON_VIEW_TRUNCATION_LENGTH          "icon_view/truncation_length"
 
 /* The icon view uses 2 variables to store the sort order and
  * whether to use manual layout.  However, the UI for these
@@ -169,6 +171,7 @@ typedef enum
 #define NAUTILUS_PREFERENCES_SHOW_IMAGE_FILE_THUMBNAILS	"preferences/show_image_thumbnails"
 #define NAUTILUS_PREFERENCES_IMAGE_FILE_THUMBNAIL_LIMIT	"preferences/thumbnail_limit"
 #define NAUTILUS_PREFERENCES_PREVIEW_SOUND		"preferences/preview_sound"
+
 
 typedef enum
 {
Index: libnautilus-private/nautilus-global-preferences.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-global-preferences.c,v
retrieving revision 1.228
diff -u -p -r1.228 nautilus-global-preferences.c
--- libnautilus-private/nautilus-global-preferences.c	21 Jun 2006 16:26:14 -0000	1.228
+++ libnautilus-private/nautilus-global-preferences.c	5 Nov 2006 12:58:06 -0000
@@ -323,6 +323,14 @@ static const PreferenceDefault preferenc
 	  NULL, NULL,
 	  "speed_tradeoff"
 	},
+	{ NAUTILUS_PREFERENCES_ICON_VIEW_TRUNCATE_DISPLAYNAMES,
+	  PREFERENCE_BOOLEAN,
+	  GINT_TO_POINTER (FALSE)
+	},
+	{ NAUTILUS_PREFERENCES_ICON_VIEW_TRUNCATION_LENGTH,
+	  PREFERENCE_INTEGER,
+	  GINT_TO_POINTER (20)
+	},
 	{ NAUTILUS_PREFERENCES_SHOW_ADVANCED_PERMISSIONS,
 	  PREFERENCE_BOOLEAN,
 	  GINT_TO_POINTER (FALSE)
Index: libnautilus-private/nautilus-icon-container.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-icon-container.c,v
retrieving revision 1.419
diff -u -p -r1.419 nautilus-icon-container.c
--- libnautilus-private/nautilus-icon-container.c	18 Oct 2006 12:28:35 -0000	1.419
+++ libnautilus-private/nautilus-icon-container.c	5 Nov 2006 12:58:20 -0000
@@ -195,6 +195,8 @@ static void          handle_vadjustment_
 static void          nautilus_icon_container_update_visible_icons   (NautilusIconContainer *container);
 static void          reveal_icon                                    (NautilusIconContainer *container,
 								     NautilusIcon *icon);
+static void          change_last_clicked_icon                       (NautilusIconContainer *container,
+								     NautilusIcon *icon);
 
 
 static gpointer accessible_parent_class;
@@ -494,6 +496,17 @@ icon_get_bounding_box (NautilusIcon *ico
 
 /* Utility functions for NautilusIconContainer.  */
 
+static void
+change_last_clicked_icon (NautilusIconContainer *container,
+			  NautilusIcon *icon)
+{
+	if (container->details->last_clicked_icon != icon)
+		{
+			container->details->last_clicked_icon = icon;
+			nautilus_icon_container_request_update_all (container);
+		}
+}
+
 gboolean
 nautilus_icon_container_scroll (NautilusIconContainer *container,
 				int delta_x, int delta_y)
@@ -2656,6 +2669,8 @@ keyboard_move_to (NautilusIconContainer 
 	if (icon == NULL) {
 		return;
 	}
+	if (container->details->truncate_displaynames)
+		change_last_clicked_icon (container, icon);
 
 	if ((event->state & GDK_CONTROL_MASK) != 0) {
 		/* Move the keyboard focus. Use Control modifier
@@ -3212,6 +3227,9 @@ button_press_event (GtkWidget *widget,
 	/* An item didn't take the press, so it's a background press.
          * We ignore double clicks on the desktop for now.
 	 */
+	if (container->details->truncate_displaynames)
+		change_last_clicked_icon (container, NULL);
+
 	if (event->type == GDK_2BUTTON_PRESS || event->type == GDK_3BUTTON_PRESS) {
 		return TRUE;
 	}
@@ -3940,10 +3958,14 @@ nautilus_icon_container_search_iter (Nau
 			g_signal_emit (container, signals[SELECTION_CHANGED], 0);
 		}
 		schedule_keyboard_icon_reveal (container, icon);
+		if (container->details->truncate_displaynames)
+			change_last_clicked_icon (container, icon);
 		
 		return TRUE;
 	}
-	
+	if (container->details->truncate_displaynames)
+		change_last_clicked_icon (container, NULL);
+
 	return FALSE;
 }
 
@@ -4968,6 +4990,9 @@ handle_icon_button_press (NautilusIconCo
 	NautilusIconContainerDetails *details;
 
 	details = container->details;
+	
+	if (container->details->truncate_displaynames)
+		change_last_clicked_icon (container, icon);
 
 	if (event->type == GDK_3BUTTON_PRESS) {
 		return TRUE;
@@ -5624,8 +5649,8 @@ nautilus_icon_container_update_icon (Nau
 	eel_g_list_free_deep (emblem_icon_names);
 
 	nautilus_icon_container_get_icon_text (container,
-					       icon->data,
-					       &editable_text,
+					       (NautilusIconData *) icon, /* TODO: Make this function call type safe */
+					       &editable_text,            
 					       &additional_text);
 
 	/* If name of icon being renamed was changed from elsewhere, end renaming mode. 
