diff -Nru unity-gtk-module-0.0.0+14.04.20140311/debian/changelog unity-gtk-module-0.0.0+14.04.20140319/debian/changelog --- unity-gtk-module-0.0.0+14.04.20140311/debian/changelog 2014-03-19 09:08:12.000000000 +0000 +++ unity-gtk-module-0.0.0+14.04.20140319/debian/changelog 2014-03-19 09:08:12.000000000 +0000 @@ -1,3 +1,10 @@ +unity-gtk-module (0.0.0+14.04.20140319-0ubuntu1) trusty; urgency=low + + [ William Hua ] + * Watch use-underline property on GtkMenuItems. (LP: #1260777) + + -- Ubuntu daily release Wed, 19 Mar 2014 09:04:02 +0000 + unity-gtk-module (0.0.0+14.04.20140311-0ubuntu1) trusty; urgency=low [ CI bot ] diff -Nru unity-gtk-module-0.0.0+14.04.20140311/lib/unity-gtk-menu-item.c unity-gtk-module-0.0.0+14.04.20140319/lib/unity-gtk-menu-item.c --- unity-gtk-module-0.0.0+14.04.20140311/lib/unity-gtk-menu-item.c 2014-03-11 12:37:57.000000000 +0000 +++ unity-gtk-module-0.0.0+14.04.20140319/lib/unity-gtk-menu-item.c 2014-03-19 09:03:53.000000000 +0000 @@ -525,6 +525,41 @@ return NULL; } +static gchar * +g_strdup_escape_underscores (const gchar *str) +{ + if (str != NULL) + { + gchar *string; + gchar *out; + const gchar *in; + guint underscores; + + underscores = 0; + + for (in = strchr (str, '_'); in != NULL; in = strchr (in + 1, '_')) + underscores++; + + if (underscores == 0) + return g_strdup (str); + + string = g_malloc (strlen (str) + underscores + 1); + out = string; + + for (in = str; *in != '\0'; in++) + { + *out++ = *in; + + if (*in == '_') + *out++ = '_'; + } + + return string; + } + + return NULL; +} + const gchar * unity_gtk_menu_item_get_label (UnityGtkMenuItem *item) { @@ -556,10 +591,15 @@ if (label != NULL && label[0] != '\0') { - if (item->parent_shell == NULL || item->parent_shell->has_mnemonics) - item->label = g_strdup (label); + if (gtk_menu_item_get_use_underline (item->menu_item)) + { + if (item->parent_shell == NULL || item->parent_shell->has_mnemonics) + item->label = g_strdup (label); + else + item->label = g_strdup_no_mnemonics (label); + } else - item->label = g_strdup_no_mnemonics (label); + item->label = g_strdup_escape_underscores (label); } } diff -Nru unity-gtk-module-0.0.0+14.04.20140311/lib/unity-gtk-menu-shell.c unity-gtk-module-0.0.0+14.04.20140319/lib/unity-gtk-menu-shell.c --- unity-gtk-module-0.0.0+14.04.20140311/lib/unity-gtk-menu-shell.c 2014-03-11 12:37:57.000000000 +0000 +++ unity-gtk-module-0.0.0+14.04.20140319/lib/unity-gtk-menu-shell.c 2014-03-19 09:03:53.000000000 +0000 @@ -456,6 +456,13 @@ } static void +unity_gtk_menu_shell_handle_item_use_underline (UnityGtkMenuShell *shell, + UnityGtkMenuItem *item) +{ + unity_gtk_menu_shell_handle_item_label (shell, item); +} + +static void unity_gtk_menu_shell_handle_item_accel_path (UnityGtkMenuShell *shell, UnityGtkMenuItem *item) { @@ -979,6 +986,7 @@ static const gchar *visible_name; static const gchar *sensitive_name; static const gchar *label_name; + static const gchar *use_underline_name; static const gchar *accel_path_name; static const gchar *active_name; static const gchar *parent_name; @@ -995,6 +1003,8 @@ sensitive_name = g_intern_static_string ("sensitive"); if (label_name == NULL) label_name = g_intern_static_string ("label"); + if (use_underline_name == NULL) + use_underline_name = g_intern_static_string ("use-underline"); if (accel_path_name == NULL) accel_path_name = g_intern_static_string ("accel-path"); if (active_name == NULL) @@ -1015,6 +1025,8 @@ unity_gtk_menu_shell_handle_item_sensitive (shell, item); else if (name == label_name) unity_gtk_menu_shell_handle_item_label (shell, item); + else if (name == use_underline_name) + unity_gtk_menu_shell_handle_item_use_underline (shell, item); else if (name == accel_path_name) unity_gtk_menu_shell_handle_item_accel_path (shell, item); else if (name == active_name)