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