Commit ee2c880e authored by Christian Persch's avatar Christian Persch Committed by Christian Persch

Use pango ellipsisation instead of truncating the strings. Bug #410113.

2007-07-24  Christian Persch  <chpe@gnome.org>

	* libnautilus-private/nautilus-bookmark.c:
	(nautilus_bookmark_menu_item_new):
	* libnautilus-private/nautilus-customization-data.c:
	(nautilus_customization_data_new),
	(nautilus_customization_data_get_next_element_for_display):
	* libnautilus-private/nautilus-customization-data.h:
	* src/nautilus-application.c:
	* src/nautilus-bookmark-list.c: (new_bookmark_from_uri):
	* src/nautilus-navigation-window-menus.c: (connect_proxy_cb),
	(refresh_go_menu):
	* src/nautilus-places-sidebar.c: (bookmarks_drop_uris),
	(drag_data_received_callback):
	* src/nautilus-property-browser.c:
	(make_properties_from_directories):
	* src/nautilus-window-bookmarks.c: (connect_proxy_cb),
	(update_bookmarks):
	* src/nautilus-window-menus.c:
	(nautilus_menus_append_bookmark_to_menu):
	* test/test-nautilus-wrap-table.c: (main): Use pango ellipsisation
	instead of truncating the strings. Bug #410113.

svn path=/trunk/; revision=13025
parent 32ec3056
2007-07-24 Christian Persch <chpe@gnome.org>
* libnautilus-private/nautilus-bookmark.c:
(nautilus_bookmark_menu_item_new):
* libnautilus-private/nautilus-customization-data.c:
(nautilus_customization_data_new),
(nautilus_customization_data_get_next_element_for_display):
* libnautilus-private/nautilus-customization-data.h:
* src/nautilus-application.c:
* src/nautilus-bookmark-list.c: (new_bookmark_from_uri):
* src/nautilus-navigation-window-menus.c: (connect_proxy_cb),
(refresh_go_menu):
* src/nautilus-places-sidebar.c: (bookmarks_drop_uris),
(drag_data_received_callback):
* src/nautilus-property-browser.c:
(make_properties_from_directories):
* src/nautilus-window-bookmarks.c: (connect_proxy_cb),
(update_bookmarks):
* src/nautilus-window-menus.c:
(nautilus_menus_append_bookmark_to_menu):
* test/test-nautilus-wrap-table.c: (main): Use pango ellipsisation
instead of truncating the strings. Bug #410113.
2007-07-24 Christian Persch <chpe@gnome.org>
* src/nautilus-navigation-window.c: (location_button_create),
......
......@@ -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 (NautilusBookmark *bookmark)
{
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 (NautilusBookmark *bookmark)
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;
}
......
......@@ -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 *data);
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 char *customization_name,
}
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_element_for_display (NautilusCustomizationD
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_element_for_display (NautilusCustomizationD
*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;
......
......@@ -42,7 +42,6 @@ typedef struct NautilusCustomizationData 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);
......
......@@ -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>
......
......@@ -72,20 +72,6 @@ static void bookmark_monitor_notify_cb (GnomeVFSMonitorHandle *handle,
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, const char *label)
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;
......
......@@ -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 (NautilusWindow *window,
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 (NautilusNavigationWindow *window)
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,
......
......@@ -766,16 +766,18 @@ drag_leave_callback (GtkTreeView *tree_view,
/* 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 (NautilusPlacesSidebar *sidebar,
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 (NautilusPlacesSidebar *sidebar,
}
g_object_unref (bookmark);
g_free (name_truncated);
g_free (name);
g_free (uri);
}
......@@ -964,7 +964,7 @@ drag_data_received_callback (GtkWidget *widget,
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:
......
......@@ -1760,7 +1760,6 @@ make_properties_from_directories (NautilusPropertyBrowser *property_browser)
} 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) {
......
......@@ -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;
......@@ -200,6 +202,24 @@ remove_bookmarks_menu_items (NautilusWindow *window)
}
}
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)
{
......@@ -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,
......
......@@ -152,8 +152,9 @@ nautilus_menus_append_bookmark_to_menu (NautilusWindow *window,
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 (NautilusWindow *window,
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 (NautilusWindow *window,
FALSE);
g_object_unref (pixbuf);
g_free (action_name);
g_free (display_name);
g_free (name);
}
static void
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment