annotate src/menu.c @ 804:db73a88f4c2d

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