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