Bug #323956: Unwanted accelerate key in the action-based toolbar.



I've submited this bug in the bugzilla, and I tried to fix it in the
_gtk_toolbar_elide_underscores (...), even I force

gtk_tool_button_construct_contents (...) in the gtk/gtktoolbutton.c to elide the label widget, I was failed.:-(

Any comments?

my patch on the _gtk_toolbar_elide_underscores,

--- gtk+.orig/gtk/gtktoolbar.c  2005-12-13 13:17:48.000000000 +0800
+++ gtk+/gtk/gtktoolbar.c       2005-12-14 10:33:53.000000000 +0800
@@ -4786,17 +4786,29 @@
   gchar *q, *result;
   const gchar *p;
   gboolean last_underscore;
+  gint original_len;

   if (!original)
     return NULL;

-  q = result = g_malloc (strlen (original) + 1);
+  original_len = strlen (original);
+  q = result = g_malloc (original_len + 1);
   last_underscore = FALSE;

   for (p = original; *p; p++)
     {
       if (!last_underscore && *p == '_')
-       last_underscore = TRUE;
+       {
+         if (((p - original) >= 1 && *(p - 1) == '(')
+               && ((p - original + 3) <= original_len && *(p + 2) == ')'))
+           {
+               p += 2;
+               q --;
+               continue;
+           }
+         else
+           last_underscore = TRUE;
+       }
       else
        {
          last_underscore = FALSE;

I've wroten some test cases:

#include <stdio.h>
#include <string.h>
#include <glib.h>

gchar *_gtk_toolbar_elide_underscores(const gchar * original)
{
    gchar *q, *result;
    const gchar *p;
    gboolean last_underscore;
    gint original_len;

    if (!original)
        return NULL;

    original_len = strlen(original);
    q = result = g_malloc(original_len + 1);
    last_underscore = FALSE;

    for (p = original; *p; p++) {
        if (!last_underscore && *p == '_') {
            if (((p - original) >= 1 && *(p - 1) == '(')
                && ((p - original + 3) <= original_len && *(p + 2) == ')')) {
                p += 2;
                q --;
                continue;
            } else
                last_underscore = TRUE;
        } else {
            last_underscore = FALSE;
            *q++ = *p;
        }
    }

    *q = '\0';

    return result;
}


int main(int argc, char **argv)
{
    const gchar *tests[] = {"_Forward", "前进(_F)",
                            "For__ward", "For___ward",
                            "前进(_)", "前进__F)",
                            "前进(N)", "前进__NF)",
                            "前进(__F)", "前进(___F)"};

    gchar *res = NULL;
    int i;

    for (i = 0; i < G_N_ELEMENTS(tests); i ++)
    {
        res = _gtk_toolbar_elide_underscores(tests[i]);
        printf("test %d: %s, elided: %s\n", i, tests[i], res);
        g_free(res);
    }

    return 0;
}

result:

test 0: _Forward, elided: Forward
test 1: 前进(_F), elided: 前进
test 2: For__ward, elided: For_ward
test 3: For___ward, elided: For_ward
test 4: 前进(_), elided: 前进()
test 5: 前进__F), elided: 前进_F)
test 6: 前进(N), elided: 前进(N)
test 7: 前进__NF), elided: 前进_NF)
test 8: 前进(__F), elided: 前进(_F)
test 9: 前进(___F), elided: 前进(_F)


begin:vcard
fn:Yang Hong
n:Hong;Yang
org;quoted-printable:=E5=85=B1=E5=88=9B=E5=BC=80=E6=BA=90
adr;quoted-printable;dom:;;=E5=8C=97=E4=BA=AC
email;internet:yanghong ccoss com cn
title;quoted-printable:Linux =E7=A0=94=E5=8F=91
tel;work:010-82357030-275
x-mozilla-html:TRUE
url:http://www.co-create.com.cn
version:2.1
end:vcard



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]