]>
Commit | Line | Data |
---|---|---|
e7d66cb1 AM |
1 | To: vim-dev@vim.org |
2 | Subject: Patch 7.2.432 | |
3 | Fcc: outbox | |
4 | From: Bram Moolenaar <Bram@moolenaar.net> | |
5 | Mime-Version: 1.0 | |
6 | Content-Type: text/plain; charset=UTF-8 | |
7 | Content-Transfer-Encoding: 8bit | |
8 | ------------ | |
9 | ||
10 | Patch 7.2.432 | |
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 | |
16 | ||
17 | ||
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 | |
20 | *************** | |
21 | *** 58,63 **** | |
22 | --- 58,66 ---- | |
23 | static char_u *menutrans_lookup __ARGS((char_u *name, int len)); | |
24 | #endif | |
25 | ||
26 | + static char_u *menu_translate_tab_and_shift __ARGS((char_u *arg_start)); | |
27 | + static void menu_unescape_name __ARGS((char_u *p)); | |
28 | + | |
29 | /* The character for each menu mode */ | |
30 | static char_u menu_mode_chars[] = {'n', 'v', 's', 'o', 'i', 'c', 't'}; | |
31 | ||
32 | *************** | |
33 | *** 106,115 **** | |
34 | int pri_tab[MENUDEPTH + 1]; | |
35 | int enable = MAYBE; /* TRUE for "menu enable", FALSE for "menu | |
36 | * disable */ | |
37 | - #ifdef FEAT_MULTI_LANG | |
38 | - char_u *tofree = NULL; | |
39 | - char_u *new_cmd; | |
40 | - #endif | |
41 | #ifdef FEAT_TOOLBAR | |
42 | char_u *icon = NULL; | |
43 | #endif | |
44 | --- 109,114 ---- | |
45 | *************** | |
46 | *** 251,291 **** | |
47 | } | |
48 | #endif | |
49 | ||
50 | - #ifdef FEAT_MULTI_LANG | |
51 | - /* | |
52 | - * Translate menu names as specified with ":menutrans" commands. | |
53 | - */ | |
54 | - menu_path = arg; | |
55 | - while (*menu_path) | |
56 | - { | |
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)); | |
60 | - if (map_to != NULL) | |
61 | - { | |
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) | |
66 | - break; | |
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; | |
71 | - vim_free(tofree); | |
72 | - tofree = new_cmd; | |
73 | - arg = new_cmd; | |
74 | - } | |
75 | - if (*p != '.') | |
76 | - break; | |
77 | - menu_path = p + 1; | |
78 | - } | |
79 | - #endif | |
80 | - | |
81 | - /* | |
82 | - * Isolate the menu name. | |
83 | - * Skip the menu name, and translate <Tab> into a real TAB. | |
84 | - */ | |
85 | menu_path = arg; | |
86 | if (*menu_path == '.') | |
87 | { | |
88 | --- 250,255 ---- | |
89 | *************** | |
90 | *** 293,313 **** | |
91 | goto theend; | |
92 | } | |
93 | ||
94 | ! while (*arg && !vim_iswhite(*arg)) | |
95 | ! { | |
96 | ! if ((*arg == '\\' || *arg == Ctrl_V) && arg[1] != NUL) | |
97 | ! arg++; | |
98 | ! else if (STRNICMP(arg, "<TAB>", 5) == 0) | |
99 | ! { | |
100 | ! *arg = TAB; | |
101 | ! STRMOVE(arg + 1, arg + 5); | |
102 | ! } | |
103 | ! arg++; | |
104 | ! } | |
105 | ! if (*arg != NUL) | |
106 | ! *arg++ = NUL; | |
107 | ! arg = skipwhite(arg); | |
108 | ! map_to = arg; | |
109 | ||
110 | /* | |
111 | * If there is only a menu name, display menus with that name. | |
112 | --- 257,263 ---- | |
113 | goto theend; | |
114 | } | |
115 | ||
116 | ! map_to = menu_translate_tab_and_shift(arg); | |
117 | ||
118 | /* | |
119 | * If there is only a menu name, display menus with that name. | |
120 | *************** | |
121 | *** 453,463 **** | |
122 | #endif | |
123 | ||
124 | theend: | |
125 | - #ifdef FEAT_MULTI_LANG | |
126 | - vim_free(tofree); | |
127 | - #else | |
128 | ; | |
129 | - #endif | |
130 | } | |
131 | ||
132 | /* | |
133 | --- 403,409 ---- | |
134 | *************** | |
135 | *** 498,503 **** | |
136 | --- 444,453 ---- | |
137 | int pri_idx = 0; | |
138 | int old_modes = 0; | |
139 | int amenu; | |
140 | + #ifdef FEAT_MULTI_LANG | |
141 | + char_u *en_name; | |
142 | + char_u *map_to = NULL; | |
143 | + #endif | |
144 | ||
145 | /* Make a copy so we can stuff around with it, since it could be const */ | |
146 | path_name = vim_strsave(menu_path); | |
147 | *************** | |
148 | *** 511,516 **** | |
149 | --- 461,476 ---- | |
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) | |
156 | + { | |
157 | + en_name = name; | |
158 | + name = map_to; | |
159 | + } | |
160 | + else | |
161 | + en_name = NULL; | |
162 | + #endif | |
163 | dname = menu_text(name, NULL, NULL); | |
164 | if (dname == NULL) | |
165 | goto erret; | |
166 | *************** | |
167 | *** 594,599 **** | |
168 | --- 554,571 ---- | |
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) | |
174 | + { | |
175 | + menu->en_name = vim_strsave(en_name); | |
176 | + menu->en_dname = menu_text(en_name, NULL, NULL); | |
177 | + } | |
178 | + else | |
179 | + { | |
180 | + menu->en_name = NULL; | |
181 | + menu->en_dname = NULL; | |
182 | + } | |
183 | + #endif | |
184 | menu->priority = pri_tab[pri_idx]; | |
185 | menu->parent = parent; | |
186 | #ifdef FEAT_GUI_MOTIF | |
187 | *************** | |
188 | *** 1040,1045 **** | |
189 | --- 1012,1021 ---- | |
190 | *menup = menu->next; | |
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); | |
196 | + #endif | |
197 | vim_free(menu->actext); | |
198 | #ifdef FEAT_TOOLBAR | |
199 | vim_free(menu->iconfile); | |
200 | *************** | |
201 | *** 1357,1365 **** | |
202 | --- 1333,1347 ---- | |
203 | { | |
204 | static vimmenu_T *menu = NULL; | |
205 | char_u *str; | |
206 | + #ifdef FEAT_MULTI_LANG | |
207 | + static int should_advance = FALSE; | |
208 | + #endif | |
209 | ||
210 | if (idx == 0) /* first call: start at first item */ | |
211 | + { | |
212 | menu = expand_menu; | |
213 | + should_advance = FALSE; | |
214 | + } | |
215 | ||
216 | /* Skip PopUp[nvoci]. */ | |
217 | while (menu != NULL && (menu_is_hidden(menu->dname) | |
218 | *************** | |
219 | *** 1372,1383 **** | |
220 | return NULL; | |
221 | ||
222 | if (menu->modes & expand_modes) | |
223 | ! str = menu->dname; | |
224 | else | |
225 | str = (char_u *)""; | |
226 | ||
227 | ! /* Advance to next menu entry. */ | |
228 | ! menu = menu->next; | |
229 | ||
230 | return str; | |
231 | } | |
232 | --- 1354,1383 ---- | |
233 | return NULL; | |
234 | ||
235 | if (menu->modes & expand_modes) | |
236 | ! #ifdef FEAT_MULTI_LANG | |
237 | ! if (should_advance) | |
238 | ! str = menu->en_dname; | |
239 | ! else | |
240 | ! { | |
241 | ! #endif | |
242 | ! str = menu->dname; | |
243 | ! #ifdef FEAT_MULTI_LANG | |
244 | ! if (menu->en_dname == NULL) | |
245 | ! should_advance = TRUE; | |
246 | ! } | |
247 | ! #endif | |
248 | else | |
249 | str = (char_u *)""; | |
250 | ||
251 | ! #ifdef FEAT_MULTI_LANG | |
252 | ! if (should_advance) | |
253 | ! #endif | |
254 | ! /* Advance to next menu entry. */ | |
255 | ! menu = menu->next; | |
256 | ! | |
257 | ! #ifdef FEAT_MULTI_LANG | |
258 | ! should_advance = !should_advance; | |
259 | ! #endif | |
260 | ||
261 | return str; | |
262 | } | |
263 | *************** | |
264 | *** 1394,1402 **** | |
265 | --- 1394,1408 ---- | |
266 | static vimmenu_T *menu = NULL; | |
267 | static char_u tbuffer[256]; /*hack*/ | |
268 | char_u *str; | |
269 | + #ifdef FEAT_MULTI_LANG | |
270 | + static int should_advance = FALSE; | |
271 | + #endif | |
272 | ||
273 | if (idx == 0) /* first call: start at first item */ | |
274 | + { | |
275 | menu = expand_menu; | |
276 | + should_advance = FALSE; | |
277 | + } | |
278 | ||
279 | /* Skip Browse-style entries, popup menus and separators. */ | |
280 | while (menu != NULL | |
281 | *************** | |
282 | *** 1416,1435 **** | |
283 | { | |
284 | if (menu->children != NULL) | |
285 | { | |
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"); | |
290 | str = tbuffer; | |
291 | } | |
292 | else | |
293 | ! str = menu->dname; | |
294 | } | |
295 | else | |
296 | str = (char_u *)""; | |
297 | ||
298 | ! /* Advance to next menu entry. */ | |
299 | ! menu = menu->next; | |
300 | ||
301 | return str; | |
302 | } | |
303 | --- 1422,1472 ---- | |
304 | { | |
305 | if (menu->children != NULL) | |
306 | { | |
307 | ! #ifdef FEAT_MULTI_LANG | |
308 | ! if (should_advance) | |
309 | ! STRCPY(tbuffer, menu->en_dname); | |
310 | ! else | |
311 | ! { | |
312 | ! #endif | |
313 | ! STRCPY(tbuffer, menu->dname); | |
314 | ! #ifdef FEAT_MULTI_LANG | |
315 | ! if (menu->en_dname == NULL) | |
316 | ! should_advance = TRUE; | |
317 | ! } | |
318 | ! #endif | |
319 | /* hack on menu separators: use a 'magic' char for the separator | |
320 | * so that '.' in names gets escaped properly */ | |
321 | STRCAT(tbuffer, "\001"); | |
322 | str = tbuffer; | |
323 | } | |
324 | else | |
325 | ! #ifdef FEAT_MULTI_LANG | |
326 | ! { | |
327 | ! if (should_advance) | |
328 | ! str = menu->en_dname; | |
329 | ! else | |
330 | ! { | |
331 | ! #endif | |
332 | ! str = menu->dname; | |
333 | ! #ifdef FEAT_MULTI_LANG | |
334 | ! if (menu->en_dname == NULL) | |
335 | ! should_advance = TRUE; | |
336 | ! } | |
337 | ! } | |
338 | ! #endif | |
339 | } | |
340 | else | |
341 | str = (char_u *)""; | |
342 | ||
343 | ! #ifdef FEAT_MULTI_LANG | |
344 | ! if (should_advance) | |
345 | ! #endif | |
346 | ! /* Advance to next menu entry. */ | |
347 | ! menu = menu->next; | |
348 | ! | |
349 | ! #ifdef FEAT_MULTI_LANG | |
350 | ! should_advance = !should_advance; | |
351 | ! #endif | |
352 | ||
353 | return str; | |
354 | } | |
355 | *************** | |
356 | *** 1469,1475 **** | |
357 | char_u *name; | |
358 | vimmenu_T *menu; | |
359 | { | |
360 | ! return (menu_namecmp(name, menu->name) || menu_namecmp(name, menu->dname)); | |
361 | } | |
362 | ||
363 | static int | |
364 | --- 1506,1516 ---- | |
365 | char_u *name; | |
366 | vimmenu_T *menu; | |
367 | { | |
368 | ! if (menu->en_name != NULL | |
369 | ! && (menu_namecmp(name,menu->en_name) | |
370 | ! || menu_namecmp(name,menu->en_dname))) | |
371 | ! return TRUE; | |
372 | ! return menu_namecmp(name, menu->name) || menu_namecmp(name, menu->dname); | |
373 | } | |
374 | ||
375 | static int | |
376 | *************** | |
377 | *** 2402,2407 **** | |
378 | --- 2443,2452 ---- | |
379 | to = vim_strnsave(to, (int)(arg - to)); | |
380 | if (from_noamp != NULL && to != NULL) | |
381 | { | |
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; | |
389 | *************** | |
390 | *** 2476,2479 **** | |
391 | --- 2521,2566 ---- | |
392 | } | |
393 | #endif /* FEAT_MULTI_LANG */ | |
394 | ||
395 | + /* | |
396 | + * Unescape the name in the translate dictionary table. | |
397 | + */ | |
398 | + static void | |
399 | + menu_unescape_name(name) | |
400 | + char_u *name; | |
401 | + { | |
402 | + char_u *p; | |
403 | + | |
404 | + for (p = name; *p && *p != '.'; mb_ptr_adv(p)) | |
405 | + if (*p == '\\') | |
406 | + STRMOVE(p, p + 1); | |
407 | + } | |
408 | + | |
409 | + /* | |
410 | + * Isolate the menu name. | |
411 | + * Skip the menu name, and translate <Tab> into a real TAB. | |
412 | + */ | |
413 | + static char_u * | |
414 | + menu_translate_tab_and_shift(arg_start) | |
415 | + char_u *arg_start; | |
416 | + { | |
417 | + char_u *arg = arg_start; | |
418 | + | |
419 | + while (*arg && !vim_iswhite(*arg)) | |
420 | + { | |
421 | + if ((*arg == '\\' || *arg == Ctrl_V) && arg[1] != NUL) | |
422 | + arg++; | |
423 | + else if (STRNICMP(arg, "<TAB>", 5) == 0) | |
424 | + { | |
425 | + *arg = TAB; | |
426 | + STRMOVE(arg + 1, arg + 5); | |
427 | + } | |
428 | + arg++; | |
429 | + } | |
430 | + if (*arg != NUL) | |
431 | + *arg++ = NUL; | |
432 | + arg = skipwhite(arg); | |
433 | + | |
434 | + return arg; | |
435 | + } | |
436 | + | |
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 | |
440 | *************** | |
441 | *** 232,238 **** | |
442 | { | |
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 */ | |
449 | --- 232,238 ---- | |
450 | { | |
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 */ | |
457 | *************** | |
458 | *** 2207,2214 **** | |
459 | { | |
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 */ | |
467 | --- 2207,2220 ---- | |
468 | { | |
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 */ | |
478 | ! #endif | |
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 | |
484 | *************** | |
485 | *** 683,684 **** | |
486 | --- 683,686 ---- | |
487 | { /* Add new patch number below this line */ | |
488 | + /**/ | |
489 | + 432, | |
490 | /**/ | |
491 | ||
492 | -- | |
493 | It is hard to understand how a cemetery raised its burial | |
494 | cost and blamed it on the cost of living. | |
495 | ||
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 /// |