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