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