annotate src/menu.c @ 22292:3515f341e8ac v8.2.1695

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