[patch] [bug 410113] remove use of eel string truncation



Hi;
There is a problem with eel_str_middle_truncate in that is produces
invalid UTF-8 (see bug #409271). And anyway nautilus shouldn't truncate
the strings arbitrarily like that, but use pango ellipsisation instead,
which handles compose characters etc. correctly. Attached patch [ from
http://bugzilla.gnome.org/show_bug.cgi?id=410113 ] removes some uses of
eel_str_middle_truncate from nautilus; ok to commit ?

The remaining uses of eel_str_middle_truncate are harder to get rid of,
since they concern the use of potentially long strings embedded into
other text (dialogues) and the window title, where we cannot use pango
ellipsisation.

Regards,
	Christian
Index: src/nautilus-window-menus.c
===================================================================
--- src/nautilus-window-menus.c	(révision 13021)
+++ src/nautilus-window-menus.c	(copie de travail)
@@ -152,8 +152,9 @@ nautilus_menus_append_bookmark_to_menu (
 					GCallback refresh_callback,
 					NautilusBookmarkFailedCallback failed_callback)
 {
-	BookmarkHolder *bookmark_holder;		
-	char *raw_name, *display_name, *truncated_name, *action_name;
+	BookmarkHolder *bookmark_holder;
+	char action_name[128];
+	char *name;
 	GdkPixbuf *pixbuf;
 	GtkAction *action;
 
@@ -161,25 +162,15 @@ nautilus_menus_append_bookmark_to_menu (
 	g_assert (NAUTILUS_IS_BOOKMARK (bookmark));
 
 	bookmark_holder = bookmark_holder_new (bookmark, window, refresh_callback, failed_callback);
-
-	/* We double the underscores here to escape them so gtk+ will know they are
-	 * not keyboard accelerator character prefixes. If we ever find we need to
-	 * escape more than just the underscores, we'll add a menu helper function
-	 * instead of a string utility. (Like maybe escaping control characters.)
-	 */
-	raw_name = nautilus_bookmark_get_name (bookmark);
-	truncated_name = eel_truncate_text_for_menu_item (raw_name);
-	display_name = eel_str_double_underscores (truncated_name);
-	g_free (raw_name);
-	g_free (truncated_name);
+	name = nautilus_bookmark_get_name (bookmark);
 
 	/* Create menu item with pixbuf */
 	pixbuf = nautilus_bookmark_get_pixbuf (bookmark, GTK_ICON_SIZE_MENU);
 
-	action_name = g_strdup_printf ("bookmark_%s_%d", parent_id, index_in_parent);
+	g_snprintf (action_name, sizeof (action_name), "%s%d", parent_id, index_in_parent);
 
 	action = gtk_action_new (action_name,
-				 display_name,
+				 name,
 				 _("Go to the location specified by this bookmark"),
 				 NULL);
 	
@@ -206,8 +197,7 @@ nautilus_menus_append_bookmark_to_menu (
 			       FALSE);
 
 	g_object_unref (pixbuf);
-	g_free (action_name);
-	g_free (display_name);
+	g_free (name);
 }
 
 static void
Index: src/nautilus-application.c
===================================================================
--- src/nautilus-application.c	(révision 13021)
+++ src/nautilus-application.c	(copie de travail)
@@ -58,6 +58,7 @@
 #include "nautilus-window-manage-views.h"
 #include <libxml/xmlsave.h>
 #include <glib/gstdio.h>
+#include <glib/gi18n.h>
 #include <bonobo/bonobo-main.h>
 #include <bonobo/bonobo-object.h>
 #include <eel/eel-gtk-extensions.h>
@@ -70,7 +71,6 @@
 #include <gtk/gtksignal.h>
 #include <gtk/gtkwindow.h>
 #include <libgnome/gnome-config.h>
-#include <glib/gi18n.h>
 #include <libgnome/gnome-util.h>
 #include <libgnomeui/gnome-authentication-manager.h>
 #include <libgnomeui/gnome-client.h>
Index: src/nautilus-bookmark-list.c
===================================================================
--- src/nautilus-bookmark-list.c	(révision 13021)
+++ src/nautilus-bookmark-list.c	(copie de travail)
@@ -72,20 +72,6 @@ static void 	   bookmark_monitor_notify_
 		            				 GnomeVFSMonitorEventType  event_type,
 		            				 gpointer                  user_data);
 
-
-static char *
-get_default_bookmark_name (const char *text_uri)
-{
-	char *title, *title_truncated;
-
-	title = nautilus_compute_title_for_uri (text_uri);
-	title_truncated = eel_str_middle_truncate (title, MAX_BOOKMARK_LENGTH);	
-	g_free (title);
-
-	return title_truncated;
-
-}
-
 static NautilusBookmark *
 new_bookmark_from_uri (const char *uri, const char *label)
 {
@@ -96,7 +82,7 @@ new_bookmark_from_uri (const char *uri, 
 
 	has_label = FALSE;
 	if (!label) { 
-		name = get_default_bookmark_name (uri);
+		name = nautilus_compute_title_for_uri (uri);
 	} else {
 		name = g_strdup (label);
 		has_label = TRUE;
Index: src/nautilus-navigation-window-menus.c
===================================================================
--- src/nautilus-navigation-window-menus.c	(révision 13021)
+++ src/nautilus-navigation-window-menus.c	(copie de travail)
@@ -65,6 +65,7 @@
 #define MENU_PATH_HISTORY_PLACEHOLDER			"/MenuBar/Other Menus/Go/History Placeholder"
 
 #define RESPONSE_FORGET		1000
+#define MENU_ITEM_MAX_WIDTH_CHARS 32
 
 static void                  schedule_refresh_go_menu                      (NautilusNavigationWindow   *window);
 
@@ -296,6 +297,23 @@ show_bogus_history_window (NautilusWindo
 	g_free (detail);
 }
 
+static void
+connect_proxy_cb (GtkActionGroup *action_group,
+                  GtkAction *action,
+                  GtkWidget *proxy,
+                  gpointer dummy)
+{
+	GtkLabel *label;
+
+	if (!GTK_IS_MENU_ITEM (proxy))
+		return;
+
+	label = GTK_LABEL (GTK_BIN (proxy)->child);
+
+	gtk_label_set_use_underline (label, FALSE);
+	gtk_label_set_ellipsize (label, PANGO_ELLIPSIZE_END);
+	gtk_label_set_max_width_chars (label, MENU_ITEM_MAX_WIDTH_CHARS);
+}
 
 /**
  * refresh_go_menu:
@@ -322,6 +340,8 @@ refresh_go_menu (NautilusNavigationWindo
 
 	window->details->go_menu_merge_id = gtk_ui_manager_new_merge_id (ui_manager);
 	window->details->go_menu_action_group = gtk_action_group_new ("GoMenuGroup");
+	g_signal_connect (window->details->go_menu_action_group, "connect-proxy",
+			  G_CALLBACK (connect_proxy_cb), NULL);
 
 	gtk_ui_manager_insert_action_group (ui_manager,
 					    window->details->go_menu_action_group,
Index: src/nautilus-property-browser.c
===================================================================
--- src/nautilus-property-browser.c	(révision 13021)
+++ src/nautilus-property-browser.c	(copie de travail)
@@ -1760,7 +1760,6 @@ make_properties_from_directories (Nautil
 	} else {
 		customization_data = nautilus_customization_data_new (property_browser->details->category,
 								      !property_browser->details->remove_mode,
-								      FALSE,
 								      MAX_ICON_WIDTH,
 								      MAX_ICON_HEIGHT);
 		if (customization_data == NULL) {
Index: src/nautilus-window-bookmarks.c
===================================================================
--- src/nautilus-window-bookmarks.c	(révision 13021)
+++ src/nautilus-window-bookmarks.c	(copie de travail)
@@ -39,6 +39,8 @@
 #include <eel/eel-vfs-extensions.h>
 #include <eel/eel-gtk-extensions.h>
 
+#define MENU_ITEM_MAX_WIDTH_CHARS 32
+
 static GtkWindow *bookmarks_window = NULL;
 static NautilusBookmarkList *bookmarks = NULL;
 
@@ -201,6 +203,24 @@ remove_bookmarks_menu_items (NautilusWin
 }
 
 static void
+connect_proxy_cb (GtkActionGroup *action_group,
+                  GtkAction *action,
+                  GtkWidget *proxy,
+                  gpointer dummy)
+{
+	GtkLabel *label;
+
+	if (!GTK_IS_MENU_ITEM (proxy))
+		return;
+
+	label = GTK_LABEL (GTK_BIN (proxy)->child);
+
+	gtk_label_set_use_underline (label, FALSE);
+	gtk_label_set_ellipsize (label, PANGO_ELLIPSIZE_END);
+	gtk_label_set_max_width_chars (label, MENU_ITEM_MAX_WIDTH_CHARS);
+}
+
+static void
 update_bookmarks (NautilusWindow *window)
 {
         NautilusBookmarkList *bookmarks;
@@ -219,6 +239,8 @@ update_bookmarks (NautilusWindow *window
 	
 	window->details->bookmarks_merge_id = gtk_ui_manager_new_merge_id (ui_manager);
 	window->details->bookmarks_action_group = gtk_action_group_new ("BookmarksGroup");
+	g_signal_connect (window->details->bookmarks_action_group, "connect-proxy",
+			  G_CALLBACK (connect_proxy_cb), NULL);
 
 	gtk_ui_manager_insert_action_group (ui_manager,
 					    window->details->bookmarks_action_group,
Index: src/nautilus-places-sidebar.c
===================================================================
--- src/nautilus-places-sidebar.c	(révision 13021)
+++ src/nautilus-places-sidebar.c	(copie de travail)
@@ -766,16 +766,18 @@ drag_leave_callback (GtkTreeView *tree_v
 /* Parses a "text/uri-list" string and inserts its URIs as bookmarks */
 static void
 bookmarks_drop_uris (NautilusPlacesSidebar *sidebar,
-		     const char            *data,
+		     GtkSelectionData      *selection_data,
 		     int                    position)
 {
 	NautilusBookmark *bookmark;
 	NautilusFile *file;
-	char *uri, *name, *name_truncated;
+	char *uri, *name;
 	char **uris;
 	int i;
 	
-	uris = g_uri_list_extract_uris (data);
+	uris = gtk_selection_data_get_uris (selection_data);
+	if (!uris)
+		return;
 	
 	for (i = 0; uris[i]; i++) {
 		uri = uris[i];
@@ -790,9 +792,8 @@ bookmarks_drop_uris (NautilusPlacesSideb
 		nautilus_file_unref (file);
 
 		name = nautilus_compute_title_for_uri (uri);
-		name_truncated = eel_truncate_text_for_menu_item (name);	
 
-		bookmark = nautilus_bookmark_new_with_icon (uri, name_truncated,
+		bookmark = nautilus_bookmark_new_with_icon (uri, name,
 							    FALSE, "gnome-fs-directory");
 		
 		if (!nautilus_bookmark_list_contains (sidebar->bookmarks, bookmark)) {
@@ -800,7 +801,6 @@ bookmarks_drop_uris (NautilusPlacesSideb
 		}
 
 		g_object_unref (bookmark);
-		g_free (name_truncated);
 		g_free (name);
 		g_free (uri);
 	}
@@ -964,7 +964,7 @@ drag_data_received_callback (GtkWidget *
 	
 		switch (info) {
 		case TEXT_URI_LIST:
-			bookmarks_drop_uris (sidebar, selection_data->data, position);
+			bookmarks_drop_uris (sidebar, selection_data, position);
 			success = TRUE;
 			break;
 		case GTK_TREE_MODEL_ROW:
Index: test/test-nautilus-wrap-table.c
===================================================================
--- test/test-nautilus-wrap-table.c	(révision 13021)
+++ test/test-nautilus-wrap-table.c	(copie de travail)
@@ -53,7 +53,7 @@ main (int argc, char* argv[])
 
 
 	/* Use nautilus_customization to make the emblem widgets */
-	customization_data = nautilus_customization_data_new ("emblems", TRUE, TRUE,
+	customization_data = nautilus_customization_data_new ("emblems", TRUE,
 							      NAUTILUS_ICON_SIZE_SMALL, 
 							      NAUTILUS_ICON_SIZE_SMALL);
 	
Index: libnautilus-private/nautilus-bookmark.c
===================================================================
--- libnautilus-private/nautilus-bookmark.c	(révision 13021)
+++ libnautilus-private/nautilus-bookmark.c	(copie de travail)
@@ -50,6 +50,8 @@ enum {
 #define GENERIC_BOOKMARK_ICON_NAME	"gnome-fs-bookmark"
 #define MISSING_BOOKMARK_ICON_NAME	"gnome-fs-bookmark-missing"
 
+#define ELLIPSISED_MENU_ITEM_MIN_CHARS  32
+
 static guint signals[LAST_SIGNAL];
 
 struct NautilusBookmarkDetails
@@ -525,10 +527,13 @@ nautilus_bookmark_menu_item_new (Nautilu
 {
 	GtkWidget *menu_item;
 	GtkWidget *image_widget;
-	GtkWidget *label;
-	char *display_name;
+	GtkLabel *label;
 	
-	menu_item = gtk_image_menu_item_new ();
+	menu_item = gtk_image_menu_item_new_with_label (bookmark->details->name);
+	label = GTK_LABEL (GTK_BIN (menu_item)->child);
+	gtk_label_set_use_underline (label, FALSE);
+	gtk_label_set_ellipsize (label, PANGO_ELLIPSIZE_END);
+	gtk_label_set_max_width_chars (label, ELLIPSISED_MENU_ITEM_MIN_CHARS);
 
 	image_widget = create_image_widget_for_bookmark (bookmark);
 	if (image_widget != NULL) {
@@ -536,13 +541,6 @@ nautilus_bookmark_menu_item_new (Nautilu
 		gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item),
 					       image_widget);
 	}
-	display_name = eel_truncate_text_for_menu_item (bookmark->details->name);
-	label = gtk_label_new (display_name);
-	g_free (display_name);
-	gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
-
-	gtk_container_add (GTK_CONTAINER (menu_item), label);
-	gtk_widget_show (label);
 
 	return menu_item;
 }
Index: libnautilus-private/nautilus-customization-data.c
===================================================================
--- libnautilus-private/nautilus-customization-data.c	(révision 13021)
+++ libnautilus-private/nautilus-customization-data.c	(copie de travail)
@@ -56,7 +56,6 @@ typedef enum {
 
 struct NautilusCustomizationData {
 	char *customization_name;
-	CustomizationReadingMode reading_mode;
 
 	GList *public_file_list;	
 	GList *private_file_list;
@@ -66,10 +65,11 @@ struct NautilusCustomizationData {
 	
 	GdkPixbuf *pattern_frame;
 
-	gboolean private_data_was_displayed;
-	gboolean data_is_for_a_menu;
 	int maximum_icon_height;
 	int maximum_icon_width;
+
+	guint private_data_was_displayed : 1;
+	guint reading_mode : 2; /* enough bits for CustomizationReadingMode */
 };
 
 
@@ -85,7 +85,6 @@ static void		 load_name_map_hash_table	 
 NautilusCustomizationData* 
 nautilus_customization_data_new (const char *customization_name,
 				 gboolean show_public_customizations,
-				 gboolean data_is_for_a_menu,
 				 int maximum_icon_height,
 				 int maximum_icon_width)
 {
@@ -142,7 +141,6 @@ nautilus_customization_data_new (const c
 	}
 
 	data->private_data_was_displayed = FALSE;
-	data->data_is_for_a_menu = data_is_for_a_menu;
 	data->customization_name = g_strdup (customization_name);
 
 	data->maximum_icon_height = maximum_icon_height;
@@ -160,8 +158,7 @@ nautilus_customization_data_get_next_ele
 							  char **label_out)
 {
 	GnomeVFSFileInfo *current_file_info;
-
-	char *image_file_name, *filtered_name;
+	char *image_file_name;
 	GdkPixbuf *pixbuf;
 	GdkPixbuf *orig_pixbuf;
 	gboolean is_reset_image;
@@ -238,19 +235,7 @@ nautilus_customization_data_get_next_ele
 	
 	*pixbuf_out = pixbuf;
 	
-	filtered_name = format_name_for_display (data, current_file_info->name);
-	/* If the data is for a menu,
-	   we want to truncate it and not use the nautilus
-	   label because anti-aliased text doesn't look right
-	   in menus */
-	if (data->data_is_for_a_menu) {
-		*label_out = eel_truncate_text_for_menu_item (filtered_name);
-	}
-	else {
-		*label_out = g_strdup (filtered_name);
-	}
-	
-	g_free (filtered_name);
+	*label_out = format_name_for_display (data, current_file_info->name);
 
 	if (data->reading_mode == READ_PRIVATE_CUSTOMIZATIONS) {
 		data->private_data_was_displayed = TRUE;
Index: libnautilus-private/nautilus-customization-data.h
===================================================================
--- libnautilus-private/nautilus-customization-data.h	(révision 13021)
+++ libnautilus-private/nautilus-customization-data.h	(copie de travail)
@@ -42,7 +42,6 @@ typedef struct NautilusCustomizationData
 
 NautilusCustomizationData* nautilus_customization_data_new                          (const char *customization_name,
 										     gboolean show_public_customizations,
-										     gboolean data_is_for_a_menu,
 										     int maximum_icon_height,
 										     int maximum_icon_width);
 


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