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