Mercurial > vim
annotate src/menu.c @ 18426:3b80bdbdc832 v8.1.2207
patch 8.1.2207: "gn" doesn't work quite right
Commit: https://github.com/vim/vim/commit/edaad6e0a0e3c1fcb6a5c2771e647c52475bb19c
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Oct 24 15:23:37 2019 +0200
patch 8.1.2207: "gn" doesn't work quite right
Problem: "gn" doesn't work quite right. (Jaehwang Jerry Jung)
Solution: Improve and simplify the search logic. (Christian Brabandt,
closes #5103, closes #5075)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 24 Oct 2019 15:30:03 +0200 |
parents | 506bf60a30a0 |
children | e9b2ade1adbd |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9536
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * GUI/Motif support by Robert Webb | |
5 * | |
6 * Do ":help uganda" in Vim to read copying and usage conditions. | |
7 * Do ":help credits" in Vim to see a list of people who contributed. | |
8 * See README.txt for an overview of the Vim source code. | |
9 */ | |
10 | |
11 /* | |
12 * Code for menus. Used for the GUI and 'wildmenu'. | |
13 */ | |
14 | |
15 #include "vim.h" | |
16 | |
17 #if defined(FEAT_MENU) || defined(PROTO) | |
18 | |
19 #define MENUDEPTH 10 /* maximum depth of menus */ | |
20 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
21 #ifdef FEAT_GUI_MSWIN |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
5735
diff
changeset
|
22 static int add_menu_path(char_u *, vimmenu_T *, int *, char_u *, int); |
7 | 23 #else |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
5735
diff
changeset
|
24 static int add_menu_path(char_u *, vimmenu_T *, int *, char_u *); |
7 | 25 #endif |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
5735
diff
changeset
|
26 static int menu_nable_recurse(vimmenu_T *menu, char_u *name, int modes, int enable); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
5735
diff
changeset
|
27 static int remove_menu(vimmenu_T **, char_u *, int, int silent); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
5735
diff
changeset
|
28 static void free_menu(vimmenu_T **menup); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
5735
diff
changeset
|
29 static void free_menu_string(vimmenu_T *, int); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
5735
diff
changeset
|
30 static int show_menus(char_u *, int); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
5735
diff
changeset
|
31 static void show_menus_recursive(vimmenu_T *, int, int); |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
32 static char_u *menu_name_skip(char_u *name); |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
5735
diff
changeset
|
33 static int menu_name_equal(char_u *name, vimmenu_T *menu); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
5735
diff
changeset
|
34 static int menu_namecmp(char_u *name, char_u *mname); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
5735
diff
changeset
|
35 static int get_menu_cmd_modes(char_u *, int, int *, int *); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
5735
diff
changeset
|
36 static char_u *popup_mode_name(char_u *name, int idx); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
5735
diff
changeset
|
37 static char_u *menu_text(char_u *text, int *mnemonic, char_u **actext); |
7 | 38 |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
39 #if defined(FEAT_GUI_MSWIN) && defined(FEAT_TEAROFF) |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
5735
diff
changeset
|
40 static void gui_create_tearoffs_recurse(vimmenu_T *menu, const char_u *pname, int *pri_tab, int pri_idx); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
5735
diff
changeset
|
41 static void gui_add_tearoff(char_u *tearpath, int *pri_tab, int pri_idx); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
5735
diff
changeset
|
42 static void gui_destroy_tearoffs_recurse(vimmenu_T *menu); |
7 | 43 static int s_tearoffs = FALSE; |
44 #endif | |
45 | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
5735
diff
changeset
|
46 static int menu_is_hidden(char_u *name); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
5735
diff
changeset
|
47 static int menu_is_tearoff(char_u *name); |
7 | 48 |
49 #if defined(FEAT_MULTI_LANG) || defined(FEAT_TOOLBAR) | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
5735
diff
changeset
|
50 static char_u *menu_skip_part(char_u *p); |
7 | 51 #endif |
52 #ifdef FEAT_MULTI_LANG | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
5735
diff
changeset
|
53 static char_u *menutrans_lookup(char_u *name, int len); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
5735
diff
changeset
|
54 static void menu_unescape_name(char_u *p); |
7 | 55 #endif |
56 | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
5735
diff
changeset
|
57 static char_u *menu_translate_tab_and_shift(char_u *arg_start); |
2150
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
58 |
7 | 59 /* The character for each menu mode */ |
14952
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
60 static char *menu_mode_chars[] = {"n", "v", "s", "o", "i", "c", "tl", "t"}; |
7 | 61 |
62 static char_u e_notsubmenu[] = N_("E327: Part of menu-item path is not sub-menu"); | |
436 | 63 static char_u e_nomenu[] = N_("E329: No menu \"%s\""); |
7 | 64 |
65 #ifdef FEAT_TOOLBAR | |
66 static const char *toolbar_names[] = | |
67 { | |
68 /* 0 */ "New", "Open", "Save", "Undo", "Redo", | |
69 /* 5 */ "Cut", "Copy", "Paste", "Print", "Help", | |
70 /* 10 */ "Find", "SaveAll", "SaveSesn", "NewSesn", "LoadSesn", | |
71 /* 15 */ "RunScript", "Replace", "WinClose", "WinMax", "WinMin", | |
72 /* 20 */ "WinSplit", "Shell", "FindPrev", "FindNext", "FindHelp", | |
73 /* 25 */ "Make", "TagJump", "RunCtags", "WinVSplit", "WinMaxWidth", | |
74 /* 30 */ "WinMinWidth", "Exit" | |
75 }; | |
76 # define TOOLBAR_NAME_COUNT (sizeof(toolbar_names) / sizeof(char *)) | |
77 #endif | |
78 | |
79 /* | |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
80 * Return TRUE if "name" is a window toolbar menu name. |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
81 */ |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
82 static int |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
83 menu_is_winbar(char_u *name) |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
84 { |
12527
259983a729fa
patch 8.0.1142: window toolbar menu gets a tear-off item
Christian Brabandt <cb@256bit.org>
parents:
12521
diff
changeset
|
85 return (STRNCMP(name, "WinBar", 6) == 0); |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
86 } |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
87 |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
88 int |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
89 winbar_height(win_T *wp) |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
90 { |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
91 if (wp->w_winbar != NULL && wp->w_winbar->children != NULL) |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
92 return 1; |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
93 return 0; |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
94 } |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
95 |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
96 static vimmenu_T ** |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
97 get_root_menu(char_u *name) |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
98 { |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
99 if (menu_is_winbar(name)) |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
100 return &curwin->w_winbar; |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
101 return &root_menu; |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
102 } |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
103 |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
104 /* |
7 | 105 * Do the :menu command and relatives. |
106 */ | |
107 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
108 ex_menu( |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
109 exarg_T *eap) /* Ex command arguments */ |
7 | 110 { |
111 char_u *menu_path; | |
112 int modes; | |
113 char_u *map_to; | |
114 int noremap; | |
115 int silent = FALSE; | |
860 | 116 int special = FALSE; |
7 | 117 int unmenu; |
118 char_u *map_buf; | |
119 char_u *arg; | |
120 char_u *p; | |
121 int i; | |
575 | 122 #if defined(FEAT_GUI) && !defined(FEAT_GUI_GTK) |
7 | 123 int old_menu_height; |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
124 # if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN) |
7 | 125 int old_toolbar_height; |
126 # endif | |
127 #endif | |
128 int pri_tab[MENUDEPTH + 1]; | |
129 int enable = MAYBE; /* TRUE for "menu enable", FALSE for "menu | |
130 * disable */ | |
131 #ifdef FEAT_TOOLBAR | |
132 char_u *icon = NULL; | |
133 #endif | |
134 vimmenu_T menuarg; | |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
135 vimmenu_T **root_menu_ptr; |
7 | 136 |
137 modes = get_menu_cmd_modes(eap->cmd, eap->forceit, &noremap, &unmenu); | |
138 arg = eap->arg; | |
139 | |
140 for (;;) | |
141 { | |
142 if (STRNCMP(arg, "<script>", 8) == 0) | |
143 { | |
144 noremap = REMAP_SCRIPT; | |
145 arg = skipwhite(arg + 8); | |
146 continue; | |
147 } | |
148 if (STRNCMP(arg, "<silent>", 8) == 0) | |
149 { | |
150 silent = TRUE; | |
151 arg = skipwhite(arg + 8); | |
152 continue; | |
153 } | |
860 | 154 if (STRNCMP(arg, "<special>", 9) == 0) |
155 { | |
156 special = TRUE; | |
157 arg = skipwhite(arg + 9); | |
158 continue; | |
159 } | |
7 | 160 break; |
161 } | |
162 | |
163 | |
164 /* Locate an optional "icon=filename" argument. */ | |
165 if (STRNCMP(arg, "icon=", 5) == 0) | |
166 { | |
167 arg += 5; | |
168 #ifdef FEAT_TOOLBAR | |
169 icon = arg; | |
170 #endif | |
171 while (*arg != NUL && *arg != ' ') | |
172 { | |
173 if (*arg == '\\') | |
1624 | 174 STRMOVE(arg, arg + 1); |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11044
diff
changeset
|
175 MB_PTR_ADV(arg); |
7 | 176 } |
177 if (*arg != NUL) | |
178 { | |
179 *arg++ = NUL; | |
180 arg = skipwhite(arg); | |
181 } | |
182 } | |
183 | |
184 /* | |
185 * Fill in the priority table. | |
186 */ | |
187 for (p = arg; *p; ++p) | |
188 if (!VIM_ISDIGIT(*p) && *p != '.') | |
189 break; | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
190 if (VIM_ISWHITE(*p)) |
7 | 191 { |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
192 for (i = 0; i < MENUDEPTH && !VIM_ISWHITE(*arg); ++i) |
7 | 193 { |
194 pri_tab[i] = getdigits(&arg); | |
195 if (pri_tab[i] == 0) | |
196 pri_tab[i] = 500; | |
197 if (*arg == '.') | |
198 ++arg; | |
199 } | |
200 arg = skipwhite(arg); | |
201 } | |
202 else if (eap->addr_count && eap->line2 != 0) | |
203 { | |
204 pri_tab[0] = eap->line2; | |
205 i = 1; | |
206 } | |
207 else | |
208 i = 0; | |
209 while (i < MENUDEPTH) | |
210 pri_tab[i++] = 500; | |
211 pri_tab[MENUDEPTH] = -1; /* mark end of the table */ | |
212 | |
213 /* | |
214 * Check for "disable" or "enable" argument. | |
215 */ | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
216 if (STRNCMP(arg, "enable", 6) == 0 && VIM_ISWHITE(arg[6])) |
7 | 217 { |
218 enable = TRUE; | |
219 arg = skipwhite(arg + 6); | |
220 } | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
221 else if (STRNCMP(arg, "disable", 7) == 0 && VIM_ISWHITE(arg[7])) |
7 | 222 { |
223 enable = FALSE; | |
224 arg = skipwhite(arg + 7); | |
225 } | |
226 | |
227 /* | |
228 * If there is no argument, display all menus. | |
229 */ | |
230 if (*arg == NUL) | |
231 { | |
232 show_menus(arg, modes); | |
233 return; | |
234 } | |
235 | |
236 #ifdef FEAT_TOOLBAR | |
237 /* | |
238 * Need to get the toolbar icon index before doing the translation. | |
239 */ | |
240 menuarg.iconidx = -1; | |
241 menuarg.icon_builtin = FALSE; | |
242 if (menu_is_toolbar(arg)) | |
243 { | |
244 menu_path = menu_skip_part(arg); | |
245 if (*menu_path == '.') | |
246 { | |
247 p = menu_skip_part(++menu_path); | |
248 if (STRNCMP(menu_path, "BuiltIn", 7) == 0) | |
249 { | |
250 if (skipdigits(menu_path + 7) == p) | |
251 { | |
252 menuarg.iconidx = atoi((char *)menu_path + 7); | |
1880 | 253 if (menuarg.iconidx >= (int)TOOLBAR_NAME_COUNT) |
7 | 254 menuarg.iconidx = -1; |
255 else | |
256 menuarg.icon_builtin = TRUE; | |
257 } | |
258 } | |
259 else | |
260 { | |
1880 | 261 for (i = 0; i < (int)TOOLBAR_NAME_COUNT; ++i) |
7 | 262 if (STRNCMP(toolbar_names[i], menu_path, p - menu_path) |
263 == 0) | |
264 { | |
265 menuarg.iconidx = i; | |
266 break; | |
267 } | |
268 } | |
269 } | |
270 } | |
271 #endif | |
272 | |
273 menu_path = arg; | |
274 if (*menu_path == '.') | |
275 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15375
diff
changeset
|
276 semsg(_(e_invarg2), menu_path); |
7 | 277 goto theend; |
278 } | |
279 | |
2150
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
280 map_to = menu_translate_tab_and_shift(arg); |
7 | 281 |
282 /* | |
283 * If there is only a menu name, display menus with that name. | |
284 */ | |
285 if (*map_to == NUL && !unmenu && enable == MAYBE) | |
286 { | |
287 show_menus(menu_path, modes); | |
288 goto theend; | |
289 } | |
290 else if (*map_to != NUL && (unmenu || enable != MAYBE)) | |
291 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15375
diff
changeset
|
292 emsg(_(e_trailing)); |
7 | 293 goto theend; |
294 } | |
575 | 295 #if defined(FEAT_GUI) && !(defined(FEAT_GUI_GTK) || defined(FEAT_GUI_PHOTON)) |
7 | 296 old_menu_height = gui.menu_height; |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
297 # if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN) |
7 | 298 old_toolbar_height = gui.toolbar_height; |
299 # endif | |
300 #endif | |
301 | |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
302 root_menu_ptr = get_root_menu(menu_path); |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
303 if (root_menu_ptr == &curwin->w_winbar) |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
304 /* Assume the window toolbar menu will change. */ |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
305 redraw_later(NOT_VALID); |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
306 |
7 | 307 if (enable != MAYBE) |
308 { | |
309 /* | |
310 * Change sensitivity of the menu. | |
311 * For the PopUp menu, remove a menu for each mode separately. | |
312 * Careful: menu_nable_recurse() changes menu_path. | |
313 */ | |
314 if (STRCMP(menu_path, "*") == 0) /* meaning: do all menus */ | |
315 menu_path = (char_u *)""; | |
316 | |
317 if (menu_is_popup(menu_path)) | |
318 { | |
319 for (i = 0; i < MENU_INDEX_TIP; ++i) | |
320 if (modes & (1 << i)) | |
321 { | |
322 p = popup_mode_name(menu_path, i); | |
323 if (p != NULL) | |
324 { | |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
325 menu_nable_recurse(*root_menu_ptr, p, MENU_ALL_MODES, |
7 | 326 enable); |
327 vim_free(p); | |
328 } | |
329 } | |
330 } | |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
331 menu_nable_recurse(*root_menu_ptr, menu_path, modes, enable); |
7 | 332 } |
333 else if (unmenu) | |
334 { | |
335 /* | |
336 * Delete menu(s). | |
337 */ | |
338 if (STRCMP(menu_path, "*") == 0) /* meaning: remove all menus */ | |
339 menu_path = (char_u *)""; | |
340 | |
341 /* | |
342 * For the PopUp menu, remove a menu for each mode separately. | |
343 */ | |
344 if (menu_is_popup(menu_path)) | |
345 { | |
346 for (i = 0; i < MENU_INDEX_TIP; ++i) | |
347 if (modes & (1 << i)) | |
348 { | |
349 p = popup_mode_name(menu_path, i); | |
350 if (p != NULL) | |
351 { | |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
352 remove_menu(root_menu_ptr, p, MENU_ALL_MODES, TRUE); |
7 | 353 vim_free(p); |
354 } | |
355 } | |
356 } | |
357 | |
358 /* Careful: remove_menu() changes menu_path */ | |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
359 remove_menu(root_menu_ptr, menu_path, modes, FALSE); |
7 | 360 } |
361 else | |
362 { | |
363 /* | |
364 * Add menu(s). | |
365 * Replace special key codes. | |
366 */ | |
367 if (STRICMP(map_to, "<nop>") == 0) /* "<Nop>" means nothing */ | |
368 { | |
369 map_to = (char_u *)""; | |
370 map_buf = NULL; | |
371 } | |
26 | 372 else if (modes & MENU_TIP_MODE) |
373 map_buf = NULL; /* Menu tips are plain text. */ | |
7 | 374 else |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
375 map_to = replace_termcodes(map_to, &map_buf, |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
376 REPTERM_DO_LT | (special ? REPTERM_SPECIAL : 0), NULL); |
7 | 377 menuarg.modes = modes; |
378 #ifdef FEAT_TOOLBAR | |
379 menuarg.iconfile = icon; | |
380 #endif | |
381 menuarg.noremap[0] = noremap; | |
382 menuarg.silent[0] = silent; | |
383 add_menu_path(menu_path, &menuarg, pri_tab, map_to | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
384 #ifdef FEAT_GUI_MSWIN |
7 | 385 , TRUE |
386 #endif | |
387 ); | |
388 | |
389 /* | |
390 * For the PopUp menu, add a menu for each mode separately. | |
391 */ | |
392 if (menu_is_popup(menu_path)) | |
393 { | |
394 for (i = 0; i < MENU_INDEX_TIP; ++i) | |
395 if (modes & (1 << i)) | |
396 { | |
397 p = popup_mode_name(menu_path, i); | |
398 if (p != NULL) | |
399 { | |
400 /* Include all modes, to make ":amenu" work */ | |
401 menuarg.modes = modes; | |
402 #ifdef FEAT_TOOLBAR | |
403 menuarg.iconfile = NULL; | |
404 menuarg.iconidx = -1; | |
405 menuarg.icon_builtin = FALSE; | |
406 #endif | |
407 add_menu_path(p, &menuarg, pri_tab, map_to | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
408 #ifdef FEAT_GUI_MSWIN |
7 | 409 , TRUE |
410 #endif | |
411 ); | |
412 vim_free(p); | |
413 } | |
414 } | |
415 } | |
416 | |
417 vim_free(map_buf); | |
418 } | |
419 | |
575 | 420 #if defined(FEAT_GUI) && !(defined(FEAT_GUI_GTK)) |
7 | 421 /* If the menubar height changed, resize the window */ |
422 if (gui.in_use | |
423 && (gui.menu_height != old_menu_height | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
424 # if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN) |
7 | 425 || gui.toolbar_height != old_toolbar_height |
426 # endif | |
427 )) | |
814 | 428 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT); |
7 | 429 #endif |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
430 if (root_menu_ptr == &curwin->w_winbar) |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
431 { |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
432 int h = winbar_height(curwin); |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
433 |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
434 if (h != curwin->w_winbar_height) |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
435 { |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
436 if (h == 0) |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
437 ++curwin->w_height; |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
438 else if (curwin->w_height > 0) |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
439 --curwin->w_height; |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
440 curwin->w_winbar_height = h; |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
441 } |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
442 } |
7 | 443 |
444 theend: | |
445 ; | |
446 } | |
447 | |
448 /* | |
449 * Add the menu with the given name to the menu hierarchy | |
450 */ | |
451 static int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
452 add_menu_path( |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
453 char_u *menu_path, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
454 vimmenu_T *menuarg, /* passes modes, iconfile, iconidx, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
455 icon_builtin, silent[0], noremap[0] */ |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
456 int *pri_tab, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
457 char_u *call_data |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
458 #ifdef FEAT_GUI_MSWIN |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
459 , int addtearoff /* may add tearoff item */ |
7 | 460 #endif |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
461 ) |
7 | 462 { |
463 char_u *path_name; | |
464 int modes = menuarg->modes; | |
465 vimmenu_T **menup; | |
466 vimmenu_T *menu = NULL; | |
467 vimmenu_T *parent; | |
468 vimmenu_T **lower_pri; | |
469 char_u *p; | |
470 char_u *name; | |
471 char_u *dname; | |
472 char_u *next_name; | |
473 int i; | |
474 int c; | |
2149
4c8008ab94d8
updated for version 7.2.431
Bram Moolenaar <bram@zimbu.org>
parents:
1883
diff
changeset
|
475 int d; |
7 | 476 #ifdef FEAT_GUI |
477 int idx; | |
478 int new_idx; | |
479 #endif | |
480 int pri_idx = 0; | |
481 int old_modes = 0; | |
482 int amenu; | |
2150
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
483 #ifdef FEAT_MULTI_LANG |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
484 char_u *en_name; |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
485 char_u *map_to = NULL; |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
486 #endif |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
487 vimmenu_T **root_menu_ptr; |
7 | 488 |
489 /* Make a copy so we can stuff around with it, since it could be const */ | |
490 path_name = vim_strsave(menu_path); | |
491 if (path_name == NULL) | |
492 return FAIL; | |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
493 root_menu_ptr = get_root_menu(menu_path); |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
494 menup = root_menu_ptr; |
7 | 495 parent = NULL; |
496 name = path_name; | |
497 while (*name) | |
498 { | |
499 /* Get name of this element in the menu hierarchy, and the simplified | |
500 * name (without mnemonic and accelerator text). */ | |
501 next_name = menu_name_skip(name); | |
2150
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
502 #ifdef FEAT_MULTI_LANG |
2217
120502692d82
Improve the MS-Windows installer.
Bram Moolenaar <bram@vim.org>
parents:
2166
diff
changeset
|
503 map_to = menutrans_lookup(name, (int)STRLEN(name)); |
2150
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
504 if (map_to != NULL) |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
505 { |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
506 en_name = name; |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
507 name = map_to; |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
508 } |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
509 else |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
510 en_name = NULL; |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
511 #endif |
7 | 512 dname = menu_text(name, NULL, NULL); |
928 | 513 if (dname == NULL) |
514 goto erret; | |
515 if (*dname == NUL) | |
516 { | |
517 /* Only a mnemonic or accelerator is not valid. */ | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15375
diff
changeset
|
518 emsg(_("E792: Empty menu name")); |
928 | 519 goto erret; |
520 } | |
7 | 521 |
522 /* See if it's already there */ | |
523 lower_pri = menup; | |
524 #ifdef FEAT_GUI | |
525 idx = 0; | |
526 new_idx = 0; | |
527 #endif | |
528 menu = *menup; | |
529 while (menu != NULL) | |
530 { | |
531 if (menu_name_equal(name, menu) || menu_name_equal(dname, menu)) | |
532 { | |
533 if (*next_name == NUL && menu->children != NULL) | |
534 { | |
535 if (!sys_menu) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15375
diff
changeset
|
536 emsg(_("E330: Menu path must not lead to a sub-menu")); |
7 | 537 goto erret; |
538 } | |
539 if (*next_name != NUL && menu->children == NULL | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
540 #ifdef FEAT_GUI_MSWIN |
7 | 541 && addtearoff |
542 #endif | |
543 ) | |
544 { | |
545 if (!sys_menu) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15375
diff
changeset
|
546 emsg(_(e_notsubmenu)); |
7 | 547 goto erret; |
548 } | |
549 break; | |
550 } | |
551 menup = &menu->next; | |
552 | |
553 /* Count menus, to find where this one needs to be inserted. | |
554 * Ignore menus that are not in the menubar (PopUp and Toolbar) */ | |
555 if (parent != NULL || menu_is_menubar(menu->name)) | |
556 { | |
557 #ifdef FEAT_GUI | |
558 ++idx; | |
559 #endif | |
560 if (menu->priority <= pri_tab[pri_idx]) | |
561 { | |
562 lower_pri = menup; | |
563 #ifdef FEAT_GUI | |
564 new_idx = idx; | |
565 #endif | |
566 } | |
567 } | |
568 menu = menu->next; | |
569 } | |
570 | |
571 if (menu == NULL) | |
572 { | |
573 if (*next_name == NUL && parent == NULL) | |
574 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15375
diff
changeset
|
575 emsg(_("E331: Must not add menu items directly to menu bar")); |
7 | 576 goto erret; |
577 } | |
578 | |
579 if (menu_is_separator(dname) && *next_name != NUL) | |
580 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15375
diff
changeset
|
581 emsg(_("E332: Separator cannot be part of a menu path")); |
7 | 582 goto erret; |
583 } | |
584 | |
585 /* Not already there, so lets add it */ | |
17262
041156ce1d22
patch 8.1.1630: various small problems
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
586 menu = ALLOC_CLEAR_ONE(vimmenu_T); |
7 | 587 if (menu == NULL) |
588 goto erret; | |
589 | |
590 menu->modes = modes; | |
591 menu->enabled = MENU_ALL_MODES; | |
592 menu->name = vim_strsave(name); | |
593 /* separate mnemonic and accelerator text from actual menu name */ | |
594 menu->dname = menu_text(name, &menu->mnemonic, &menu->actext); | |
2150
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
595 #ifdef FEAT_MULTI_LANG |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
596 if (en_name != NULL) |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
597 { |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
598 menu->en_name = vim_strsave(en_name); |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
599 menu->en_dname = menu_text(en_name, NULL, NULL); |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
600 } |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
601 else |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
602 { |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
603 menu->en_name = NULL; |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
604 menu->en_dname = NULL; |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
605 } |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
606 #endif |
7 | 607 menu->priority = pri_tab[pri_idx]; |
608 menu->parent = parent; | |
609 #ifdef FEAT_GUI_MOTIF | |
610 menu->sensitive = TRUE; /* the default */ | |
611 #endif | |
612 #ifdef FEAT_BEVAL_TIP | |
613 menu->tip = NULL; | |
614 #endif | |
615 #ifdef FEAT_GUI_ATHENA | |
616 menu->image = None; /* X-Windows definition for NULL*/ | |
617 #endif | |
618 | |
619 /* | |
620 * Add after menu that has lower priority. | |
621 */ | |
622 menu->next = *lower_pri; | |
623 *lower_pri = menu; | |
624 | |
625 old_modes = 0; | |
626 | |
627 #ifdef FEAT_TOOLBAR | |
628 menu->iconidx = menuarg->iconidx; | |
629 menu->icon_builtin = menuarg->icon_builtin; | |
630 if (*next_name == NUL && menuarg->iconfile != NULL) | |
631 menu->iconfile = vim_strsave(menuarg->iconfile); | |
632 #endif | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
633 #if defined(FEAT_GUI_MSWIN) && defined(FEAT_TEAROFF) |
7 | 634 /* the tearoff item must be present in the modes of each item. */ |
635 if (parent != NULL && menu_is_tearoff(parent->children->dname)) | |
636 parent->children->modes |= modes; | |
637 #endif | |
638 } | |
639 else | |
640 { | |
641 old_modes = menu->modes; | |
642 | |
643 /* | |
644 * If this menu option was previously only available in other | |
645 * modes, then make sure it's available for this one now | |
646 * Also enable a menu when it's created or changed. | |
647 */ | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
648 #ifdef FEAT_GUI_MSWIN |
7 | 649 /* If adding a tearbar (addtearoff == FALSE) don't update modes */ |
650 if (addtearoff) | |
651 #endif | |
652 { | |
653 menu->modes |= modes; | |
654 menu->enabled |= modes; | |
655 } | |
656 } | |
657 | |
658 #ifdef FEAT_GUI | |
659 /* | |
660 * Add the menu item when it's used in one of the modes, but not when | |
661 * only a tooltip is defined. | |
662 */ | |
663 if ((old_modes & MENU_ALL_MODES) == 0 | |
664 && (menu->modes & MENU_ALL_MODES) != 0) | |
665 { | |
666 if (gui.in_use) /* Otherwise it will be added when GUI starts */ | |
667 { | |
668 if (*next_name == NUL) | |
669 { | |
670 /* Real menu item, not sub-menu */ | |
671 gui_mch_add_menu_item(menu, new_idx); | |
672 | |
673 /* Want to update menus now even if mode not changed */ | |
674 force_menu_update = TRUE; | |
675 } | |
676 else | |
677 { | |
678 /* Sub-menu (not at end of path yet) */ | |
679 gui_mch_add_menu(menu, new_idx); | |
680 } | |
681 } | |
682 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
683 # if defined(FEAT_GUI_MSWIN) & defined(FEAT_TEAROFF) |
7 | 684 /* When adding a new submenu, may add a tearoff item */ |
685 if ( addtearoff | |
686 && *next_name | |
687 && vim_strchr(p_go, GO_TEAROFF) != NULL | |
688 && menu_is_menubar(name)) | |
689 { | |
690 char_u *tearpath; | |
691 | |
692 /* | |
693 * The pointers next_name & path_name refer to a string with | |
694 * \'s and ^V's stripped out. But menu_path is a "raw" | |
695 * string, so we must correct for special characters. | |
696 */ | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16541
diff
changeset
|
697 tearpath = alloc(STRLEN(menu_path) + TEAR_LEN + 2); |
7 | 698 if (tearpath != NULL) |
699 { | |
700 char_u *s; | |
701 int idx; | |
702 | |
703 STRCPY(tearpath, menu_path); | |
704 idx = (int)(next_name - path_name - 1); | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11044
diff
changeset
|
705 for (s = tearpath; *s && s < tearpath + idx; MB_PTR_ADV(s)) |
7 | 706 { |
707 if ((*s == '\\' || *s == Ctrl_V) && s[1]) | |
708 { | |
709 ++idx; | |
710 ++s; | |
711 } | |
712 } | |
713 tearpath[idx] = NUL; | |
714 gui_add_tearoff(tearpath, pri_tab, pri_idx); | |
715 vim_free(tearpath); | |
716 } | |
717 } | |
718 # endif | |
719 } | |
720 #endif /* FEAT_GUI */ | |
721 | |
722 menup = &menu->children; | |
723 parent = menu; | |
724 name = next_name; | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12871
diff
changeset
|
725 VIM_CLEAR(dname); |
7 | 726 if (pri_tab[pri_idx + 1] != -1) |
727 ++pri_idx; | |
728 } | |
729 vim_free(path_name); | |
730 | |
731 /* | |
732 * Only add system menu items which have not been defined yet. | |
733 * First check if this was an ":amenu". | |
734 */ | |
735 amenu = ((modes & (MENU_NORMAL_MODE | MENU_INSERT_MODE)) == | |
736 (MENU_NORMAL_MODE | MENU_INSERT_MODE)); | |
737 if (sys_menu) | |
738 modes &= ~old_modes; | |
739 | |
740 if (menu != NULL && modes) | |
741 { | |
742 #ifdef FEAT_GUI | |
743 menu->cb = gui_menu_cb; | |
744 #endif | |
745 p = (call_data == NULL) ? NULL : vim_strsave(call_data); | |
746 | |
747 /* loop over all modes, may add more than one */ | |
748 for (i = 0; i < MENU_MODES; ++i) | |
749 { | |
750 if (modes & (1 << i)) | |
751 { | |
752 /* free any old menu */ | |
753 free_menu_string(menu, i); | |
754 | |
755 /* For "amenu", may insert an extra character. | |
756 * Don't do this if adding a tearbar (addtearoff == FALSE). | |
757 * Don't do this for "<Nop>". */ | |
758 c = 0; | |
2149
4c8008ab94d8
updated for version 7.2.431
Bram Moolenaar <bram@zimbu.org>
parents:
1883
diff
changeset
|
759 d = 0; |
7 | 760 if (amenu && call_data != NULL && *call_data != NUL |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
761 #ifdef FEAT_GUI_MSWIN |
7 | 762 && addtearoff |
763 #endif | |
764 ) | |
765 { | |
766 switch (1 << i) | |
767 { | |
768 case MENU_VISUAL_MODE: | |
791 | 769 case MENU_SELECT_MODE: |
7 | 770 case MENU_OP_PENDING_MODE: |
771 case MENU_CMDLINE_MODE: | |
772 c = Ctrl_C; | |
773 break; | |
774 case MENU_INSERT_MODE: | |
2149
4c8008ab94d8
updated for version 7.2.431
Bram Moolenaar <bram@zimbu.org>
parents:
1883
diff
changeset
|
775 c = Ctrl_BSL; |
4c8008ab94d8
updated for version 7.2.431
Bram Moolenaar <bram@zimbu.org>
parents:
1883
diff
changeset
|
776 d = Ctrl_O; |
7 | 777 break; |
778 } | |
779 } | |
780 | |
2149
4c8008ab94d8
updated for version 7.2.431
Bram Moolenaar <bram@zimbu.org>
parents:
1883
diff
changeset
|
781 if (c != 0) |
7 | 782 { |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16541
diff
changeset
|
783 menu->strings[i] = alloc(STRLEN(call_data) + 5); |
7 | 784 if (menu->strings[i] != NULL) |
785 { | |
786 menu->strings[i][0] = c; | |
2149
4c8008ab94d8
updated for version 7.2.431
Bram Moolenaar <bram@zimbu.org>
parents:
1883
diff
changeset
|
787 if (d == 0) |
4c8008ab94d8
updated for version 7.2.431
Bram Moolenaar <bram@zimbu.org>
parents:
1883
diff
changeset
|
788 STRCPY(menu->strings[i] + 1, call_data); |
4c8008ab94d8
updated for version 7.2.431
Bram Moolenaar <bram@zimbu.org>
parents:
1883
diff
changeset
|
789 else |
4c8008ab94d8
updated for version 7.2.431
Bram Moolenaar <bram@zimbu.org>
parents:
1883
diff
changeset
|
790 { |
4c8008ab94d8
updated for version 7.2.431
Bram Moolenaar <bram@zimbu.org>
parents:
1883
diff
changeset
|
791 menu->strings[i][1] = d; |
4c8008ab94d8
updated for version 7.2.431
Bram Moolenaar <bram@zimbu.org>
parents:
1883
diff
changeset
|
792 STRCPY(menu->strings[i] + 2, call_data); |
4c8008ab94d8
updated for version 7.2.431
Bram Moolenaar <bram@zimbu.org>
parents:
1883
diff
changeset
|
793 } |
7 | 794 if (c == Ctrl_C) |
795 { | |
835 | 796 int len = (int)STRLEN(menu->strings[i]); |
7 | 797 |
798 /* Append CTRL-\ CTRL-G to obey 'insertmode'. */ | |
799 menu->strings[i][len] = Ctrl_BSL; | |
800 menu->strings[i][len + 1] = Ctrl_G; | |
801 menu->strings[i][len + 2] = NUL; | |
802 } | |
803 } | |
804 } | |
805 else | |
806 menu->strings[i] = p; | |
807 menu->noremap[i] = menuarg->noremap[0]; | |
808 menu->silent[i] = menuarg->silent[0]; | |
809 } | |
810 } | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
811 #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN) \ |
12871
1a450ce6980c
patch 8.0.1312: balloon_show() only works in terminal when compiled with GUI
Christian Brabandt <cb@256bit.org>
parents:
12527
diff
changeset
|
812 && (defined(FEAT_BEVAL_GUI) || defined(FEAT_GUI_GTK)) |
7 | 813 /* Need to update the menu tip. */ |
814 if (modes & MENU_TIP_MODE) | |
815 gui_mch_menu_set_tip(menu); | |
816 #endif | |
817 } | |
818 return OK; | |
819 | |
820 erret: | |
821 vim_free(path_name); | |
822 vim_free(dname); | |
928 | 823 |
824 /* Delete any empty submenu we added before discovering the error. Repeat | |
825 * for higher levels. */ | |
826 while (parent != NULL && parent->children == NULL) | |
827 { | |
828 if (parent->parent == NULL) | |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
829 menup = root_menu_ptr; |
928 | 830 else |
831 menup = &parent->parent->children; | |
832 for ( ; *menup != NULL && *menup != parent; menup = &((*menup)->next)) | |
833 ; | |
834 if (*menup == NULL) /* safety check */ | |
835 break; | |
836 parent = parent->parent; | |
837 free_menu(menup); | |
838 } | |
7 | 839 return FAIL; |
840 } | |
841 | |
842 /* | |
843 * Set the (sub)menu with the given name to enabled or disabled. | |
844 * Called recursively. | |
845 */ | |
846 static int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
847 menu_nable_recurse( |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
848 vimmenu_T *menu, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
849 char_u *name, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
850 int modes, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
851 int enable) |
7 | 852 { |
853 char_u *p; | |
854 | |
855 if (menu == NULL) | |
856 return OK; /* Got to bottom of hierarchy */ | |
857 | |
858 /* Get name of this element in the menu hierarchy */ | |
859 p = menu_name_skip(name); | |
860 | |
861 /* Find the menu */ | |
862 while (menu != NULL) | |
863 { | |
864 if (*name == NUL || *name == '*' || menu_name_equal(name, menu)) | |
865 { | |
866 if (*p != NUL) | |
867 { | |
868 if (menu->children == NULL) | |
869 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15375
diff
changeset
|
870 emsg(_(e_notsubmenu)); |
7 | 871 return FAIL; |
872 } | |
873 if (menu_nable_recurse(menu->children, p, modes, enable) | |
874 == FAIL) | |
875 return FAIL; | |
876 } | |
877 else | |
878 if (enable) | |
879 menu->enabled |= modes; | |
880 else | |
881 menu->enabled &= ~modes; | |
882 | |
883 /* | |
884 * When name is empty, we are doing all menu items for the given | |
885 * modes, so keep looping, otherwise we are just doing the named | |
886 * menu item (which has been found) so break here. | |
887 */ | |
888 if (*name != NUL && *name != '*') | |
889 break; | |
890 } | |
891 menu = menu->next; | |
892 } | |
893 if (*name != NUL && *name != '*' && menu == NULL) | |
894 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15375
diff
changeset
|
895 semsg(_(e_nomenu), name); |
7 | 896 return FAIL; |
897 } | |
898 | |
899 #ifdef FEAT_GUI | |
900 /* Want to update menus now even if mode not changed */ | |
901 force_menu_update = TRUE; | |
902 #endif | |
903 | |
904 return OK; | |
905 } | |
906 | |
907 /* | |
908 * Remove the (sub)menu with the given name from the menu hierarchy | |
909 * Called recursively. | |
910 */ | |
911 static int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
912 remove_menu( |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
913 vimmenu_T **menup, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
914 char_u *name, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
915 int modes, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
916 int silent) /* don't give error messages */ |
7 | 917 { |
918 vimmenu_T *menu; | |
919 vimmenu_T *child; | |
920 char_u *p; | |
921 | |
922 if (*menup == NULL) | |
923 return OK; /* Got to bottom of hierarchy */ | |
924 | |
925 /* Get name of this element in the menu hierarchy */ | |
926 p = menu_name_skip(name); | |
927 | |
928 /* Find the menu */ | |
929 while ((menu = *menup) != NULL) | |
930 { | |
931 if (*name == NUL || menu_name_equal(name, menu)) | |
932 { | |
933 if (*p != NUL && menu->children == NULL) | |
934 { | |
935 if (!silent) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15375
diff
changeset
|
936 emsg(_(e_notsubmenu)); |
7 | 937 return FAIL; |
938 } | |
939 if ((menu->modes & modes) != 0x0) | |
940 { | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
941 #if defined(FEAT_GUI_MSWIN) & defined(FEAT_TEAROFF) |
7 | 942 /* |
943 * If we are removing all entries for this menu,MENU_ALL_MODES, | |
944 * Then kill any tearoff before we start | |
945 */ | |
946 if (*p == NUL && modes == MENU_ALL_MODES) | |
947 { | |
948 if (IsWindow(menu->tearoff_handle)) | |
949 DestroyWindow(menu->tearoff_handle); | |
950 } | |
951 #endif | |
952 if (remove_menu(&menu->children, p, modes, silent) == FAIL) | |
953 return FAIL; | |
954 } | |
955 else if (*name != NUL) | |
956 { | |
957 if (!silent) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15375
diff
changeset
|
958 emsg(_(e_menuothermode)); |
7 | 959 return FAIL; |
960 } | |
961 | |
962 /* | |
963 * When name is empty, we are removing all menu items for the given | |
964 * modes, so keep looping, otherwise we are just removing the named | |
965 * menu item (which has been found) so break here. | |
966 */ | |
967 if (*name != NUL) | |
968 break; | |
969 | |
970 /* Remove the menu item for the given mode[s]. If the menu item | |
971 * is no longer valid in ANY mode, delete it */ | |
972 menu->modes &= ~modes; | |
973 if (modes & MENU_TIP_MODE) | |
974 free_menu_string(menu, MENU_INDEX_TIP); | |
975 if ((menu->modes & MENU_ALL_MODES) == 0) | |
976 free_menu(menup); | |
977 else | |
978 menup = &menu->next; | |
979 } | |
980 else | |
981 menup = &menu->next; | |
982 } | |
983 if (*name != NUL) | |
984 { | |
985 if (menu == NULL) | |
986 { | |
987 if (!silent) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15375
diff
changeset
|
988 semsg(_(e_nomenu), name); |
7 | 989 return FAIL; |
990 } | |
991 | |
992 | |
993 /* Recalculate modes for menu based on the new updated children */ | |
994 menu->modes &= ~modes; | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
995 #if defined(FEAT_GUI_MSWIN) & defined(FEAT_TEAROFF) |
7 | 996 if ((s_tearoffs) && (menu->children != NULL)) /* there's a tear bar.. */ |
997 child = menu->children->next; /* don't count tearoff bar */ | |
998 else | |
999 #endif | |
1000 child = menu->children; | |
1001 for ( ; child != NULL; child = child->next) | |
1002 menu->modes |= child->modes; | |
1003 if (modes & MENU_TIP_MODE) | |
1004 { | |
1005 free_menu_string(menu, MENU_INDEX_TIP); | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
1006 #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN) \ |
12871
1a450ce6980c
patch 8.0.1312: balloon_show() only works in terminal when compiled with GUI
Christian Brabandt <cb@256bit.org>
parents:
12527
diff
changeset
|
1007 && (defined(FEAT_BEVAL_GUI) || defined(FEAT_GUI_GTK)) |
7 | 1008 /* Need to update the menu tip. */ |
1009 if (gui.in_use) | |
1010 gui_mch_menu_set_tip(menu); | |
1011 #endif | |
1012 } | |
1013 if ((menu->modes & MENU_ALL_MODES) == 0) | |
1014 { | |
1015 /* The menu item is no longer valid in ANY mode, so delete it */ | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
1016 #if defined(FEAT_GUI_MSWIN) & defined(FEAT_TEAROFF) |
7 | 1017 if (s_tearoffs && menu->children != NULL) /* there's a tear bar.. */ |
1018 free_menu(&menu->children); | |
1019 #endif | |
1020 *menup = menu; | |
1021 free_menu(menup); | |
1022 } | |
1023 } | |
1024 | |
1025 return OK; | |
1026 } | |
1027 | |
1028 /* | |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1029 * Remove the WinBar menu from window "wp". |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1030 */ |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1031 void |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1032 remove_winbar(win_T *wp) |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1033 { |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1034 remove_menu(&wp->w_winbar, (char_u *)"", MENU_ALL_MODES, TRUE); |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1035 vim_free(wp->w_winbar_items); |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1036 } |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1037 |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1038 /* |
7 | 1039 * Free the given menu structure and remove it from the linked list. |
1040 */ | |
1041 static void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1042 free_menu(vimmenu_T **menup) |
7 | 1043 { |
1044 int i; | |
1045 vimmenu_T *menu; | |
1046 | |
1047 menu = *menup; | |
1048 | |
1049 #ifdef FEAT_GUI | |
1050 /* Free machine specific menu structures (only when already created) */ | |
1051 /* Also may rebuild a tearoff'ed menu */ | |
1052 if (gui.in_use) | |
1053 gui_mch_destroy_menu(menu); | |
1054 #endif | |
1055 | |
1056 /* Don't change *menup until after calling gui_mch_destroy_menu(). The | |
1057 * MacOS code needs the original structure to properly delete the menu. */ | |
1058 *menup = menu->next; | |
1059 vim_free(menu->name); | |
1060 vim_free(menu->dname); | |
2150
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1061 #ifdef FEAT_MULTI_LANG |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1062 vim_free(menu->en_name); |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1063 vim_free(menu->en_dname); |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1064 #endif |
7 | 1065 vim_free(menu->actext); |
1066 #ifdef FEAT_TOOLBAR | |
1067 vim_free(menu->iconfile); | |
162 | 1068 # ifdef FEAT_GUI_MOTIF |
1069 vim_free(menu->xpm_fname); | |
1070 # endif | |
7 | 1071 #endif |
1072 for (i = 0; i < MENU_MODES; i++) | |
1073 free_menu_string(menu, i); | |
1074 vim_free(menu); | |
1075 | |
1076 #ifdef FEAT_GUI | |
1077 /* Want to update menus now even if mode not changed */ | |
1078 force_menu_update = TRUE; | |
1079 #endif | |
1080 } | |
1081 | |
1082 /* | |
1083 * Free the menu->string with the given index. | |
1084 */ | |
1085 static void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1086 free_menu_string(vimmenu_T *menu, int idx) |
7 | 1087 { |
1088 int count = 0; | |
1089 int i; | |
1090 | |
1091 for (i = 0; i < MENU_MODES; i++) | |
1092 if (menu->strings[i] == menu->strings[idx]) | |
1093 count++; | |
1094 if (count == 1) | |
1095 vim_free(menu->strings[idx]); | |
1096 menu->strings[idx] = NULL; | |
1097 } | |
1098 | |
1099 /* | |
1100 * Show the mapping associated with a menu item or hierarchy in a sub-menu. | |
1101 */ | |
1102 static int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1103 show_menus(char_u *path_name, int modes) |
7 | 1104 { |
1105 char_u *p; | |
1106 char_u *name; | |
1107 vimmenu_T *menu; | |
1108 vimmenu_T *parent = NULL; | |
1109 | |
1110 name = path_name = vim_strsave(path_name); | |
1111 if (path_name == NULL) | |
1112 return FAIL; | |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1113 menu = *get_root_menu(path_name); |
7 | 1114 |
1115 /* First, find the (sub)menu with the given name */ | |
1116 while (*name) | |
1117 { | |
1118 p = menu_name_skip(name); | |
1119 while (menu != NULL) | |
1120 { | |
1121 if (menu_name_equal(name, menu)) | |
1122 { | |
1123 /* Found menu */ | |
1124 if (*p != NUL && menu->children == NULL) | |
1125 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15375
diff
changeset
|
1126 emsg(_(e_notsubmenu)); |
7 | 1127 vim_free(path_name); |
1128 return FAIL; | |
1129 } | |
1130 else if ((menu->modes & modes) == 0x0) | |
1131 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15375
diff
changeset
|
1132 emsg(_(e_menuothermode)); |
7 | 1133 vim_free(path_name); |
1134 return FAIL; | |
1135 } | |
1136 break; | |
1137 } | |
1138 menu = menu->next; | |
1139 } | |
1140 if (menu == NULL) | |
1141 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15375
diff
changeset
|
1142 semsg(_(e_nomenu), name); |
7 | 1143 vim_free(path_name); |
1144 return FAIL; | |
1145 } | |
1146 name = p; | |
1147 parent = menu; | |
1148 menu = menu->children; | |
1149 } | |
1704 | 1150 vim_free(path_name); |
7 | 1151 |
1152 /* Now we have found the matching menu, and we list the mappings */ | |
1153 /* Highlight title */ | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
1154 msg_puts_title(_("\n--- Menus ---")); |
7 | 1155 |
1156 show_menus_recursive(parent, modes, 0); | |
1157 return OK; | |
1158 } | |
1159 | |
1160 /* | |
1161 * Recursively show the mappings associated with the menus under the given one | |
1162 */ | |
1163 static void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1164 show_menus_recursive(vimmenu_T *menu, int modes, int depth) |
7 | 1165 { |
1166 int i; | |
1167 int bit; | |
1168 | |
1169 if (menu != NULL && (menu->modes & modes) == 0x0) | |
1170 return; | |
1171 | |
1172 if (menu != NULL) | |
1173 { | |
1174 msg_putchar('\n'); | |
1175 if (got_int) /* "q" hit for "--more--" */ | |
1176 return; | |
1177 for (i = 0; i < depth; i++) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
1178 msg_puts(" "); |
7 | 1179 if (menu->priority) |
1180 { | |
1181 msg_outnum((long)menu->priority); | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
1182 msg_puts(" "); |
7 | 1183 } |
1184 /* Same highlighting as for directories!? */ | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
1185 msg_outtrans_attr(menu->name, HL_ATTR(HLF_D)); |
7 | 1186 } |
1187 | |
1188 if (menu != NULL && menu->children == NULL) | |
1189 { | |
1190 for (bit = 0; bit < MENU_MODES; bit++) | |
1191 if ((menu->modes & modes & (1 << bit)) != 0) | |
1192 { | |
1193 msg_putchar('\n'); | |
1194 if (got_int) /* "q" hit for "--more--" */ | |
1195 return; | |
1196 for (i = 0; i < depth + 2; i++) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
1197 msg_puts(" "); |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
1198 msg_puts(menu_mode_chars[bit]); |
7 | 1199 if (menu->noremap[bit] == REMAP_NONE) |
1200 msg_putchar('*'); | |
1201 else if (menu->noremap[bit] == REMAP_SCRIPT) | |
1202 msg_putchar('&'); | |
1203 else | |
1204 msg_putchar(' '); | |
1205 if (menu->silent[bit]) | |
1206 msg_putchar('s'); | |
1207 else | |
1208 msg_putchar(' '); | |
1209 if ((menu->modes & menu->enabled & (1 << bit)) == 0) | |
1210 msg_putchar('-'); | |
1211 else | |
1212 msg_putchar(' '); | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
1213 msg_puts(" "); |
7 | 1214 if (*menu->strings[bit] == NUL) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
1215 msg_puts_attr("<Nop>", HL_ATTR(HLF_8)); |
7 | 1216 else |
16393
c1c25e2523a6
patch 8.1.1201: output of :command is hard to read
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
1217 msg_outtrans_special(menu->strings[bit], FALSE, 0); |
7 | 1218 } |
1219 } | |
1220 else | |
1221 { | |
1222 if (menu == NULL) | |
1223 { | |
1224 menu = root_menu; | |
1225 depth--; | |
1226 } | |
1227 else | |
1228 menu = menu->children; | |
1229 | |
1230 /* recursively show all children. Skip PopUp[nvoci]. */ | |
1231 for (; menu != NULL && !got_int; menu = menu->next) | |
1232 if (!menu_is_hidden(menu->dname)) | |
1233 show_menus_recursive(menu, modes, depth + 1); | |
1234 } | |
1235 } | |
1236 | |
1237 /* | |
1238 * Used when expanding menu names. | |
1239 */ | |
1240 static vimmenu_T *expand_menu = NULL; | |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1241 static vimmenu_T *expand_menu_alt = NULL; |
7 | 1242 static int expand_modes = 0x0; |
1243 static int expand_emenu; /* TRUE for ":emenu" command */ | |
1244 | |
1245 /* | |
1246 * Work out what to complete when doing command line completion of menu names. | |
1247 */ | |
1248 char_u * | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1249 set_context_in_menu_cmd( |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1250 expand_T *xp, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1251 char_u *cmd, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1252 char_u *arg, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1253 int forceit) |
7 | 1254 { |
1255 char_u *after_dot; | |
1256 char_u *p; | |
1257 char_u *path_name = NULL; | |
1258 char_u *name; | |
1259 int unmenu; | |
1260 vimmenu_T *menu; | |
1261 int expand_menus; | |
1262 | |
1263 xp->xp_context = EXPAND_UNSUCCESSFUL; | |
1264 | |
1265 | |
1266 /* Check for priority numbers, enable and disable */ | |
1267 for (p = arg; *p; ++p) | |
1268 if (!VIM_ISDIGIT(*p) && *p != '.') | |
1269 break; | |
1270 | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
1271 if (!VIM_ISWHITE(*p)) |
7 | 1272 { |
1273 if (STRNCMP(arg, "enable", 6) == 0 | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
1274 && (arg[6] == NUL || VIM_ISWHITE(arg[6]))) |
7 | 1275 p = arg + 6; |
1276 else if (STRNCMP(arg, "disable", 7) == 0 | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
1277 && (arg[7] == NUL || VIM_ISWHITE(arg[7]))) |
7 | 1278 p = arg + 7; |
1279 else | |
1280 p = arg; | |
1281 } | |
1282 | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
1283 while (*p != NUL && VIM_ISWHITE(*p)) |
7 | 1284 ++p; |
1285 | |
1286 arg = after_dot = p; | |
1287 | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
1288 for (; *p && !VIM_ISWHITE(*p); ++p) |
7 | 1289 { |
1290 if ((*p == '\\' || *p == Ctrl_V) && p[1] != NUL) | |
1291 p++; | |
1292 else if (*p == '.') | |
1293 after_dot = p + 1; | |
1294 } | |
1295 | |
1296 /* ":tearoff" and ":popup" only use menus, not entries */ | |
1297 expand_menus = !((*cmd == 't' && cmd[1] == 'e') || *cmd == 'p'); | |
1298 expand_emenu = (*cmd == 'e'); | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
1299 if (expand_menus && VIM_ISWHITE(*p)) |
7 | 1300 return NULL; /* TODO: check for next command? */ |
1301 if (*p == NUL) /* Complete the menu name */ | |
1302 { | |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1303 int try_alt_menu = TRUE; |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1304 |
7 | 1305 /* |
1306 * With :unmenu, you only want to match menus for the appropriate mode. | |
1307 * With :menu though you might want to add a menu with the same name as | |
1308 * one in another mode, so match menus from other modes too. | |
1309 */ | |
1310 expand_modes = get_menu_cmd_modes(cmd, forceit, NULL, &unmenu); | |
1311 if (!unmenu) | |
1312 expand_modes = MENU_ALL_MODES; | |
1313 | |
1314 menu = root_menu; | |
1315 if (after_dot != arg) | |
1316 { | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16541
diff
changeset
|
1317 path_name = alloc(after_dot - arg); |
7 | 1318 if (path_name == NULL) |
1319 return NULL; | |
419 | 1320 vim_strncpy(path_name, arg, after_dot - arg - 1); |
7 | 1321 } |
1322 name = path_name; | |
1323 while (name != NULL && *name) | |
1324 { | |
1325 p = menu_name_skip(name); | |
1326 while (menu != NULL) | |
1327 { | |
1328 if (menu_name_equal(name, menu)) | |
1329 { | |
1330 /* Found menu */ | |
1331 if ((*p != NUL && menu->children == NULL) | |
1332 || ((menu->modes & expand_modes) == 0x0)) | |
1333 { | |
1334 /* | |
1335 * Menu path continues, but we have reached a leaf. | |
1336 * Or menu exists only in another mode. | |
1337 */ | |
1338 vim_free(path_name); | |
1339 return NULL; | |
1340 } | |
1341 break; | |
1342 } | |
1343 menu = menu->next; | |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1344 if (menu == NULL && try_alt_menu) |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1345 { |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1346 menu = curwin->w_winbar; |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1347 try_alt_menu = FALSE; |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1348 } |
7 | 1349 } |
1350 if (menu == NULL) | |
1351 { | |
1352 /* No menu found with the name we were looking for */ | |
1353 vim_free(path_name); | |
1354 return NULL; | |
1355 } | |
1356 name = p; | |
1357 menu = menu->children; | |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1358 try_alt_menu = FALSE; |
7 | 1359 } |
840 | 1360 vim_free(path_name); |
7 | 1361 |
1362 xp->xp_context = expand_menus ? EXPAND_MENUNAMES : EXPAND_MENUS; | |
1363 xp->xp_pattern = after_dot; | |
1364 expand_menu = menu; | |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1365 if (expand_menu == root_menu) |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1366 expand_menu_alt = curwin->w_winbar; |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1367 else |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1368 expand_menu_alt = NULL; |
7 | 1369 } |
1370 else /* We're in the mapping part */ | |
1371 xp->xp_context = EXPAND_NOTHING; | |
1372 return NULL; | |
1373 } | |
1374 | |
1375 /* | |
1376 * Function given to ExpandGeneric() to obtain the list of (sub)menus (not | |
1377 * entries). | |
1378 */ | |
1379 char_u * | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1380 get_menu_name(expand_T *xp UNUSED, int idx) |
7 | 1381 { |
1382 static vimmenu_T *menu = NULL; | |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1383 static int did_alt_menu = FALSE; |
7 | 1384 char_u *str; |
2150
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1385 #ifdef FEAT_MULTI_LANG |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1386 static int should_advance = FALSE; |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1387 #endif |
7 | 1388 |
1389 if (idx == 0) /* first call: start at first item */ | |
2150
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1390 { |
7 | 1391 menu = expand_menu; |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1392 did_alt_menu = FALSE; |
2166 | 1393 #ifdef FEAT_MULTI_LANG |
2150
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1394 should_advance = FALSE; |
2166 | 1395 #endif |
2150
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1396 } |
7 | 1397 |
1398 /* Skip PopUp[nvoci]. */ | |
1399 while (menu != NULL && (menu_is_hidden(menu->dname) | |
1400 || menu_is_separator(menu->dname) | |
1401 || menu_is_tearoff(menu->dname) | |
1402 || menu->children == NULL)) | |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1403 { |
7 | 1404 menu = menu->next; |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1405 if (menu == NULL && !did_alt_menu) |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1406 { |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1407 menu = expand_menu_alt; |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1408 did_alt_menu = TRUE; |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1409 } |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1410 } |
7 | 1411 |
1412 if (menu == NULL) /* at end of linked list */ | |
1413 return NULL; | |
1414 | |
1415 if (menu->modes & expand_modes) | |
2150
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1416 #ifdef FEAT_MULTI_LANG |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1417 if (should_advance) |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1418 str = menu->en_dname; |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1419 else |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1420 { |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1421 #endif |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1422 str = menu->dname; |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1423 #ifdef FEAT_MULTI_LANG |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1424 if (menu->en_dname == NULL) |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
1425 should_advance = TRUE; |
2150
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1426 } |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1427 #endif |
7 | 1428 else |
1429 str = (char_u *)""; | |
1430 | |
2150
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1431 #ifdef FEAT_MULTI_LANG |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1432 if (should_advance) |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1433 #endif |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1434 { |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
1435 /* Advance to next menu entry. */ |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
1436 menu = menu->next; |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1437 if (menu == NULL && !did_alt_menu) |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1438 { |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1439 menu = expand_menu_alt; |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1440 did_alt_menu = TRUE; |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1441 } |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1442 } |
2150
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1443 |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1444 #ifdef FEAT_MULTI_LANG |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1445 should_advance = !should_advance; |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1446 #endif |
7 | 1447 |
1448 return str; | |
1449 } | |
1450 | |
1451 /* | |
1452 * Function given to ExpandGeneric() to obtain the list of menus and menu | |
1453 * entries. | |
1454 */ | |
1455 char_u * | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1456 get_menu_names(expand_T *xp UNUSED, int idx) |
7 | 1457 { |
1458 static vimmenu_T *menu = NULL; | |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1459 static int did_alt_menu = FALSE; |
2768 | 1460 #define TBUFFER_LEN 256 |
1461 static char_u tbuffer[TBUFFER_LEN]; /*hack*/ | |
7 | 1462 char_u *str; |
2150
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1463 #ifdef FEAT_MULTI_LANG |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1464 static int should_advance = FALSE; |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1465 #endif |
7 | 1466 |
1467 if (idx == 0) /* first call: start at first item */ | |
2150
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1468 { |
7 | 1469 menu = expand_menu; |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1470 did_alt_menu = FALSE; |
2166 | 1471 #ifdef FEAT_MULTI_LANG |
2150
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1472 should_advance = FALSE; |
2166 | 1473 #endif |
2150
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1474 } |
7 | 1475 |
1476 /* Skip Browse-style entries, popup menus and separators. */ | |
1477 while (menu != NULL | |
1478 && ( menu_is_hidden(menu->dname) | |
1479 || (expand_emenu && menu_is_separator(menu->dname)) | |
1480 || menu_is_tearoff(menu->dname) | |
1481 #ifndef FEAT_BROWSE | |
1482 || menu->dname[STRLEN(menu->dname) - 1] == '.' | |
1483 #endif | |
1484 )) | |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1485 { |
7 | 1486 menu = menu->next; |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1487 if (menu == NULL && !did_alt_menu) |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1488 { |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1489 menu = expand_menu_alt; |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1490 did_alt_menu = TRUE; |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1491 } |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1492 } |
7 | 1493 |
1494 if (menu == NULL) /* at end of linked list */ | |
1495 return NULL; | |
1496 | |
1497 if (menu->modes & expand_modes) | |
1498 { | |
1499 if (menu->children != NULL) | |
1500 { | |
2150
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1501 #ifdef FEAT_MULTI_LANG |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1502 if (should_advance) |
2768 | 1503 vim_strncpy(tbuffer, menu->en_dname, TBUFFER_LEN - 2); |
2150
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1504 else |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1505 { |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1506 #endif |
2768 | 1507 vim_strncpy(tbuffer, menu->dname, TBUFFER_LEN - 2); |
2150
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1508 #ifdef FEAT_MULTI_LANG |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1509 if (menu->en_dname == NULL) |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1510 should_advance = TRUE; |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1511 } |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1512 #endif |
7 | 1513 /* hack on menu separators: use a 'magic' char for the separator |
1514 * so that '.' in names gets escaped properly */ | |
1515 STRCAT(tbuffer, "\001"); | |
1516 str = tbuffer; | |
1517 } | |
1518 else | |
2150
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1519 #ifdef FEAT_MULTI_LANG |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
1520 { |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
1521 if (should_advance) |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
1522 str = menu->en_dname; |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
1523 else |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
1524 { |
2150
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1525 #endif |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
1526 str = menu->dname; |
2150
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1527 #ifdef FEAT_MULTI_LANG |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
1528 if (menu->en_dname == NULL) |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
1529 should_advance = TRUE; |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
1530 } |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
1531 } |
2150
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1532 #endif |
7 | 1533 } |
1534 else | |
1535 str = (char_u *)""; | |
1536 | |
2150
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1537 #ifdef FEAT_MULTI_LANG |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1538 if (should_advance) |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1539 #endif |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1540 { |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
1541 /* Advance to next menu entry. */ |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
1542 menu = menu->next; |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1543 if (menu == NULL && !did_alt_menu) |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1544 { |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1545 menu = expand_menu_alt; |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1546 did_alt_menu = TRUE; |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1547 } |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
1548 } |
2150
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1549 |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1550 #ifdef FEAT_MULTI_LANG |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1551 should_advance = !should_advance; |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1552 #endif |
7 | 1553 |
1554 return str; | |
1555 } | |
1556 | |
1557 /* | |
1558 * Skip over this element of the menu path and return the start of the next | |
1559 * element. Any \ and ^Vs are removed from the current element. | |
436 | 1560 * "name" may be modified. |
7 | 1561 */ |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
1562 static char_u * |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1563 menu_name_skip(char_u *name) |
7 | 1564 { |
1565 char_u *p; | |
1566 | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11044
diff
changeset
|
1567 for (p = name; *p && *p != '.'; MB_PTR_ADV(p)) |
7 | 1568 { |
1569 if (*p == '\\' || *p == Ctrl_V) | |
1570 { | |
1624 | 1571 STRMOVE(p, p + 1); |
7 | 1572 if (*p == NUL) |
1573 break; | |
1574 } | |
1575 } | |
1576 if (*p) | |
1577 *p++ = NUL; | |
1578 return p; | |
1579 } | |
1580 | |
1581 /* | |
1582 * Return TRUE when "name" matches with menu "menu". The name is compared in | |
1583 * two ways: raw menu name and menu name without '&'. ignore part after a TAB. | |
1584 */ | |
1585 static int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1586 menu_name_equal(char_u *name, vimmenu_T *menu) |
7 | 1587 { |
2166 | 1588 #ifdef FEAT_MULTI_LANG |
2150
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1589 if (menu->en_name != NULL |
2676 | 1590 && (menu_namecmp(name, menu->en_name) |
1591 || menu_namecmp(name, menu->en_dname))) | |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2251
diff
changeset
|
1592 return TRUE; |
2166 | 1593 #endif |
2150
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
1594 return menu_namecmp(name, menu->name) || menu_namecmp(name, menu->dname); |
7 | 1595 } |
1596 | |
1597 static int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1598 menu_namecmp(char_u *name, char_u *mname) |
7 | 1599 { |
1600 int i; | |
1601 | |
1602 for (i = 0; name[i] != NUL && name[i] != TAB; ++i) | |
1603 if (name[i] != mname[i]) | |
1604 break; | |
1605 return ((name[i] == NUL || name[i] == TAB) | |
1606 && (mname[i] == NUL || mname[i] == TAB)); | |
1607 } | |
1608 | |
1609 /* | |
1610 * Return the modes specified by the given menu command (eg :menu! returns | |
1611 * MENU_CMDLINE_MODE | MENU_INSERT_MODE). | |
1612 * If "noremap" is not NULL, then the flag it points to is set according to | |
1613 * whether the command is a "nore" command. | |
1614 * If "unmenu" is not NULL, then the flag it points to is set according to | |
1615 * whether the command is an "unmenu" command. | |
1616 */ | |
1617 static int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1618 get_menu_cmd_modes( |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1619 char_u *cmd, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1620 int forceit, /* Was there a "!" after the command? */ |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1621 int *noremap, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1622 int *unmenu) |
7 | 1623 { |
1624 int modes; | |
1625 | |
1626 switch (*cmd++) | |
1627 { | |
1628 case 'v': /* vmenu, vunmenu, vnoremenu */ | |
791 | 1629 modes = MENU_VISUAL_MODE | MENU_SELECT_MODE; |
1630 break; | |
1631 case 'x': /* xmenu, xunmenu, xnoremenu */ | |
7 | 1632 modes = MENU_VISUAL_MODE; |
1633 break; | |
791 | 1634 case 's': /* smenu, sunmenu, snoremenu */ |
1635 modes = MENU_SELECT_MODE; | |
1636 break; | |
7 | 1637 case 'o': /* omenu */ |
1638 modes = MENU_OP_PENDING_MODE; | |
1639 break; | |
1640 case 'i': /* imenu */ | |
1641 modes = MENU_INSERT_MODE; | |
1642 break; | |
1643 case 't': | |
14952
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
1644 if (*cmd == 'l') /* tlmenu, tlunmenu, tlnoremenu */ |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
1645 { |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
1646 modes = MENU_TERMINAL_MODE; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
1647 ++cmd; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
1648 break; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
1649 } |
7 | 1650 modes = MENU_TIP_MODE; /* tmenu */ |
1651 break; | |
1652 case 'c': /* cmenu */ | |
1653 modes = MENU_CMDLINE_MODE; | |
1654 break; | |
1655 case 'a': /* amenu */ | |
1656 modes = MENU_INSERT_MODE | MENU_CMDLINE_MODE | MENU_NORMAL_MODE | |
791 | 1657 | MENU_VISUAL_MODE | MENU_SELECT_MODE |
856 | 1658 | MENU_OP_PENDING_MODE; |
7 | 1659 break; |
1660 case 'n': | |
1661 if (*cmd != 'o') /* nmenu, not noremenu */ | |
1662 { | |
1663 modes = MENU_NORMAL_MODE; | |
1664 break; | |
1665 } | |
1666 /* FALLTHROUGH */ | |
1667 default: | |
1668 --cmd; | |
1669 if (forceit) /* menu!! */ | |
1670 modes = MENU_INSERT_MODE | MENU_CMDLINE_MODE; | |
1671 else /* menu */ | |
791 | 1672 modes = MENU_NORMAL_MODE | MENU_VISUAL_MODE | MENU_SELECT_MODE |
7 | 1673 | MENU_OP_PENDING_MODE; |
1674 } | |
1675 | |
1676 if (noremap != NULL) | |
1677 *noremap = (*cmd == 'n' ? REMAP_NONE : REMAP_YES); | |
1678 if (unmenu != NULL) | |
1679 *unmenu = (*cmd == 'u'); | |
1680 return modes; | |
1681 } | |
1682 | |
1683 /* | |
1684 * Modify a menu name starting with "PopUp" to include the mode character. | |
1685 * Returns the name in allocated memory (NULL for failure). | |
1686 */ | |
1687 static char_u * | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1688 popup_mode_name(char_u *name, int idx) |
7 | 1689 { |
1690 char_u *p; | |
1691 int len = (int)STRLEN(name); | |
14952
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
1692 char *mode_chars = menu_mode_chars[idx]; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
1693 int mode_chars_len = (int)strlen(mode_chars); |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
1694 int i; |
7 | 1695 |
14952
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
1696 p = vim_strnsave(name, len + mode_chars_len); |
7 | 1697 if (p != NULL) |
1698 { | |
14952
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
1699 mch_memmove(p + 5 + mode_chars_len, p + 5, (size_t)(len - 4)); |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
1700 for (i = 0; i < mode_chars_len; ++i) |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
1701 p[5 + i] = menu_mode_chars[idx][i]; |
7 | 1702 } |
1703 return p; | |
1704 } | |
1705 | |
1706 #if defined(FEAT_GUI) || defined(PROTO) | |
1707 /* | |
1708 * Return the index into the menu->strings or menu->noremap arrays for the | |
1709 * current state. Returns MENU_INDEX_INVALID if there is no mapping for the | |
1710 * given menu in the current mode. | |
1711 */ | |
1712 int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1713 get_menu_index(vimmenu_T *menu, int state) |
7 | 1714 { |
1715 int idx; | |
1716 | |
1717 if ((state & INSERT)) | |
1718 idx = MENU_INDEX_INSERT; | |
1719 else if (state & CMDLINE) | |
1720 idx = MENU_INDEX_CMDLINE; | |
14952
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
1721 #ifdef FEAT_TERMINAL |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
1722 else if (term_use_loop()) |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
1723 idx = MENU_INDEX_TERMINAL; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
1724 #endif |
7 | 1725 else if (VIsual_active) |
791 | 1726 { |
856 | 1727 if (VIsual_select) |
1728 idx = MENU_INDEX_SELECT; | |
1729 else | |
1730 idx = MENU_INDEX_VISUAL; | |
791 | 1731 } |
7 | 1732 else if (state == HITRETURN || state == ASKMORE) |
1733 idx = MENU_INDEX_CMDLINE; | |
1734 else if (finish_op) | |
1735 idx = MENU_INDEX_OP_PENDING; | |
1736 else if ((state & NORMAL)) | |
1737 idx = MENU_INDEX_NORMAL; | |
1738 else | |
1739 idx = MENU_INDEX_INVALID; | |
1740 | |
1741 if (idx != MENU_INDEX_INVALID && menu->strings[idx] == NULL) | |
1742 idx = MENU_INDEX_INVALID; | |
1743 return idx; | |
1744 } | |
1745 #endif | |
1746 | |
1747 /* | |
1748 * Duplicate the menu item text and then process to see if a mnemonic key | |
1749 * and/or accelerator text has been identified. | |
1750 * Returns a pointer to allocated memory, or NULL for failure. | |
1751 * If mnemonic != NULL, *mnemonic is set to the character after the first '&'. | |
1752 * If actext != NULL, *actext is set to the text after the first TAB. | |
1753 */ | |
1754 static char_u * | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1755 menu_text(char_u *str, int *mnemonic, char_u **actext) |
7 | 1756 { |
1757 char_u *p; | |
1758 char_u *text; | |
1759 | |
1760 /* Locate accelerator text, after the first TAB */ | |
1761 p = vim_strchr(str, TAB); | |
1762 if (p != NULL) | |
1763 { | |
1764 if (actext != NULL) | |
1765 *actext = vim_strsave(p + 1); | |
1766 text = vim_strnsave(str, (int)(p - str)); | |
1767 } | |
1768 else | |
1769 text = vim_strsave(str); | |
1770 | |
1771 /* Find mnemonic characters "&a" and reduce "&&" to "&". */ | |
1772 for (p = text; p != NULL; ) | |
1773 { | |
1774 p = vim_strchr(p, '&'); | |
1775 if (p != NULL) | |
1776 { | |
1777 if (p[1] == NUL) /* trailing "&" */ | |
1778 break; | |
1779 if (mnemonic != NULL && p[1] != '&') | |
1780 #if !defined(__MVS__) || defined(MOTIF390_MNEMONIC_FIXED) | |
1781 *mnemonic = p[1]; | |
1782 #else | |
1783 { | |
1784 /* | |
1785 * Well there is a bug in the Motif libraries on OS390 Unix. | |
1786 * The mnemonic keys needs to be converted to ASCII values | |
1787 * first. | |
1788 * This behavior has been seen in 2.8 and 2.9. | |
1789 */ | |
1790 char c = p[1]; | |
1791 __etoa_l(&c, 1); | |
1792 *mnemonic = c; | |
1793 } | |
1794 #endif | |
1624 | 1795 STRMOVE(p, p + 1); |
7 | 1796 p = p + 1; |
1797 } | |
1798 } | |
1799 return text; | |
1800 } | |
1801 | |
1802 /* | |
1803 * Return TRUE if "name" can be a menu in the MenuBar. | |
1804 */ | |
1805 int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1806 menu_is_menubar(char_u *name) |
7 | 1807 { |
1808 return (!menu_is_popup(name) | |
1809 && !menu_is_toolbar(name) | |
12527
259983a729fa
patch 8.0.1142: window toolbar menu gets a tear-off item
Christian Brabandt <cb@256bit.org>
parents:
12521
diff
changeset
|
1810 && !menu_is_winbar(name) |
7 | 1811 && *name != MNU_HIDDEN_CHAR); |
1812 } | |
1813 | |
1814 /* | |
1815 * Return TRUE if "name" is a popup menu name. | |
1816 */ | |
1817 int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1818 menu_is_popup(char_u *name) |
7 | 1819 { |
1820 return (STRNCMP(name, "PopUp", 5) == 0); | |
1821 } | |
1822 | |
1823 #if (defined(FEAT_GUI_MOTIF) && (XmVersion <= 1002)) || defined(PROTO) | |
1824 /* | |
1825 * Return TRUE if "name" is part of a popup menu. | |
1826 */ | |
1827 int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1828 menu_is_child_of_popup(vimmenu_T *menu) |
7 | 1829 { |
1830 while (menu->parent != NULL) | |
1831 menu = menu->parent; | |
1832 return menu_is_popup(menu->name); | |
1833 } | |
1834 #endif | |
1835 | |
1836 /* | |
1837 * Return TRUE if "name" is a toolbar menu name. | |
1838 */ | |
1839 int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1840 menu_is_toolbar(char_u *name) |
7 | 1841 { |
1842 return (STRNCMP(name, "ToolBar", 7) == 0); | |
1843 } | |
1844 | |
1845 /* | |
1846 * Return TRUE if the name is a menu separator identifier: Starts and ends | |
1847 * with '-' | |
1848 */ | |
1849 int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1850 menu_is_separator(char_u *name) |
7 | 1851 { |
1852 return (name[0] == '-' && name[STRLEN(name) - 1] == '-'); | |
1853 } | |
1854 | |
1855 /* | |
1856 * Return TRUE if the menu is hidden: Starts with ']' | |
1857 */ | |
1858 static int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1859 menu_is_hidden(char_u *name) |
7 | 1860 { |
1861 return (name[0] == ']') || (menu_is_popup(name) && name[5] != NUL); | |
1862 } | |
1863 | |
1864 /* | |
1865 * Return TRUE if the menu is the tearoff menu. | |
1866 */ | |
1867 static int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1868 menu_is_tearoff(char_u *name UNUSED) |
7 | 1869 { |
1870 #ifdef FEAT_GUI | |
1871 return (STRCMP(name, TEAR_STRING) == 0); | |
1872 #else | |
1873 return FALSE; | |
1874 #endif | |
1875 } | |
1876 | |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1877 #if defined(FEAT_GUI) || defined(FEAT_TERM_POPUP_MENU) || defined(PROTO) |
7 | 1878 |
1879 static int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1880 get_menu_mode(void) |
7 | 1881 { |
14952
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
1882 #ifdef FEAT_TERMINAL |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
1883 if (term_use_loop()) |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
1884 return MENU_INDEX_TERMINAL; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
1885 #endif |
7 | 1886 if (VIsual_active) |
791 | 1887 { |
856 | 1888 if (VIsual_select) |
1889 return MENU_INDEX_SELECT; | |
7 | 1890 return MENU_INDEX_VISUAL; |
791 | 1891 } |
7 | 1892 if (State & INSERT) |
1893 return MENU_INDEX_INSERT; | |
1894 if ((State & CMDLINE) || State == ASKMORE || State == HITRETURN) | |
1895 return MENU_INDEX_CMDLINE; | |
1896 if (finish_op) | |
1897 return MENU_INDEX_OP_PENDING; | |
1898 if (State & NORMAL) | |
1899 return MENU_INDEX_NORMAL; | |
1900 if (State & LANGMAP) /* must be a "r" command, like Insert mode */ | |
1901 return MENU_INDEX_INSERT; | |
1902 return MENU_INDEX_INVALID; | |
1903 } | |
1904 | |
13392
d5347779fb20
patch 8.0.1570: can't use :popup for a menu in the terminal
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1905 int |
d5347779fb20
patch 8.0.1570: can't use :popup for a menu in the terminal
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1906 get_menu_mode_flag(void) |
d5347779fb20
patch 8.0.1570: can't use :popup for a menu in the terminal
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1907 { |
d5347779fb20
patch 8.0.1570: can't use :popup for a menu in the terminal
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1908 int mode = get_menu_mode(); |
d5347779fb20
patch 8.0.1570: can't use :popup for a menu in the terminal
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1909 |
d5347779fb20
patch 8.0.1570: can't use :popup for a menu in the terminal
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1910 if (mode == MENU_INDEX_INVALID) |
d5347779fb20
patch 8.0.1570: can't use :popup for a menu in the terminal
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1911 return 0; |
d5347779fb20
patch 8.0.1570: can't use :popup for a menu in the terminal
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1912 return 1 << mode; |
d5347779fb20
patch 8.0.1570: can't use :popup for a menu in the terminal
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1913 } |
d5347779fb20
patch 8.0.1570: can't use :popup for a menu in the terminal
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1914 |
7 | 1915 /* |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1916 * Display the Special "PopUp" menu as a pop-up at the current mouse |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1917 * position. The "PopUpn" menu is for Normal mode, "PopUpi" for Insert mode, |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1918 * etc. |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1919 */ |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1920 void |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1921 show_popupmenu(void) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1922 { |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1923 vimmenu_T *menu; |
14952
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
1924 int menu_mode; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
1925 char* mode; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
1926 int mode_len; |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1927 |
14952
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
1928 menu_mode = get_menu_mode(); |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
1929 if (menu_mode == MENU_INDEX_INVALID) |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
1930 return; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
1931 mode = menu_mode_chars[menu_mode]; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
1932 mode_len = (int)strlen(mode); |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1933 |
14952
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
1934 apply_autocmds(EVENT_MENUPOPUP, (char_u*)mode, NULL, FALSE, curbuf); |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1935 |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1936 for (menu = root_menu; menu != NULL; menu = menu->next) |
14952
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
1937 if (STRNCMP("PopUp", menu->name, 5) == 0 && STRNCMP(menu->name + 5, mode, mode_len) == 0) |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1938 break; |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1939 |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1940 /* Only show a popup when it is defined and has entries */ |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1941 if (menu != NULL && menu->children != NULL) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1942 { |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1943 # if defined(FEAT_GUI) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1944 if (gui.in_use) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1945 { |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1946 /* Update the menus now, in case the MenuPopup autocommand did |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1947 * anything. */ |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1948 gui_update_menus(0); |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1949 gui_mch_show_popupmenu(menu); |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1950 } |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1951 # endif |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1952 # if defined(FEAT_GUI) && defined(FEAT_TERM_POPUP_MENU) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1953 else |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1954 # endif |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1955 # if defined(FEAT_TERM_POPUP_MENU) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1956 pum_show_popupmenu(menu); |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1957 # endif |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1958 } |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1959 } |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1960 #endif |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1961 |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1962 #if defined(FEAT_GUI) || defined(PROTO) |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1963 |
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1964 /* |
936 | 1965 * Check that a pointer appears in the menu tree. Used to protect from using |
1966 * a menu that was deleted after it was selected but before the event was | |
1967 * handled. | |
1968 * Return OK or FAIL. Used recursively. | |
1969 */ | |
1970 int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1971 check_menu_pointer(vimmenu_T *root, vimmenu_T *menu_to_check) |
936 | 1972 { |
1973 vimmenu_T *p; | |
1974 | |
1975 for (p = root; p != NULL; p = p->next) | |
1976 if (p == menu_to_check | |
1977 || (p->children != NULL | |
1978 && check_menu_pointer(p->children, menu_to_check) == OK)) | |
1979 return OK; | |
1980 return FAIL; | |
1981 } | |
1982 | |
1983 /* | |
7 | 1984 * After we have started the GUI, then we can create any menus that have been |
1985 * defined. This is done once here. add_menu_path() may have already been | |
1986 * called to define these menus, and may be called again. This function calls | |
1987 * itself recursively. Should be called at the top level with: | |
9536
b2aada04d84e
commit https://github.com/vim/vim/commit/a06ecab7a5159e744448ace731036f0dc5f87dd4
Christian Brabandt <cb@256bit.org>
parents:
9264
diff
changeset
|
1988 * gui_create_initial_menus(root_menu); |
7 | 1989 */ |
1990 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1991 gui_create_initial_menus(vimmenu_T *menu) |
7 | 1992 { |
1993 int idx = 0; | |
1994 | |
1995 while (menu != NULL) | |
1996 { | |
1997 /* Don't add a menu when only a tip was defined. */ | |
1998 if (menu->modes & MENU_ALL_MODES) | |
1999 { | |
2000 if (menu->children != NULL) | |
2001 { | |
2002 gui_mch_add_menu(menu, idx); | |
2003 gui_create_initial_menus(menu->children); | |
2004 } | |
2005 else | |
2006 gui_mch_add_menu_item(menu, idx); | |
2007 } | |
2008 menu = menu->next; | |
2009 ++idx; | |
2010 } | |
2011 } | |
2012 | |
2013 /* | |
2014 * Used recursively by gui_update_menus (see below) | |
2015 */ | |
2016 static void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2017 gui_update_menus_recurse(vimmenu_T *menu, int mode) |
7 | 2018 { |
2019 int grey; | |
2020 | |
2021 while (menu) | |
2022 { | |
2023 if ((menu->modes & menu->enabled & mode) | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
2024 # if defined(FEAT_GUI_MSWIN) && defined(FEAT_TEAROFF) |
7 | 2025 || menu_is_tearoff(menu->dname) |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
2026 # endif |
7 | 2027 ) |
2028 grey = FALSE; | |
2029 else | |
2030 grey = TRUE; | |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
2031 # ifdef FEAT_GUI_ATHENA |
7 | 2032 /* Hiding menus doesn't work for Athena, it can cause a crash. */ |
2033 gui_mch_menu_grey(menu, grey); | |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
2034 # else |
7 | 2035 /* Never hide a toplevel menu, it may make the menubar resize or |
2036 * disappear. Same problem for ToolBar items. */ | |
2037 if (vim_strchr(p_go, GO_GREY) != NULL || menu->parent == NULL | |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
2038 # ifdef FEAT_TOOLBAR |
7 | 2039 || menu_is_toolbar(menu->parent->name) |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
2040 # endif |
7 | 2041 ) |
2042 gui_mch_menu_grey(menu, grey); | |
2043 else | |
2044 gui_mch_menu_hidden(menu, grey); | |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
2045 # endif |
7 | 2046 gui_update_menus_recurse(menu->children, mode); |
2047 menu = menu->next; | |
2048 } | |
2049 } | |
2050 | |
2051 /* | |
2052 * Make sure only the valid menu items appear for this mode. If | |
2053 * force_menu_update is not TRUE, then we only do this if the mode has changed | |
2054 * since last time. If "modes" is not 0, then we use these modes instead. | |
2055 */ | |
2056 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2057 gui_update_menus(int modes) |
7 | 2058 { |
2059 static int prev_mode = -1; | |
2060 int mode = 0; | |
2061 | |
2062 if (modes != 0x0) | |
2063 mode = modes; | |
2064 else | |
13392
d5347779fb20
patch 8.0.1570: can't use :popup for a menu in the terminal
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
2065 mode = get_menu_mode_flag(); |
7 | 2066 |
2067 if (force_menu_update || mode != prev_mode) | |
2068 { | |
2069 gui_update_menus_recurse(root_menu, mode); | |
2070 gui_mch_draw_menubar(); | |
2071 prev_mode = mode; | |
2072 force_menu_update = FALSE; | |
2073 } | |
2074 } | |
2075 | |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
2076 # if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_MOTIF) \ |
575 | 2077 || defined(FEAT_GUI_GTK) || defined(FEAT_GUI_PHOTON) || defined(PROTO) |
7 | 2078 /* |
2079 * Check if a key is used as a mnemonic for a toplevel menu. | |
2080 * Case of the key is ignored. | |
2081 */ | |
2082 int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2083 gui_is_menu_shortcut(int key) |
7 | 2084 { |
2085 vimmenu_T *menu; | |
2086 | |
2087 if (key < 256) | |
2088 key = TOLOWER_LOC(key); | |
2089 for (menu = root_menu; menu != NULL; menu = menu->next) | |
2090 if (menu->mnemonic == key | |
2091 || (menu->mnemonic < 256 && TOLOWER_LOC(menu->mnemonic) == key)) | |
2092 return TRUE; | |
2093 return FALSE; | |
2094 } | |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
2095 # endif |
7 | 2096 #endif /* FEAT_GUI */ |
2097 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
2098 #if (defined(FEAT_GUI_MSWIN) && defined(FEAT_TEAROFF)) || defined(PROTO) |
7 | 2099 |
2100 /* | |
2101 * Deal with tearoff items that are added like a menu item. | |
2102 * Currently only for Win32 GUI. Others may follow later. | |
2103 */ | |
2104 | |
2105 void | |
2106 gui_mch_toggle_tearoffs(int enable) | |
2107 { | |
2108 int pri_tab[MENUDEPTH + 1]; | |
2109 int i; | |
2110 | |
2111 if (enable) | |
2112 { | |
2113 for (i = 0; i < MENUDEPTH; ++i) | |
2114 pri_tab[i] = 500; | |
2115 pri_tab[MENUDEPTH] = -1; | |
2116 gui_create_tearoffs_recurse(root_menu, (char_u *)"", pri_tab, 0); | |
2117 } | |
2118 else | |
2119 gui_destroy_tearoffs_recurse(root_menu); | |
2120 s_tearoffs = enable; | |
2121 } | |
2122 | |
2123 /* | |
2124 * Recursively add tearoff items | |
2125 */ | |
2126 static void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2127 gui_create_tearoffs_recurse( |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2128 vimmenu_T *menu, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2129 const char_u *pname, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2130 int *pri_tab, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2131 int pri_idx) |
7 | 2132 { |
2133 char_u *newpname = NULL; | |
2134 int len; | |
2135 char_u *s; | |
2136 char_u *d; | |
2137 | |
2138 if (pri_tab[pri_idx + 1] != -1) | |
2139 ++pri_idx; | |
2140 while (menu != NULL) | |
2141 { | |
2142 if (menu->children != NULL && menu_is_menubar(menu->name)) | |
2143 { | |
2144 /* Add the menu name to the menu path. Insert a backslash before | |
2145 * dots (it's used to separate menu names). */ | |
2146 len = (int)STRLEN(pname) + (int)STRLEN(menu->name); | |
2147 for (s = menu->name; *s; ++s) | |
2148 if (*s == '.' || *s == '\\') | |
2149 ++len; | |
2150 newpname = alloc(len + TEAR_LEN + 2); | |
2151 if (newpname != NULL) | |
2152 { | |
2153 STRCPY(newpname, pname); | |
2154 d = newpname + STRLEN(newpname); | |
2155 for (s = menu->name; *s; ++s) | |
2156 { | |
2157 if (*s == '.' || *s == '\\') | |
2158 *d++ = '\\'; | |
2159 *d++ = *s; | |
2160 } | |
2161 *d = NUL; | |
2162 | |
2163 /* check if tearoff already exists */ | |
2164 if (STRCMP(menu->children->name, TEAR_STRING) != 0) | |
2165 { | |
2166 gui_add_tearoff(newpname, pri_tab, pri_idx - 1); | |
2167 *d = NUL; /* remove TEAR_STRING */ | |
2168 } | |
2169 | |
2170 STRCAT(newpname, "."); | |
2171 gui_create_tearoffs_recurse(menu->children, newpname, | |
2172 pri_tab, pri_idx); | |
2173 vim_free(newpname); | |
2174 } | |
2175 } | |
2176 menu = menu->next; | |
2177 } | |
2178 } | |
2179 | |
2180 /* | |
2181 * Add tear-off menu item for a submenu. | |
2182 * "tearpath" is the menu path, and must have room to add TEAR_STRING. | |
2183 */ | |
2184 static void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2185 gui_add_tearoff(char_u *tearpath, int *pri_tab, int pri_idx) |
7 | 2186 { |
2187 char_u *tbuf; | |
2188 int t; | |
2189 vimmenu_T menuarg; | |
2190 | |
2191 tbuf = alloc(5 + (unsigned int)STRLEN(tearpath)); | |
2192 if (tbuf != NULL) | |
2193 { | |
2194 tbuf[0] = K_SPECIAL; | |
2195 tbuf[1] = K_SECOND(K_TEAROFF); | |
2196 tbuf[2] = K_THIRD(K_TEAROFF); | |
2197 STRCPY(tbuf + 3, tearpath); | |
2198 STRCAT(tbuf + 3, "\r"); | |
2199 | |
2200 STRCAT(tearpath, "."); | |
2201 STRCAT(tearpath, TEAR_STRING); | |
2202 | |
2203 /* Priority of tear-off is always 1 */ | |
2204 t = pri_tab[pri_idx + 1]; | |
2205 pri_tab[pri_idx + 1] = 1; | |
2206 | |
2207 #ifdef FEAT_TOOLBAR | |
2208 menuarg.iconfile = NULL; | |
2209 menuarg.iconidx = -1; | |
2210 menuarg.icon_builtin = FALSE; | |
2211 #endif | |
2212 menuarg.noremap[0] = REMAP_NONE; | |
2213 menuarg.silent[0] = TRUE; | |
2214 | |
2215 menuarg.modes = MENU_ALL_MODES; | |
2216 add_menu_path(tearpath, &menuarg, pri_tab, tbuf, FALSE); | |
2217 | |
2218 menuarg.modes = MENU_TIP_MODE; | |
2219 add_menu_path(tearpath, &menuarg, pri_tab, | |
2220 (char_u *)_("Tear off this menu"), FALSE); | |
2221 | |
2222 pri_tab[pri_idx + 1] = t; | |
2223 vim_free(tbuf); | |
2224 } | |
2225 } | |
2226 | |
2227 /* | |
2228 * Recursively destroy tearoff items | |
2229 */ | |
2230 static void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2231 gui_destroy_tearoffs_recurse(vimmenu_T *menu) |
7 | 2232 { |
2233 while (menu) | |
2234 { | |
2235 if (menu->children) | |
2236 { | |
2237 /* check if tearoff exists */ | |
2238 if (STRCMP(menu->children->name, TEAR_STRING) == 0) | |
2239 { | |
2240 /* Disconnect the item and free the memory */ | |
2241 free_menu(&menu->children); | |
2242 } | |
2243 if (menu->children != NULL) /* if not the last one */ | |
2244 gui_destroy_tearoffs_recurse(menu->children); | |
2245 } | |
2246 menu = menu->next; | |
2247 } | |
2248 } | |
2249 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
2250 #endif /* FEAT_GUI_MSWIN && FEAT_TEAROFF */ |
7 | 2251 |
2252 /* | |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2253 * Execute "menu". Use by ":emenu" and the window toolbar. |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2254 * "eap" is NULL for the window toolbar. |
14952
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2255 * "mode_idx" specifies a MENU_INDEX_ value, use -1 to depend on the current |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2256 * state. |
7 | 2257 */ |
13369
244ff1b6d2ad
patch 8.0.1558: no right-click menu in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
2258 void |
14952
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2259 execute_menu(exarg_T *eap, vimmenu_T *menu, int mode_idx) |
7 | 2260 { |
14952
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2261 int idx = mode_idx; |
7 | 2262 |
14952
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2263 if (idx < 0) |
7 | 2264 { |
14952
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2265 /* Use the Insert mode entry when returning to Insert mode. */ |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2266 if (restart_edit |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2267 #ifdef FEAT_EVAL |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2268 && !current_sctx.sc_sid |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2269 #endif |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2270 ) |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2271 { |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2272 idx = MENU_INDEX_INSERT; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2273 } |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2274 #ifdef FEAT_TERMINAL |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2275 else if (term_use_loop()) |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2276 { |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2277 idx = MENU_INDEX_TERMINAL; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2278 } |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2279 #endif |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2280 else if (VIsual_active) |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2281 { |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2282 idx = MENU_INDEX_VISUAL; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2283 } |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2284 else if (eap != NULL && eap->addr_count) |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2285 { |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2286 pos_T tpos; |
7 | 2287 |
14952
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2288 idx = MENU_INDEX_VISUAL; |
7 | 2289 |
14952
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2290 /* GEDDES: This is not perfect - but it is a |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2291 * quick way of detecting whether we are doing this from a |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2292 * selection - see if the range matches up with the visual |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2293 * select start and end. */ |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2294 if ((curbuf->b_visual.vi_start.lnum == eap->line1) |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2295 && (curbuf->b_visual.vi_end.lnum) == eap->line2) |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2296 { |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2297 /* Set it up for visual mode - equivalent to gv. */ |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2298 VIsual_mode = curbuf->b_visual.vi_mode; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2299 tpos = curbuf->b_visual.vi_end; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2300 curwin->w_cursor = curbuf->b_visual.vi_start; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2301 curwin->w_curswant = curbuf->b_visual.vi_curswant; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2302 } |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2303 else |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2304 { |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2305 /* Set it up for line-wise visual mode */ |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2306 VIsual_mode = 'V'; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2307 curwin->w_cursor.lnum = eap->line1; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2308 curwin->w_cursor.col = 1; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2309 tpos.lnum = eap->line2; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2310 tpos.col = MAXCOL; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2311 tpos.coladd = 0; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2312 } |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2313 |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2314 /* Activate visual mode */ |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2315 VIsual_active = TRUE; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2316 VIsual_reselect = TRUE; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2317 check_cursor(); |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2318 VIsual = curwin->w_cursor; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2319 curwin->w_cursor = tpos; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2320 |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2321 check_cursor(); |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2322 |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2323 /* Adjust the cursor to make sure it is in the correct pos |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2324 * for exclusive mode */ |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2325 if (*p_sel == 'e' && gchar_cursor() != NUL) |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2326 ++curwin->w_cursor.col; |
7 | 2327 } |
2328 } | |
12521
718787498836
patch 8.0.1139: using window toolbar changes state
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
2329 |
718787498836
patch 8.0.1139: using window toolbar changes state
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
2330 /* For the WinBar menu always use the Normal mode menu. */ |
718787498836
patch 8.0.1139: using window toolbar changes state
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
2331 if (idx == -1 || eap == NULL) |
7 | 2332 idx = MENU_INDEX_NORMAL; |
2333 | |
16541
822d00007b34
patch 8.1.1274: after :unmenu can still execute the menu with :emenu
Bram Moolenaar <Bram@vim.org>
parents:
16521
diff
changeset
|
2334 if (idx != MENU_INDEX_INVALID && menu->strings[idx] != NULL |
822d00007b34
patch 8.1.1274: after :unmenu can still execute the menu with :emenu
Bram Moolenaar <Bram@vim.org>
parents:
16521
diff
changeset
|
2335 && (menu->modes & (1 << idx))) |
7 | 2336 { |
36 | 2337 /* When executing a script or function execute the commands right now. |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2338 * Also for the window toolbar. |
36 | 2339 * Otherwise put them in the typeahead buffer. */ |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2340 if (eap == NULL |
1050 | 2341 #ifdef FEAT_EVAL |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
13394
diff
changeset
|
2342 || current_sctx.sc_sid != 0 |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2343 #endif |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2344 ) |
12521
718787498836
patch 8.0.1139: using window toolbar changes state
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
2345 { |
718787498836
patch 8.0.1139: using window toolbar changes state
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
2346 save_state_T save_state; |
718787498836
patch 8.0.1139: using window toolbar changes state
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
2347 |
718787498836
patch 8.0.1139: using window toolbar changes state
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
2348 ++ex_normal_busy; |
718787498836
patch 8.0.1139: using window toolbar changes state
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
2349 if (save_current_state(&save_state)) |
718787498836
patch 8.0.1139: using window toolbar changes state
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
2350 exec_normal_cmd(menu->strings[idx], menu->noremap[idx], |
36 | 2351 menu->silent[idx]); |
12521
718787498836
patch 8.0.1139: using window toolbar changes state
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
2352 restore_current_state(&save_state); |
718787498836
patch 8.0.1139: using window toolbar changes state
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
2353 --ex_normal_busy; |
718787498836
patch 8.0.1139: using window toolbar changes state
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
2354 } |
36 | 2355 else |
2356 ins_typebuf(menu->strings[idx], menu->noremap[idx], 0, | |
7 | 2357 TRUE, menu->silent[idx]); |
2358 } | |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2359 else if (eap != NULL) |
14952
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2360 { |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2361 char_u *mode; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2362 |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2363 switch (idx) |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2364 { |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2365 case MENU_INDEX_VISUAL: |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2366 mode = (char_u *)"Visual"; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2367 break; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2368 case MENU_INDEX_SELECT: |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2369 mode = (char_u *)"Select"; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2370 break; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2371 case MENU_INDEX_OP_PENDING: |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2372 mode = (char_u *)"Op-pending"; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2373 break; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2374 case MENU_INDEX_TERMINAL: |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2375 mode = (char_u *)"Terminal"; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2376 break; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2377 case MENU_INDEX_INSERT: |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2378 mode = (char_u *)"Insert"; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2379 break; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2380 case MENU_INDEX_CMDLINE: |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2381 mode = (char_u *)"Cmdline"; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2382 break; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2383 // case MENU_INDEX_TIP: cannot happen |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2384 default: |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2385 mode = (char_u *)"Normal"; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2386 } |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15375
diff
changeset
|
2387 semsg(_("E335: Menu not defined for %s mode"), mode); |
14952
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2388 } |
7 | 2389 } |
2390 | |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2391 /* |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2392 * Given a menu descriptor, e.g. "File.New", find it in the menu hierarchy and |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2393 * execute it. |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2394 */ |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2395 void |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2396 ex_emenu(exarg_T *eap) |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2397 { |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2398 vimmenu_T *menu; |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2399 char_u *name; |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2400 char_u *saved_name; |
14952
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2401 char_u *arg = eap->arg; |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2402 char_u *p; |
14952
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2403 int gave_emsg = FALSE; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2404 int mode_idx = -1; |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2405 |
14952
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2406 if (arg[0] && VIM_ISWHITE(arg[1])) |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2407 { |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2408 switch (arg[0]) |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2409 { |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2410 case 'n': mode_idx = MENU_INDEX_NORMAL; break; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2411 case 'v': mode_idx = MENU_INDEX_VISUAL; break; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2412 case 's': mode_idx = MENU_INDEX_SELECT; break; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2413 case 'o': mode_idx = MENU_INDEX_OP_PENDING; break; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2414 case 't': mode_idx = MENU_INDEX_TERMINAL; break; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2415 case 'i': mode_idx = MENU_INDEX_INSERT; break; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2416 case 'c': mode_idx = MENU_INDEX_CMDLINE; break; |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15375
diff
changeset
|
2417 default: semsg(_(e_invarg2), arg); |
14952
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2418 return; |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2419 } |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2420 arg = skipwhite(arg + 2); |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2421 } |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2422 |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2423 saved_name = vim_strsave(arg); |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2424 if (saved_name == NULL) |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2425 return; |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2426 |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2427 menu = *get_root_menu(saved_name); |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2428 name = saved_name; |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2429 while (*name) |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2430 { |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2431 /* Find in the menu hierarchy */ |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2432 p = menu_name_skip(name); |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2433 |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2434 while (menu != NULL) |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2435 { |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2436 if (menu_name_equal(name, menu)) |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2437 { |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2438 if (*p == NUL && menu->children != NULL) |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2439 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15375
diff
changeset
|
2440 emsg(_("E333: Menu path must lead to a menu item")); |
14952
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2441 gave_emsg = TRUE; |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2442 menu = NULL; |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2443 } |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2444 else if (*p != NUL && menu->children == NULL) |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2445 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15375
diff
changeset
|
2446 emsg(_(e_notsubmenu)); |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2447 menu = NULL; |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2448 } |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2449 break; |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2450 } |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2451 menu = menu->next; |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2452 } |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2453 if (menu == NULL || *p == NUL) |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2454 break; |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2455 menu = menu->children; |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2456 name = p; |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2457 } |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2458 vim_free(saved_name); |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2459 if (menu == NULL) |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2460 { |
14952
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2461 if (!gave_emsg) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15375
diff
changeset
|
2462 semsg(_("E334: Menu not found: %s"), arg); |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2463 return; |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2464 } |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2465 |
14952
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2466 // Found the menu, so execute. |
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2467 execute_menu(eap, menu, mode_idx); |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2468 } |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2469 |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2470 /* |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2471 * Handle a click in the window toolbar of "wp" at column "col". |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2472 */ |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2473 void |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2474 winbar_click(win_T *wp, int col) |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2475 { |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2476 int idx; |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2477 |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2478 if (wp->w_winbar_items == NULL) |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2479 return; |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2480 for (idx = 0; wp->w_winbar_items[idx].wb_menu != NULL; ++idx) |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2481 { |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2482 winbar_item_T *item = &wp->w_winbar_items[idx]; |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2483 |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2484 if (col >= item->wb_startcol && col <= item->wb_endcol) |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2485 { |
16521
a7299d144bb9
patch 8.1.1264: crash when closing window from WinBar click
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2486 win_T *save_curwin = NULL; |
12521
718787498836
patch 8.0.1139: using window toolbar changes state
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
2487 pos_T save_visual = VIsual; |
718787498836
patch 8.0.1139: using window toolbar changes state
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
2488 int save_visual_active = VIsual_active; |
718787498836
patch 8.0.1139: using window toolbar changes state
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
2489 int save_visual_select = VIsual_select; |
718787498836
patch 8.0.1139: using window toolbar changes state
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
2490 int save_visual_reselect = VIsual_reselect; |
718787498836
patch 8.0.1139: using window toolbar changes state
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
2491 int save_visual_mode = VIsual_mode; |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2492 |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2493 if (wp != curwin) |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2494 { |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2495 /* Clicking in the window toolbar of a not-current window. |
12521
718787498836
patch 8.0.1139: using window toolbar changes state
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
2496 * Make that window the current one and save Visual mode. */ |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2497 save_curwin = curwin; |
12521
718787498836
patch 8.0.1139: using window toolbar changes state
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
2498 VIsual_active = FALSE; |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2499 curwin = wp; |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2500 curbuf = curwin->w_buffer; |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2501 check_cursor(); |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2502 } |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2503 |
16521
a7299d144bb9
patch 8.1.1264: crash when closing window from WinBar click
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2504 // Note: the command might close the current window. |
14952
405309f9dd13
patch 8.1.0487: no menus specifically for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
14700
diff
changeset
|
2505 execute_menu(NULL, item->wb_menu, -1); |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2506 |
16521
a7299d144bb9
patch 8.1.1264: crash when closing window from WinBar click
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2507 if (save_curwin != NULL && win_valid(save_curwin)) |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2508 { |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2509 curwin = save_curwin; |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2510 curbuf = curwin->w_buffer; |
12521
718787498836
patch 8.0.1139: using window toolbar changes state
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
2511 VIsual = save_visual; |
718787498836
patch 8.0.1139: using window toolbar changes state
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
2512 VIsual_active = save_visual_active; |
718787498836
patch 8.0.1139: using window toolbar changes state
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
2513 VIsual_select = save_visual_select; |
718787498836
patch 8.0.1139: using window toolbar changes state
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
2514 VIsual_reselect = save_visual_reselect; |
718787498836
patch 8.0.1139: using window toolbar changes state
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
2515 VIsual_mode = save_visual_mode; |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2516 } |
16521
a7299d144bb9
patch 8.1.1264: crash when closing window from WinBar click
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2517 if (!win_valid(wp)) |
a7299d144bb9
patch 8.1.1264: crash when closing window from WinBar click
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2518 break; |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2519 } |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2520 } |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2521 } |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2522 |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2523 #if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_GTK) \ |
13394
d21899f0d850
patch 8.0.1571: can't build without GUI
Christian Brabandt <cb@256bit.org>
parents:
13392
diff
changeset
|
2524 || defined(FEAT_TERM_POPUP_MENU) \ |
7 | 2525 || defined(FEAT_BEVAL_TIP) || defined(PROTO) |
2526 /* | |
2527 * Given a menu descriptor, e.g. "File.New", find it in the menu hierarchy. | |
2528 */ | |
2529 vimmenu_T * | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2530 gui_find_menu(char_u *path_name) |
7 | 2531 { |
2532 vimmenu_T *menu = NULL; | |
2533 char_u *name; | |
2534 char_u *saved_name; | |
2535 char_u *p; | |
2536 | |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2537 menu = *get_root_menu(path_name); |
7 | 2538 |
2539 saved_name = vim_strsave(path_name); | |
2540 if (saved_name == NULL) | |
2541 return NULL; | |
2542 | |
2543 name = saved_name; | |
2544 while (*name) | |
2545 { | |
2546 /* find the end of one dot-separated name and put a NUL at the dot */ | |
2547 p = menu_name_skip(name); | |
2548 | |
2549 while (menu != NULL) | |
2550 { | |
2676 | 2551 if (menu_name_equal(name, menu)) |
7 | 2552 { |
2553 if (menu->children == NULL) | |
2554 { | |
2555 /* found a menu item instead of a sub-menu */ | |
2556 if (*p == NUL) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15375
diff
changeset
|
2557 emsg(_("E336: Menu path must lead to a sub-menu")); |
7 | 2558 else |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15375
diff
changeset
|
2559 emsg(_(e_notsubmenu)); |
7 | 2560 menu = NULL; |
2561 goto theend; | |
2562 } | |
2563 if (*p == NUL) /* found a full match */ | |
2564 goto theend; | |
2565 break; | |
2566 } | |
2567 menu = menu->next; | |
2568 } | |
2569 if (menu == NULL) /* didn't find it */ | |
2570 break; | |
2571 | |
2572 /* Found a match, search the sub-menu. */ | |
2573 menu = menu->children; | |
2574 name = p; | |
2575 } | |
2576 | |
2577 if (menu == NULL) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15375
diff
changeset
|
2578 emsg(_("E337: Menu not found - check menu names")); |
7 | 2579 theend: |
2580 vim_free(saved_name); | |
2581 return menu; | |
2582 } | |
2583 #endif | |
2584 | |
2585 #ifdef FEAT_MULTI_LANG | |
2586 /* | |
2587 * Translation of menu names. Just a simple lookup table. | |
2588 */ | |
2589 | |
2590 typedef struct | |
2591 { | |
2592 char_u *from; /* English name */ | |
2593 char_u *from_noamp; /* same, without '&' */ | |
2594 char_u *to; /* translated name */ | |
2595 } menutrans_T; | |
2596 | |
2597 static garray_T menutrans_ga = {0, 0, 0, 0, NULL}; | |
2598 #endif | |
2599 | |
2600 /* | |
2601 * ":menutrans". | |
2602 * This function is also defined without the +multi_lang feature, in which | |
2603 * case the commands are ignored. | |
2604 */ | |
2605 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2606 ex_menutranslate(exarg_T *eap UNUSED) |
7 | 2607 { |
2608 #ifdef FEAT_MULTI_LANG | |
2609 char_u *arg = eap->arg; | |
2610 menutrans_T *tp; | |
2611 int i; | |
2612 char_u *from, *from_noamp, *to; | |
2613 | |
2614 if (menutrans_ga.ga_itemsize == 0) | |
2615 ga_init2(&menutrans_ga, (int)sizeof(menutrans_T), 5); | |
2616 | |
2617 /* | |
2618 * ":menutrans clear": clear all translations. | |
2619 */ | |
2620 if (STRNCMP(arg, "clear", 5) == 0 && ends_excmd(*skipwhite(arg + 5))) | |
2621 { | |
2622 tp = (menutrans_T *)menutrans_ga.ga_data; | |
2623 for (i = 0; i < menutrans_ga.ga_len; ++i) | |
2624 { | |
2625 vim_free(tp[i].from); | |
2626 vim_free(tp[i].from_noamp); | |
2627 vim_free(tp[i].to); | |
2628 } | |
2629 ga_clear(&menutrans_ga); | |
2630 # ifdef FEAT_EVAL | |
2631 /* Delete all "menutrans_" global variables. */ | |
2632 del_menutrans_vars(); | |
2633 # endif | |
2634 } | |
2635 else | |
2636 { | |
2637 /* ":menutrans from to": add translation */ | |
2638 from = arg; | |
2639 arg = menu_skip_part(arg); | |
2640 to = skipwhite(arg); | |
2641 *arg = NUL; | |
2642 arg = menu_skip_part(to); | |
2643 if (arg == to) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15375
diff
changeset
|
2644 emsg(_(e_invarg)); |
7 | 2645 else |
2646 { | |
2647 if (ga_grow(&menutrans_ga, 1) == OK) | |
2648 { | |
2649 tp = (menutrans_T *)menutrans_ga.ga_data; | |
2650 from = vim_strsave(from); | |
838 | 2651 if (from != NULL) |
7 | 2652 { |
838 | 2653 from_noamp = menu_text(from, NULL, NULL); |
2654 to = vim_strnsave(to, (int)(arg - to)); | |
2655 if (from_noamp != NULL && to != NULL) | |
2656 { | |
2150
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
2657 menu_translate_tab_and_shift(from); |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
2658 menu_translate_tab_and_shift(to); |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
2659 menu_unescape_name(from); |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
2660 menu_unescape_name(to); |
838 | 2661 tp[menutrans_ga.ga_len].from = from; |
2662 tp[menutrans_ga.ga_len].from_noamp = from_noamp; | |
2663 tp[menutrans_ga.ga_len].to = to; | |
2664 ++menutrans_ga.ga_len; | |
2665 } | |
2666 else | |
2667 { | |
2668 vim_free(from); | |
2669 vim_free(from_noamp); | |
2670 vim_free(to); | |
2671 } | |
7 | 2672 } |
2673 } | |
2674 } | |
2675 } | |
2676 #endif | |
2677 } | |
2678 | |
2679 #if defined(FEAT_MULTI_LANG) || defined(FEAT_TOOLBAR) | |
2680 /* | |
2681 * Find the character just after one part of a menu name. | |
2682 */ | |
2683 static char_u * | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2684 menu_skip_part(char_u *p) |
7 | 2685 { |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
2686 while (*p != NUL && *p != '.' && !VIM_ISWHITE(*p)) |
7 | 2687 { |
2688 if ((*p == '\\' || *p == Ctrl_V) && p[1] != NUL) | |
2689 ++p; | |
2690 ++p; | |
2691 } | |
2692 return p; | |
2693 } | |
2694 #endif | |
2695 | |
2696 #ifdef FEAT_MULTI_LANG | |
2697 /* | |
2698 * Lookup part of a menu name in the translations. | |
2699 * Return a pointer to the translation or NULL if not found. | |
2700 */ | |
2701 static char_u * | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2702 menutrans_lookup(char_u *name, int len) |
7 | 2703 { |
2704 menutrans_T *tp = (menutrans_T *)menutrans_ga.ga_data; | |
2705 int i; | |
2706 char_u *dname; | |
2707 | |
2708 for (i = 0; i < menutrans_ga.ga_len; ++i) | |
11044
eb3a2ff3309a
patch 8.0.0411: menu translations don't match when case is changed.
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2709 if (STRNICMP(name, tp[i].from, len) == 0 && tp[i].from[len] == NUL) |
7 | 2710 return tp[i].to; |
2711 | |
2712 /* Now try again while ignoring '&' characters. */ | |
2713 i = name[len]; | |
2714 name[len] = NUL; | |
2715 dname = menu_text(name, NULL, NULL); | |
2716 name[len] = i; | |
2717 if (dname != NULL) | |
2718 { | |
2719 for (i = 0; i < menutrans_ga.ga_len; ++i) | |
11044
eb3a2ff3309a
patch 8.0.0411: menu translations don't match when case is changed.
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2720 if (STRICMP(dname, tp[i].from_noamp) == 0) |
7 | 2721 { |
2722 vim_free(dname); | |
2723 return tp[i].to; | |
2724 } | |
2725 vim_free(dname); | |
2726 } | |
2727 | |
2728 return NULL; | |
2729 } | |
2730 | |
2150
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
2731 /* |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
2732 * Unescape the name in the translate dictionary table. |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
2733 */ |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
2734 static void |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2735 menu_unescape_name(char_u *name) |
2150
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
2736 { |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
2737 char_u *p; |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
2738 |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11044
diff
changeset
|
2739 for (p = name; *p && *p != '.'; MB_PTR_ADV(p)) |
2150
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
2740 if (*p == '\\') |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
2741 STRMOVE(p, p + 1); |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
2742 } |
2251
646d34788036
Fix a few compiler warnings. Fix crash with encrypted undo file.
Bram Moolenaar <bram@vim.org>
parents:
2217
diff
changeset
|
2743 #endif /* FEAT_MULTI_LANG */ |
2150
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
2744 |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
2745 /* |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
2746 * Isolate the menu name. |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
2747 * Skip the menu name, and translate <Tab> into a real TAB. |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
2748 */ |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
2749 static char_u * |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2750 menu_translate_tab_and_shift(char_u *arg_start) |
2150
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
2751 { |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
2752 char_u *arg = arg_start; |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
2753 |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
2754 while (*arg && !VIM_ISWHITE(*arg)) |
2150
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
2755 { |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
2756 if ((*arg == '\\' || *arg == Ctrl_V) && arg[1] != NUL) |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
2757 arg++; |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
2758 else if (STRNICMP(arg, "<TAB>", 5) == 0) |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
2759 { |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
2760 *arg = TAB; |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
2761 STRMOVE(arg + 1, arg + 5); |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
2762 } |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
2763 arg++; |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
2764 } |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
2765 if (*arg != NUL) |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
2766 *arg++ = NUL; |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
2767 arg = skipwhite(arg); |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
2768 |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
2769 return arg; |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
2770 } |
4269a0673478
updated for version 7.2.432
Bram Moolenaar <bram@zimbu.org>
parents:
2149
diff
changeset
|
2771 |
7 | 2772 #endif /* FEAT_MENU */ |