Fixed bug 884 (Long URI in Go menu doesn't get cut off)

Fixed bug 2667 (Really long bookmark titles stretch bookmarks menu)

	* libnautilus-extensions/nautilus-gtk-extensions.h:
	* libnautilus-extensions/nautilus-gtk-extensions.c:
	(nautilus_truncate_text_for_menu_item): New function,
	uses nautilus_str_middle_truncate to create a string
	that isn't ridiculously long.

	* libnautilus-extensions/nautilus-bookmark.c:
	(nautilus_bookmark_menu_item_new): Use new function to
	keep the menu items in the Back/Forward context menus
	from getting too wide.
	* src/nautilus-window-menus.c: (append_bookmark_to_menu):
	Use new function to keep the menu items in the Go and
	Bookmarks menus from getting too wide.
This commit is contained in:
John Sullivan 2000-09-12 19:41:41 +00:00
parent 94a464a469
commit 958002b326
9 changed files with 91 additions and 22 deletions

View file

@ -1,3 +1,22 @@
2000-09-12 John Sullivan <sullivan@eazel.com>
Fixed bug 884 (Long URI in Go menu doesn't get cut off)
Fixed bug 2667 (Really long bookmark titles stretch bookmarks menu)
* libnautilus-extensions/nautilus-gtk-extensions.h:
* libnautilus-extensions/nautilus-gtk-extensions.c:
(nautilus_truncate_text_for_menu_item): New function,
uses nautilus_str_middle_truncate to create a string
that isn't ridiculously long.
* libnautilus-extensions/nautilus-bookmark.c:
(nautilus_bookmark_menu_item_new): Use new function to
keep the menu items in the Back/Forward context menus
from getting too wide.
* src/nautilus-window-menus.c: (append_bookmark_to_menu):
Use new function to keep the menu items in the Go and
Bookmarks menus from getting too wide.
2000-09-12 Gene Z. Ragan <gzr@eazel.com>
Work in progress on making the expander UI in the tree view

View file

@ -38,6 +38,7 @@
#include <libgnomevfs/gnome-vfs-utils.h>
#include <libnautilus-extensions/nautilus-file-utilities.h>
#include <libnautilus-extensions/nautilus-gdk-pixbuf-extensions.h>
#include <libnautilus-extensions/nautilus-gtk-extensions.h>
enum {
CHANGED,
@ -522,7 +523,8 @@ nautilus_bookmark_menu_item_new (NautilusBookmark *bookmark)
{
GtkWidget *menu_item;
GtkWidget *pixmap_widget;
GtkWidget *accel_label;
GtkWidget *label;
char *display_name;
/* Could check gnome_preferences_get_menus_have_icons here, but these
* are more important than stock menu icons, since they're connected to
@ -536,12 +538,13 @@ nautilus_bookmark_menu_item_new (NautilusBookmark *bookmark)
gtk_widget_show (pixmap_widget);
gtk_pixmap_menu_item_set_pixmap (GTK_PIXMAP_MENU_ITEM (menu_item), pixmap_widget);
}
accel_label = gtk_accel_label_new (bookmark->details->name);
gtk_misc_set_alignment (GTK_MISC (accel_label), 0.0, 0.5);
display_name = nautilus_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), accel_label);
gtk_accel_label_set_accel_widget (GTK_ACCEL_LABEL (accel_label), menu_item);
gtk_widget_show (accel_label);
gtk_container_add (GTK_CONTAINER (menu_item), label);
gtk_widget_show (label);
return menu_item;
}

View file

@ -32,12 +32,18 @@
#include <gtk/gtksignal.h>
#include <libgnomeui/gnome-geometry.h>
#include "nautilus-glib-extensions.h"
#include "nautilus-string.h"
/* This number should be large enough to be visually noticeable,
* but small enough to not allow the user to perform other actions.
*/
#define BUTTON_AUTO_HIGHLIGHT_MILLISECONDS 100
/* This number is fairly arbitrary. Long enough to show a pretty long
* menu title, but not so long to make a menu grotesquely wide.
*/
#define MAXIMUM_MENU_TITLE_LENGTH 48
static gboolean
finish_button_activation (gpointer data)
{
@ -368,6 +374,19 @@ nautilus_popup_menu_position_func (GtkMenu *menu,
*y = CLAMP (*y + (int) offset->y, 0, MAX (0, gdk_screen_height () - requisition.height));
}
/**
* nautilus_truncate_text_for_menu_item:
*
* Given an arbitrary string, returns a newly-allocated string
* suitable for use as a menu item label. Truncates long strings
* in the middle.
*/
char *
nautilus_truncate_text_for_menu_item (const char *text)
{
return nautilus_str_middle_truncate (text, MAXIMUM_MENU_TITLE_LENGTH);
}
/**
* nautilus_pop_up_context_menu:
*

View file

@ -99,7 +99,8 @@ void nautilus_gtk_window_present (GtkWindow
GtkSelectionData *nautilus_gtk_selection_data_copy_deep (const GtkSelectionData *selection_data);
void nautilus_gtk_selection_data_free_deep (GtkSelectionData *selection_data);
/* GtkMenu */
/* GtkMenu and GtkMenuItem */
char * nautilus_truncate_text_for_menu_item (const char *text);
void nautilus_pop_up_context_menu (GtkMenu *menu,
gint16 offset_x,
gint16 offset_y,

View file

@ -38,6 +38,7 @@
#include <libgnomevfs/gnome-vfs-utils.h>
#include <libnautilus-extensions/nautilus-file-utilities.h>
#include <libnautilus-extensions/nautilus-gdk-pixbuf-extensions.h>
#include <libnautilus-extensions/nautilus-gtk-extensions.h>
enum {
CHANGED,
@ -522,7 +523,8 @@ nautilus_bookmark_menu_item_new (NautilusBookmark *bookmark)
{
GtkWidget *menu_item;
GtkWidget *pixmap_widget;
GtkWidget *accel_label;
GtkWidget *label;
char *display_name;
/* Could check gnome_preferences_get_menus_have_icons here, but these
* are more important than stock menu icons, since they're connected to
@ -536,12 +538,13 @@ nautilus_bookmark_menu_item_new (NautilusBookmark *bookmark)
gtk_widget_show (pixmap_widget);
gtk_pixmap_menu_item_set_pixmap (GTK_PIXMAP_MENU_ITEM (menu_item), pixmap_widget);
}
accel_label = gtk_accel_label_new (bookmark->details->name);
gtk_misc_set_alignment (GTK_MISC (accel_label), 0.0, 0.5);
display_name = nautilus_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), accel_label);
gtk_accel_label_set_accel_widget (GTK_ACCEL_LABEL (accel_label), menu_item);
gtk_widget_show (accel_label);
gtk_container_add (GTK_CONTAINER (menu_item), label);
gtk_widget_show (label);
return menu_item;
}

View file

@ -32,12 +32,18 @@
#include <gtk/gtksignal.h>
#include <libgnomeui/gnome-geometry.h>
#include "nautilus-glib-extensions.h"
#include "nautilus-string.h"
/* This number should be large enough to be visually noticeable,
* but small enough to not allow the user to perform other actions.
*/
#define BUTTON_AUTO_HIGHLIGHT_MILLISECONDS 100
/* This number is fairly arbitrary. Long enough to show a pretty long
* menu title, but not so long to make a menu grotesquely wide.
*/
#define MAXIMUM_MENU_TITLE_LENGTH 48
static gboolean
finish_button_activation (gpointer data)
{
@ -368,6 +374,19 @@ nautilus_popup_menu_position_func (GtkMenu *menu,
*y = CLAMP (*y + (int) offset->y, 0, MAX (0, gdk_screen_height () - requisition.height));
}
/**
* nautilus_truncate_text_for_menu_item:
*
* Given an arbitrary string, returns a newly-allocated string
* suitable for use as a menu item label. Truncates long strings
* in the middle.
*/
char *
nautilus_truncate_text_for_menu_item (const char *text)
{
return nautilus_str_middle_truncate (text, MAXIMUM_MENU_TITLE_LENGTH);
}
/**
* nautilus_pop_up_context_menu:
*

View file

@ -99,7 +99,8 @@ void nautilus_gtk_window_present (GtkWindow
GtkSelectionData *nautilus_gtk_selection_data_copy_deep (const GtkSelectionData *selection_data);
void nautilus_gtk_selection_data_free_deep (GtkSelectionData *selection_data);
/* GtkMenu */
/* GtkMenu and GtkMenuItem */
char * nautilus_truncate_text_for_menu_item (const char *text);
void nautilus_pop_up_context_menu (GtkMenu *menu,
gint16 offset_x,
gint16 offset_y,

View file

@ -842,7 +842,7 @@ append_bookmark_to_menu (NautilusWindow *window,
BookmarkHolder *bookmark_holder;
GdkPixbuf *pixbuf;
BonoboUIHandlerPixmapType pixmap_type;
char *raw_name, *name;
char *raw_name, *display_name, *truncated_name;
pixbuf = nautilus_bookmark_get_pixbuf (bookmark, NAUTILUS_ICON_SIZE_FOR_MENUS);
@ -861,11 +861,13 @@ append_bookmark_to_menu (NautilusWindow *window,
* instead of a string utility. (Like maybe escaping control characters.)
*/
raw_name = nautilus_bookmark_get_name (bookmark);
name = nautilus_str_double_underscores (raw_name);
truncated_name = nautilus_truncate_text_for_menu_item (raw_name);
display_name = nautilus_str_double_underscores (truncated_name);
g_free (raw_name);
g_free (truncated_name);
bonobo_ui_handler_menu_new_item (window->ui_handler,
menu_item_path,
name,
display_name,
_("Go to the specified location"),
-1,
pixmap_type,
@ -874,7 +876,7 @@ append_bookmark_to_menu (NautilusWindow *window,
0,
NULL,
NULL);
g_free (name);
g_free (display_name);
/* We must use "set_callback" since we have a destroy-notify function. */
bonobo_ui_handler_menu_set_callback

View file

@ -842,7 +842,7 @@ append_bookmark_to_menu (NautilusWindow *window,
BookmarkHolder *bookmark_holder;
GdkPixbuf *pixbuf;
BonoboUIHandlerPixmapType pixmap_type;
char *raw_name, *name;
char *raw_name, *display_name, *truncated_name;
pixbuf = nautilus_bookmark_get_pixbuf (bookmark, NAUTILUS_ICON_SIZE_FOR_MENUS);
@ -861,11 +861,13 @@ append_bookmark_to_menu (NautilusWindow *window,
* instead of a string utility. (Like maybe escaping control characters.)
*/
raw_name = nautilus_bookmark_get_name (bookmark);
name = nautilus_str_double_underscores (raw_name);
truncated_name = nautilus_truncate_text_for_menu_item (raw_name);
display_name = nautilus_str_double_underscores (truncated_name);
g_free (raw_name);
g_free (truncated_name);
bonobo_ui_handler_menu_new_item (window->ui_handler,
menu_item_path,
name,
display_name,
_("Go to the specified location"),
-1,
pixmap_type,
@ -874,7 +876,7 @@ append_bookmark_to_menu (NautilusWindow *window,
0,
NULL,
NULL);
g_free (name);
g_free (display_name);
/* We must use "set_callback" since we have a destroy-notify function. */
bonobo_ui_handler_menu_set_callback