aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Persch <chpe@cvs.gnome.org>2004-10-27 06:14:05 +0800
committerChristian Persch <chpe@src.gnome.org>2004-10-27 06:14:05 +0800
commit86c2f402bbc078f538bccce5b2c52546fb7a185a (patch)
tree4f5fa4e8e53eced0790ba85c19a84ec3167a9b43
parentd51326e6b1a458b57cfae445fda4ed4b97b715a6 (diff)
downloadgsoc2013-epiphany-86c2f402bbc078f538bccce5b2c52546fb7a185a.tar
gsoc2013-epiphany-86c2f402bbc078f538bccce5b2c52546fb7a185a.tar.gz
gsoc2013-epiphany-86c2f402bbc078f538bccce5b2c52546fb7a185a.tar.bz2
gsoc2013-epiphany-86c2f402bbc078f538bccce5b2c52546fb7a185a.tar.lz
gsoc2013-epiphany-86c2f402bbc078f538bccce5b2c52546fb7a185a.tar.xz
gsoc2013-epiphany-86c2f402bbc078f538bccce5b2c52546fb7a185a.tar.zst
gsoc2013-epiphany-86c2f402bbc078f538bccce5b2c52546fb7a185a.zip
Use ellipsising labels to shorten the bookmarks and topics titles in
2004-10-27 Christian Persch <chpe@cvs.gnome.org> * src/bookmarks/ephy-bookmark-action.c: (create_tool_item), (ephy_bookmark_action_sync_label), (connect_proxy), (bookmark_changed_cb): * src/bookmarks/ephy-bookmarks-menu.c: (connect_proxy_cb), (ensure_bookmark_actions), (ephy_bookmarks_menu_rebuild): * src/bookmarks/ephy-favorites-menu.c: (connect_proxy_cb), (ephy_favorites_menu_rebuild): * src/bookmarks/ephy-topic-action.c: (ephy_topic_action_sync_label), (append_bookmarks_menu), (build_topics_menu), (connect_proxy), (topic_changed_cb): Use ellipsising labels to shorten the bookmarks and topics titles in menus, instead of chopping the strings off at the end. Fixes bug #147765. Use gtk_entry_set_width_chars() to set the smart bookmark entry width, not gtk_widget_set_size_request().
-rw-r--r--ChangeLog20
-rw-r--r--src/bookmarks/ephy-bookmark-action.c77
-rw-r--r--src/bookmarks/ephy-bookmarks-menu.c22
-rw-r--r--src/bookmarks/ephy-favorites-menu.c22
-rw-r--r--src/bookmarks/ephy-topic-action.c77
5 files changed, 142 insertions, 76 deletions
diff --git a/ChangeLog b/ChangeLog
index e029542e2..47d427609 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2004-10-27 Christian Persch <chpe@cvs.gnome.org>
+
+ * src/bookmarks/ephy-bookmark-action.c: (create_tool_item),
+ (ephy_bookmark_action_sync_label), (connect_proxy),
+ (bookmark_changed_cb):
+ * src/bookmarks/ephy-bookmarks-menu.c: (connect_proxy_cb),
+ (ensure_bookmark_actions), (ephy_bookmarks_menu_rebuild):
+ * src/bookmarks/ephy-favorites-menu.c: (connect_proxy_cb),
+ (ephy_favorites_menu_rebuild):
+ * src/bookmarks/ephy-topic-action.c:
+ (ephy_topic_action_sync_label), (append_bookmarks_menu),
+ (build_topics_menu), (connect_proxy), (topic_changed_cb):
+
+ Use ellipsising labels to shorten the bookmarks and topics titles in
+ menus, instead of chopping the strings off at the end.
+ Fixes bug #147765.
+
+ Use gtk_entry_set_width_chars() to set the smart bookmark entry width,
+ not gtk_widget_set_size_request().
+
2004-10-26 Christian Persch <chpe@cvs.gnome.org>
* src/ephy-session.c: (offer_to_resume):
diff --git a/src/bookmarks/ephy-bookmark-action.c b/src/bookmarks/ephy-bookmark-action.c
index 25432d755..33b04ba55 100644
--- a/src/bookmarks/ephy-bookmark-action.c
+++ b/src/bookmarks/ephy-bookmark-action.c
@@ -35,14 +35,12 @@
#include "ephy-bookmark-properties.h"
#include "ephy-favicon-cache.h"
#include "ephy-shell.h"
-#include "ephy-string.h"
#include "ephy-debug.h"
+#include "ephy-string.h"
#include "ephy-gui.h"
#include <string.h>
-#define MAX_LABEL_LENGTH 32
-
static void ephy_bookmark_action_init (EphyBookmarkAction *action);
static void ephy_bookmark_action_class_init (EphyBookmarkActionClass *class);
@@ -114,6 +112,9 @@ ephy_bookmark_action_get_type (void)
return type;
}
+/* FIXME tweak this, or make it configurable? (bug 148093) */
+#define ENTRY_WIDTH_CHARS 16
+
static GtkWidget *
create_tool_item (GtkAction *action)
{
@@ -135,7 +136,7 @@ create_tool_item (GtkAction *action)
g_object_set_data (G_OBJECT (item), "button", button);
entry = gtk_entry_new ();
- gtk_widget_set_size_request (entry, 120, -1);
+ gtk_entry_set_width_chars (GTK_ENTRY (entry), ENTRY_WIDTH_CHARS);
gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
g_object_set_data (G_OBJECT (item), "entry", entry);
@@ -264,45 +265,48 @@ ephy_bookmark_action_sync_icon (GtkAction *action, GParamSpec *pspec, GtkWidget
}
}
+#define MAX_LABEL_LENGTH 32
+
static void
-ephy_bookmark_action_sync_label (GtkAction *action, GParamSpec *pspec, GtkWidget *proxy)
+ephy_bookmark_action_sync_label (GtkAction *gaction,
+ GParamSpec *pspec,
+ GtkWidget *proxy)
{
- GtkWidget *label = NULL;
- GValue value = { 0, };
+ EphyBookmarkAction *action = EPHY_BOOKMARK_ACTION (gaction);
- g_value_init (&value, G_TYPE_STRING);
- g_object_get_property (G_OBJECT (action), "label", &value);
+ g_return_if_fail (EPHY_IS_NODE (action->priv->node));
- if (EPHY_BOOKMARK_ACTION (action)->priv->smart_url
- && GTK_IS_TOOL_ITEM (proxy))
+ /* note that we cannot use ellipsizing label with defined width,
+ * since that makes the label exactly that wide, even if the
+ * text takes less space. So we have to shorten the string.
+ */
+ if (GTK_IS_TOOL_ITEM (proxy))
{
- char *label_text;
-
- label_text = g_strdup_printf (_("%s:"), g_value_get_string (&value));
+ GtkWidget *label = NULL;
+ const char *title;
+ char *title_short, *label_text;
label = g_object_get_data (G_OBJECT (proxy), "label");
g_return_if_fail (label != NULL);
- gtk_label_set_label (GTK_LABEL (label), label_text);
- g_free (label_text);
- }
- else
- {
- if (GTK_IS_TOOL_ITEM (proxy))
+ title = ephy_node_get_property_string
+ (action->priv->node, EPHY_NODE_BMK_PROP_TITLE);
+ title_short = ephy_string_shorten (title, MAX_LABEL_LENGTH);
+
+ if (EPHY_BOOKMARK_ACTION (action)->priv->smart_url)
{
- label = g_object_get_data (G_OBJECT (proxy), "label");
- g_return_if_fail (label != NULL);
+ label_text = g_strdup_printf (_("%s:"), title_short);
+
+ gtk_label_set_label (GTK_LABEL (label), label_text);
+ g_free (label_text);
}
- else if (GTK_IS_MENU_ITEM (proxy))
+ else
{
- label = GTK_BIN (proxy)->child;
+ gtk_label_set_label (GTK_LABEL (label), title_short);
}
- g_return_if_fail (label != NULL);
- gtk_label_set_label (GTK_LABEL (label), g_value_get_string (&value));
+ g_free (title_short);
}
-
- g_value_unset (&value);
}
static void
@@ -671,10 +675,6 @@ connect_proxy (GtkAction *action, GtkWidget *proxy)
(* GTK_ACTION_CLASS (parent_class)->connect_proxy) (action, proxy);
- ephy_bookmark_action_sync_label (action, NULL, proxy);
- g_signal_connect_object (action, "notify::label",
- G_CALLBACK (ephy_bookmark_action_sync_label), proxy, 0);
-
ephy_bookmark_action_sync_icon (action, NULL, proxy);
g_signal_connect_object (action, "notify::icon",
G_CALLBACK (ephy_bookmark_action_sync_icon), proxy, 0);
@@ -685,6 +685,10 @@ connect_proxy (GtkAction *action, GtkWidget *proxy)
if (GTK_IS_TOOL_ITEM (proxy))
{
+ ephy_bookmark_action_sync_label (action, NULL, proxy);
+ g_signal_connect_object (action, "notify::label",
+ G_CALLBACK (ephy_bookmark_action_sync_label), proxy, 0);
+
button = GTK_WIDGET (g_object_get_data (G_OBJECT (proxy), "button"));
g_signal_connect (button, "clicked", G_CALLBACK (activate_cb), action);
g_signal_connect (button, "popup_menu",
@@ -720,15 +724,12 @@ bookmark_changed_cb (EphyNode *node,
{
GValue value = { 0, };
const char *title;
- char *short_title;
title = ephy_node_get_property_string
- (action->priv->node, EPHY_NODE_BMK_PROP_TITLE);
- short_title = ephy_string_shorten (title, MAX_LABEL_LENGTH);
-
+ (node, EPHY_NODE_BMK_PROP_TITLE);
g_value_init (&value, G_TYPE_STRING);
- g_value_take_string (&value, short_title);
- g_object_set (G_OBJECT (action), "label", short_title, NULL);
+ g_value_set_static_string (&value, title);
+ g_object_set_property (G_OBJECT (action), "label", &value);
g_value_unset (&value);
}
else if (property_id == EPHY_NODE_BMK_PROP_ICON)
diff --git a/src/bookmarks/ephy-bookmarks-menu.c b/src/bookmarks/ephy-bookmarks-menu.c
index 2ffcd994d..a681c97f0 100644
--- a/src/bookmarks/ephy-bookmarks-menu.c
+++ b/src/bookmarks/ephy-bookmarks-menu.c
@@ -71,6 +71,7 @@ struct _EphyBookmarksMenuPrivate
#define GAZILLION 200
#define UPDATE_DELAY 5000 /* ms */
+#define LABEL_WIDTH_CHARS 32
enum
{
@@ -112,6 +113,21 @@ ephy_bookmarks_menu_get_type (void)
}
static void
+connect_proxy_cb (GtkActionGroup *action_group,
+ GtkAction *action,
+ GtkWidget *proxy)
+{
+ if (GTK_IS_MENU_ITEM (proxy))
+ {
+ GtkLabel *label;
+
+ label = (GtkLabel *) ((GtkBin *) proxy)->child;
+ gtk_label_set_width_chars (label, LABEL_WIDTH_CHARS);
+ gtk_label_set_ellipsize (label, PANGO_ELLIPSIZE_END);
+ }
+}
+
+static void
remove_action (gpointer idptr,
GtkActionGroup *action_group)
{
@@ -209,6 +225,9 @@ ensure_bookmark_actions (EphyBookmarksMenu *menu)
gtk_ui_manager_insert_action_group (menu->priv->manager,
menu->priv->bmk_actions, -1);
+ g_signal_connect (menu->priv->bmk_actions, "connect-proxy",
+ G_CALLBACK (connect_proxy_cb), NULL);
+
bookmarks = ephy_bookmarks_get_bookmarks (menu->priv->bookmarks);
children = ephy_node_get_children (bookmarks);
for (i = 0; i < children->len; i++)
@@ -428,6 +447,9 @@ ephy_bookmarks_menu_rebuild (EphyBookmarksMenu *menu)
p->folder_actions = gtk_action_group_new ("FolderActions");
gtk_ui_manager_insert_action_group (p->manager, p->folder_actions, -1);
+ g_signal_connect (p->folder_actions, "connect-proxy",
+ G_CALLBACK (connect_proxy_cb), NULL);
+
p->ui_id = gtk_ui_manager_new_merge_id (p->manager);
topics = ephy_bookmarks_get_keywords (p->bookmarks);
diff --git a/src/bookmarks/ephy-favorites-menu.c b/src/bookmarks/ephy-favorites-menu.c
index 5b42cca94..673d7b407 100644
--- a/src/bookmarks/ephy-favorites-menu.c
+++ b/src/bookmarks/ephy-favorites-menu.c
@@ -31,6 +31,8 @@
#include <gtk/gtkuimanager.h>
#include <glib/gprintf.h>
+#define LABEL_WIDTH_CHARS 32
+
#define EPHY_FAVORITES_MENU_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_FAVORITES_MENU, EphyFavoritesMenuPrivate))
struct _EphyFavoritesMenuPrivate
@@ -108,6 +110,21 @@ open_bookmark_cb (GtkAction *action, char *location, EphyWindow *window)
}
static void
+connect_proxy_cb (GtkActionGroup *action_group,
+ GtkAction *action,
+ GtkWidget *proxy)
+{
+ if (GTK_IS_MENU_ITEM (proxy))
+ {
+ GtkLabel *label;
+
+ label = (GtkLabel *) ((GtkBin *) proxy)->child;
+ gtk_label_set_width_chars (label, LABEL_WIDTH_CHARS);
+ gtk_label_set_ellipsize (label, PANGO_ELLIPSIZE_END);
+ }
+}
+
+static void
ephy_favorites_menu_rebuild (EphyFavoritesMenu *menu)
{
EphyFavoritesMenuPrivate *p = menu->priv;
@@ -126,7 +143,10 @@ ephy_favorites_menu_rebuild (EphyFavoritesMenu *menu)
children = ephy_node_get_children (fav);
p->action_group = gtk_action_group_new ("FavoritesActions");
- gtk_ui_manager_insert_action_group (merge, p->action_group, 0);
+ gtk_ui_manager_insert_action_group (merge, p->action_group, -1);
+ g_signal_connect (p->action_group, "connect-proxy",
+ G_CALLBACK (connect_proxy_cb), NULL);
+
p->ui_id = gtk_ui_manager_new_merge_id (merge);
for (i = 0; i < children->len; i++)
diff --git a/src/bookmarks/ephy-topic-action.c b/src/bookmarks/ephy-topic-action.c
index aaac2b38c..629d08b65 100644
--- a/src/bookmarks/ephy-topic-action.c
+++ b/src/bookmarks/ephy-topic-action.c
@@ -42,6 +42,8 @@
static void ephy_topic_action_init (EphyTopicAction *action);
static void ephy_topic_action_class_init (EphyTopicActionClass *class);
+#define LABEL_WIDTH_CHARS 32
+
#define EPHY_TOPIC_ACTION_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_TOPIC_ACTION, EphyTopicActionPrivate))
static GtkTargetEntry drag_targets[] =
@@ -173,40 +175,38 @@ menu_activate_cb (GtkWidget *item, GtkAction *action)
}
}
+#define MAX_LABEL_LENGTH 32
+
static void
-ephy_topic_action_sync_label (GtkAction *action, GParamSpec *pspec, GtkWidget *proxy)
+ephy_topic_action_sync_label (GtkAction *gaction,
+ GParamSpec *pspec,
+ GtkWidget *proxy)
{
- GtkWidget *label = NULL;
- GValue value = { 0, };
- const char *label_text;
-
- g_value_init (&value, G_TYPE_STRING);
- g_object_get_property (G_OBJECT (action), "label", &value);
+ EphyTopicAction *action = EPHY_TOPIC_ACTION (gaction);
- label_text = g_value_get_string (&value);
+ g_return_if_fail (EPHY_IS_NODE (action->priv->topic_node));
+ /* note that we cannot use ellipsizing label with defined width,
+ * since that makes the label exactly that wide, even if the
+ * text takes less space. So we have to shorten the string.
+ */
if (GTK_IS_TOOL_ITEM (proxy))
{
- label = GTK_WIDGET (g_object_get_data (G_OBJECT (proxy), "label"));
- }
- else if (GTK_IS_MENU_ITEM (proxy))
- {
- label = GTK_BIN (proxy)->child;
- }
- else
- {
- g_warning ("Unknown widget");
- return;
- }
+ GtkWidget *label = NULL;
+ const char *title;
+ char *title_short;
- g_return_if_fail (label != NULL);
+ label = g_object_get_data (G_OBJECT (proxy), "label");
+ g_return_if_fail (label != NULL);
- if (label_text)
- {
- gtk_label_set_label (GTK_LABEL (label), label_text);
- }
+ title = ephy_node_get_property_string
+ (action->priv->topic_node, EPHY_NODE_KEYWORD_PROP_NAME);
+ title_short = ephy_string_shorten (title, MAX_LABEL_LENGTH);
- g_value_unset (&value);
+ gtk_label_set_label (GTK_LABEL (label), title_short);
+
+ g_free (title_short);
+ }
}
static int
@@ -259,6 +259,7 @@ append_bookmarks_menu (EphyTopicAction *action, GtkWidget *menu, EphyNode *node,
{
EphyFaviconCache *cache;
GtkWidget *item;
+ GtkLabel *label;
GPtrArray *children;
cache = EPHY_FAVICON_CACHE
@@ -294,7 +295,6 @@ append_bookmarks_menu (EphyTopicAction *action, GtkWidget *menu, EphyNode *node,
EphyNode *kid;
const char *icon_location;
const char *title;
- char *title_short;
kid = (EphyNode*)l->data;
@@ -303,10 +303,12 @@ append_bookmarks_menu (EphyTopicAction *action, GtkWidget *menu, EphyNode *node,
title = ephy_node_get_property_string
(kid, EPHY_NODE_BMK_PROP_TITLE);
if (title == NULL) continue;
- title_short = ephy_string_shorten (title, MAX_LENGTH);
- LOG ("Create menu for bookmark %s", title_short)
- item = gtk_image_menu_item_new_with_label (title_short);
+ item = gtk_image_menu_item_new_with_label (title);
+ label = (GtkLabel *) ((GtkBin *) item)->child;
+ gtk_label_set_width_chars (label, LABEL_WIDTH_CHARS);
+ gtk_label_set_ellipsize (label, PANGO_ELLIPSIZE_END);
+
if (icon_location)
{
GdkPixbuf *icon;
@@ -328,8 +330,6 @@ append_bookmarks_menu (EphyTopicAction *action, GtkWidget *menu, EphyNode *node,
G_CALLBACK (menu_activate_cb), action);
gtk_widget_show (item);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
-
- g_free (title_short);
}
g_list_free (node_list);
@@ -545,15 +545,18 @@ build_topics_menu (EphyTopicAction *action)
EphyNode *kid;
const char *title;
GtkWidget *bmk_menu;
+ GtkLabel *label;
kid = (EphyNode*)l->data;
if (kid == all) continue;
title = ephy_node_get_property_string
(kid, EPHY_NODE_KEYWORD_PROP_NAME);
- LOG ("Create menu for topic %s", title);
item = gtk_image_menu_item_new_with_label (title);
+ label = (GtkLabel *) ((GtkBin *) item)->child;
+ gtk_label_set_width_chars (label, LABEL_WIDTH_CHARS);
+ gtk_label_set_ellipsize (label, PANGO_ELLIPSIZE_END);
gtk_widget_show (item);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
@@ -835,12 +838,12 @@ connect_proxy (GtkAction *action, GtkWidget *proxy)
(* GTK_ACTION_CLASS (parent_class)->connect_proxy) (action, proxy);
- ephy_topic_action_sync_label (action, NULL, proxy);
- g_signal_connect_object (action, "notify::label",
- G_CALLBACK (ephy_topic_action_sync_label), proxy, 0);
-
if (GTK_IS_TOOL_ITEM (proxy))
{
+ ephy_topic_action_sync_label (action, NULL, proxy);
+ g_signal_connect_object (action, "notify::label",
+ G_CALLBACK (ephy_topic_action_sync_label), proxy, 0);
+
button = GTK_WIDGET (g_object_get_data (G_OBJECT (proxy), "button"));
g_signal_connect (button, "toggled",
G_CALLBACK (button_toggled_cb), action);
@@ -883,7 +886,7 @@ topic_changed_cb (EphyNode *node,
}
g_value_init(&value, G_TYPE_STRING);
- g_value_set_string (&value, title);
+ g_value_set_static_string (&value, title);
g_object_set_property (G_OBJECT (action), "label", &value);
g_value_unset (&value);
}