4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
11 Problem: When menus are translated they can only be found by the translated
12 name. That makes ":emenu" difficult to use.
13 Solution: Store the untranslated name and use it for completion and :emenu.
14 (Edward L. Fox / Liang Peng / Bezetek James)
15 Files: src/menu.c, src/structs.h
18 *** ../vim-7.2.431/src/menu.c 2010-05-14 21:19:16.000000000 +0200
19 --- src/menu.c 2010-05-14 21:52:58.000000000 +0200
23 static char_u *menutrans_lookup __ARGS((char_u *name, int len));
26 + static char_u *menu_translate_tab_and_shift __ARGS((char_u *arg_start));
27 + static void menu_unescape_name __ARGS((char_u *p));
29 /* The character for each menu mode */
30 static char_u menu_mode_chars[] = {'n', 'v', 's', 'o', 'i', 'c', 't'};
34 int pri_tab[MENUDEPTH + 1];
35 int enable = MAYBE; /* TRUE for "menu enable", FALSE for "menu
37 - #ifdef FEAT_MULTI_LANG
38 - char_u *tofree = NULL;
50 - #ifdef FEAT_MULTI_LANG
52 - * Translate menu names as specified with ":menutrans" commands.
57 - /* find the end of one part and check if it should be translated */
58 - p = menu_skip_part(menu_path);
59 - map_to = menutrans_lookup(menu_path, (int)(p - menu_path));
62 - /* found a match: replace with the translated part */
63 - i = (int)STRLEN(map_to);
64 - new_cmd = alloc((unsigned)STRLEN(arg) + i + 1);
65 - if (new_cmd == NULL)
67 - mch_memmove(new_cmd, arg, menu_path - arg);
68 - mch_memmove(new_cmd + (menu_path - arg), map_to, (size_t)i);
69 - STRCPY(new_cmd + (menu_path - arg) + i, p);
70 - p = new_cmd + (menu_path - arg) + i;
82 - * Isolate the menu name.
83 - * Skip the menu name, and translate <Tab> into a real TAB.
86 if (*menu_path == '.')
94 ! while (*arg && !vim_iswhite(*arg))
96 ! if ((*arg == '\\' || *arg == Ctrl_V) && arg[1] != NUL)
98 ! else if (STRNICMP(arg, "<TAB>", 5) == 0)
101 ! STRMOVE(arg + 1, arg + 5);
107 ! arg = skipwhite(arg);
111 * If there is only a menu name, display menus with that name.
116 ! map_to = menu_translate_tab_and_shift(arg);
119 * If there is only a menu name, display menus with that name.
125 - #ifdef FEAT_MULTI_LANG
140 + #ifdef FEAT_MULTI_LANG
142 + char_u *map_to = NULL;
145 /* Make a copy so we can stuff around with it, since it could be const */
146 path_name = vim_strsave(menu_path);
150 /* Get name of this element in the menu hierarchy, and the simplified
151 * name (without mnemonic and accelerator text). */
152 next_name = menu_name_skip(name);
153 + #ifdef FEAT_MULTI_LANG
154 + map_to = menutrans_lookup(name,STRLEN(name));
155 + if (map_to != NULL)
163 dname = menu_text(name, NULL, NULL);
169 menu->name = vim_strsave(name);
170 /* separate mnemonic and accelerator text from actual menu name */
171 menu->dname = menu_text(name, &menu->mnemonic, &menu->actext);
172 + #ifdef FEAT_MULTI_LANG
173 + if (en_name != NULL)
175 + menu->en_name = vim_strsave(en_name);
176 + menu->en_dname = menu_text(en_name, NULL, NULL);
180 + menu->en_name = NULL;
181 + menu->en_dname = NULL;
184 menu->priority = pri_tab[pri_idx];
185 menu->parent = parent;
186 #ifdef FEAT_GUI_MOTIF
191 vim_free(menu->name);
192 vim_free(menu->dname);
193 + #ifdef FEAT_MULTI_LANG
194 + vim_free(menu->en_name);
195 + vim_free(menu->en_dname);
197 vim_free(menu->actext);
199 vim_free(menu->iconfile);
204 static vimmenu_T *menu = NULL;
206 + #ifdef FEAT_MULTI_LANG
207 + static int should_advance = FALSE;
210 if (idx == 0) /* first call: start at first item */
213 + should_advance = FALSE;
216 /* Skip PopUp[nvoci]. */
217 while (menu != NULL && (menu_is_hidden(menu->dname)
222 if (menu->modes & expand_modes)
227 ! /* Advance to next menu entry. */
235 if (menu->modes & expand_modes)
236 ! #ifdef FEAT_MULTI_LANG
237 ! if (should_advance)
238 ! str = menu->en_dname;
243 ! #ifdef FEAT_MULTI_LANG
244 ! if (menu->en_dname == NULL)
245 ! should_advance = TRUE;
251 ! #ifdef FEAT_MULTI_LANG
252 ! if (should_advance)
254 ! /* Advance to next menu entry. */
257 ! #ifdef FEAT_MULTI_LANG
258 ! should_advance = !should_advance;
266 static vimmenu_T *menu = NULL;
267 static char_u tbuffer[256]; /*hack*/
269 + #ifdef FEAT_MULTI_LANG
270 + static int should_advance = FALSE;
273 if (idx == 0) /* first call: start at first item */
276 + should_advance = FALSE;
279 /* Skip Browse-style entries, popup menus and separators. */
284 if (menu->children != NULL)
286 ! STRCPY(tbuffer, menu->dname);
287 /* hack on menu separators: use a 'magic' char for the separator
288 * so that '.' in names gets escaped properly */
289 STRCAT(tbuffer, "\001");
298 ! /* Advance to next menu entry. */
305 if (menu->children != NULL)
307 ! #ifdef FEAT_MULTI_LANG
308 ! if (should_advance)
309 ! STRCPY(tbuffer, menu->en_dname);
313 ! STRCPY(tbuffer, menu->dname);
314 ! #ifdef FEAT_MULTI_LANG
315 ! if (menu->en_dname == NULL)
316 ! should_advance = TRUE;
319 /* hack on menu separators: use a 'magic' char for the separator
320 * so that '.' in names gets escaped properly */
321 STRCAT(tbuffer, "\001");
325 ! #ifdef FEAT_MULTI_LANG
327 ! if (should_advance)
328 ! str = menu->en_dname;
333 ! #ifdef FEAT_MULTI_LANG
334 ! if (menu->en_dname == NULL)
335 ! should_advance = TRUE;
343 ! #ifdef FEAT_MULTI_LANG
344 ! if (should_advance)
346 ! /* Advance to next menu entry. */
349 ! #ifdef FEAT_MULTI_LANG
350 ! should_advance = !should_advance;
360 ! return (menu_namecmp(name, menu->name) || menu_namecmp(name, menu->dname));
368 ! if (menu->en_name != NULL
369 ! && (menu_namecmp(name,menu->en_name)
370 ! || menu_namecmp(name,menu->en_dname)))
372 ! return menu_namecmp(name, menu->name) || menu_namecmp(name, menu->dname);
379 to = vim_strnsave(to, (int)(arg - to));
380 if (from_noamp != NULL && to != NULL)
382 + menu_translate_tab_and_shift(from);
383 + menu_translate_tab_and_shift(to);
384 + menu_unescape_name(from);
385 + menu_unescape_name(to);
386 tp[menutrans_ga.ga_len].from = from;
387 tp[menutrans_ga.ga_len].from_noamp = from_noamp;
388 tp[menutrans_ga.ga_len].to = to;
393 #endif /* FEAT_MULTI_LANG */
396 + * Unescape the name in the translate dictionary table.
399 + menu_unescape_name(name)
404 + for (p = name; *p && *p != '.'; mb_ptr_adv(p))
410 + * Isolate the menu name.
411 + * Skip the menu name, and translate <Tab> into a real TAB.
414 + menu_translate_tab_and_shift(arg_start)
417 + char_u *arg = arg_start;
419 + while (*arg && !vim_iswhite(*arg))
421 + if ((*arg == '\\' || *arg == Ctrl_V) && arg[1] != NUL)
423 + else if (STRNICMP(arg, "<TAB>", 5) == 0)
426 + STRMOVE(arg + 1, arg + 5);
432 + arg = skipwhite(arg);
437 #endif /* FEAT_MENU */
438 *** ../vim-7.2.431/src/structs.h 2009-09-18 17:24:54.000000000 +0200
439 --- src/structs.h 2010-05-14 22:21:50.000000000 +0200
443 wininfo_T *wi_next; /* next entry or NULL for last entry */
444 wininfo_T *wi_prev; /* previous entry or NULL for first entry */
445 ! win_T *wi_win; /* pointer to window that did set wi_lnum */
446 pos_T wi_fpos; /* last cursor position in the file */
447 int wi_optset; /* TRUE when wi_opt has useful values */
448 winopt_T wi_opt; /* local window options */
451 wininfo_T *wi_next; /* next entry or NULL for last entry */
452 wininfo_T *wi_prev; /* previous entry or NULL for first entry */
453 ! win_T *wi_win; /* pointer to window that did set wi_fpos */
454 pos_T wi_fpos; /* last cursor position in the file */
455 int wi_optset; /* TRUE when wi_opt has useful values */
456 winopt_T wi_opt; /* local window options */
460 int modes; /* Which modes is this menu visible for? */
461 int enabled; /* for which modes the menu is enabled */
462 ! char_u *name; /* Name of menu */
463 ! char_u *dname; /* Displayed Name (without '&') */
464 int mnemonic; /* mnemonic key (after '&') */
465 char_u *actext; /* accelerator text (after TAB) */
466 int priority; /* Menu order priority */
469 int modes; /* Which modes is this menu visible for? */
470 int enabled; /* for which modes the menu is enabled */
471 ! char_u *name; /* Name of menu, possibly translated */
472 ! char_u *dname; /* Displayed Name ("name" without '&') */
473 ! #ifdef FEAT_MULTI_LANG
474 ! char_u *en_name; /* "name" untranslated, NULL when "name"
475 ! * was not translated */
476 ! char_u *en_dname; /* "dname" untranslated, NULL when "dname"
477 ! * was not translated */
479 int mnemonic; /* mnemonic key (after '&') */
480 char_u *actext; /* accelerator text (after TAB) */
481 int priority; /* Menu order priority */
482 *** ../vim-7.2.431/src/version.c 2010-05-14 21:19:16.000000000 +0200
483 --- src/version.c 2010-05-14 22:19:39.000000000 +0200
487 { /* Add new patch number below this line */
493 It is hard to understand how a cemetery raised its burial
494 cost and blamed it on the cost of living.
496 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
497 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
498 \\\ download, build and distribute -- http://www.A-A-P.org ///
499 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///