Ellipsize bookmarkbar items reasonably
This commit is contained in:
parent
973b149c5e
commit
27d5b35f1d
1 changed files with 48 additions and 1 deletions
|
@ -14,8 +14,9 @@
|
||||||
#include "katze-net.h"
|
#include "katze-net.h"
|
||||||
#include "katze-utils.h"
|
#include "katze-utils.h"
|
||||||
|
|
||||||
#include <gtk/gtk.h>
|
#include <string.h>
|
||||||
#include <glib/gi18n.h>
|
#include <glib/gi18n.h>
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
struct _KatzeArrayAction
|
struct _KatzeArrayAction
|
||||||
{
|
{
|
||||||
|
@ -356,6 +357,25 @@ katze_array_action_create_tool_item (GtkAction* action)
|
||||||
return toolitem;
|
return toolitem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
katze_array_action_label_notify_cb (GtkToolButton* item,
|
||||||
|
GParamSpec* pspec,
|
||||||
|
GtkLabel* label)
|
||||||
|
{
|
||||||
|
const gchar* property;
|
||||||
|
const gchar* text;
|
||||||
|
|
||||||
|
if (!G_IS_PARAM_SPEC_STRING (pspec))
|
||||||
|
return;
|
||||||
|
|
||||||
|
property = g_param_spec_get_name (pspec);
|
||||||
|
if (!strcmp (property, "label"))
|
||||||
|
{
|
||||||
|
text = gtk_tool_button_get_label (item);
|
||||||
|
gtk_label_set_text (label, text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
katze_array_action_item_notify_cb (KatzeItem* item,
|
katze_array_action_item_notify_cb (KatzeItem* item,
|
||||||
GParamSpec* pspec,
|
GParamSpec* pspec,
|
||||||
|
@ -404,6 +424,21 @@ katze_array_action_item_notify_cb (KatzeItem* item,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* katze_array_action_create_tool_item_for:
|
||||||
|
* @array_action: a #KatzeArrayAction
|
||||||
|
* @item: a #KatzeItem
|
||||||
|
*
|
||||||
|
* Creates a tool item for a particular @item, that also
|
||||||
|
* reflects changes to its properties. In the case of
|
||||||
|
* an array, the item will create a popup menu with
|
||||||
|
* the contained items.
|
||||||
|
*
|
||||||
|
* Note that the label is reasonably ellipsized for you,
|
||||||
|
* much like katze_image_menu_item_new_ellipsized().
|
||||||
|
*
|
||||||
|
* Return value: a new tool item
|
||||||
|
**/
|
||||||
GtkToolItem*
|
GtkToolItem*
|
||||||
katze_array_action_create_tool_item_for (KatzeArrayAction* array_action,
|
katze_array_action_create_tool_item_for (KatzeArrayAction* array_action,
|
||||||
KatzeItem* item)
|
KatzeItem* item)
|
||||||
|
@ -414,6 +449,7 @@ katze_array_action_create_tool_item_for (KatzeArrayAction* array_action,
|
||||||
GtkToolItem* toolitem;
|
GtkToolItem* toolitem;
|
||||||
GdkPixbuf* icon;
|
GdkPixbuf* icon;
|
||||||
GtkWidget* image;
|
GtkWidget* image;
|
||||||
|
GtkWidget* label;
|
||||||
|
|
||||||
title = katze_item_get_name (item);
|
title = katze_item_get_name (item);
|
||||||
uri = katze_item_get_uri (item);
|
uri = katze_item_get_uri (item);
|
||||||
|
@ -434,6 +470,17 @@ katze_array_action_create_tool_item_for (KatzeArrayAction* array_action,
|
||||||
g_object_unref (icon);
|
g_object_unref (icon);
|
||||||
gtk_widget_show (image);
|
gtk_widget_show (image);
|
||||||
gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (toolitem), image);
|
gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (toolitem), image);
|
||||||
|
label = gtk_label_new (NULL);
|
||||||
|
/* FIXME: Should text direction be respected here? */
|
||||||
|
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
|
||||||
|
gtk_label_set_max_width_chars (GTK_LABEL (label), 25);
|
||||||
|
gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_MIDDLE);
|
||||||
|
gtk_widget_show (label);
|
||||||
|
gtk_tool_button_set_label_widget (GTK_TOOL_BUTTON (toolitem), label);
|
||||||
|
/* GtkToolItem won't update our custom label, so we
|
||||||
|
apply a little bit of 'magic' to fix that. */
|
||||||
|
g_signal_connect (toolitem, "notify",
|
||||||
|
G_CALLBACK (katze_array_action_label_notify_cb), label);
|
||||||
if (title)
|
if (title)
|
||||||
gtk_tool_button_set_label (GTK_TOOL_BUTTON (toolitem), title);
|
gtk_tool_button_set_label (GTK_TOOL_BUTTON (toolitem), title);
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue