aboutsummaryrefslogtreecommitdiff
path: root/libdbusmenu-gtk
diff options
context:
space:
mode:
authorMichael Terry <mike@mterry.name>2011-03-09 15:02:07 -0500
committerMichael Terry <mike@mterry.name>2011-03-09 15:02:07 -0500
commit49ce3e92dd5e30a514813a9e9e8e38087a5e73bd (patch)
tree25627bd8a7a7675d9cbbed980bf26a6cb312923a /libdbusmenu-gtk
parent16bc55aa8a22ed835707685c02e7b4f480a819da (diff)
downloadlibdbusmenu-49ce3e92dd5e30a514813a9e9e8e38087a5e73bd.tar.gz
libdbusmenu-49ce3e92dd5e30a514813a9e9e8e38087a5e73bd.tar.bz2
libdbusmenu-49ce3e92dd5e30a514813a9e9e8e38087a5e73bd.zip
respect use-underline and use-markup of labels in menu items
Diffstat (limited to 'libdbusmenu-gtk')
-rw-r--r--libdbusmenu-gtk/parser.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c
index 8954d64..a890543 100644
--- a/libdbusmenu-gtk/parser.c
+++ b/libdbusmenu-gtk/parser.c
@@ -362,6 +362,32 @@ sanitize_label_text (const gchar * label)
}
}
+static gchar *
+sanitize_label (GtkLabel * label)
+{
+ gchar * text;
+
+ if (gtk_label_get_use_markup (label)) {
+ text = sanitize_label_text (gtk_label_get_label (label));
+ }
+ else {
+ text = g_strdup (gtk_label_get_label (label));
+ }
+
+ if (!gtk_label_get_use_underline (label)) {
+ /* Insert extra underscores */
+ GRegex * regex = g_regex_new ("_", 0, 0, NULL);
+ gchar * escaped = g_regex_replace_literal (regex, text, -1, 0, "__", 0, NULL);
+
+ g_regex_unref (regex);
+ g_free (text);
+
+ text = escaped;
+ }
+
+ return text;
+}
+
/* Turn a widget into a dbusmenu item depending on the type of GTK
object that it is. */
static DbusmenuMenuitem *
@@ -445,7 +471,7 @@ construct_dbusmenu_for_widget (GtkWidget * widget)
{
// Sometimes, an app will directly find and modify the label
// (like empathy), so watch the label especially for that.
- gchar * text = sanitize_label_text (gtk_label_get_label (GTK_LABEL (label)));
+ gchar * text = sanitize_label (GTK_LABEL (label));
dbusmenu_menuitem_property_set (mi, "label", text);
g_free (text);
@@ -690,7 +716,7 @@ label_notify_cb (GtkWidget *widget,
if (pspec->name == g_intern_static_string ("label"))
{
- gchar * text = sanitize_label_text (gtk_label_get_label (GTK_LABEL (widget)));
+ gchar * text = sanitize_label (GTK_LABEL (widget));
dbusmenu_menuitem_property_set (child,
DBUSMENU_MENUITEM_PROP_LABEL,
text);