/* vi:set ts=8 sts=4 sw=4: * * VIM - Vi IMproved by Bram Moolenaar * GUI/Motif support by Robert Webb * * Do ":help uganda" in Vim to read copying and usage conditions. * Do ":help credits" in Vim to see a list of people who contributed. * See README.txt for an overview of the Vim source code. */ /* * Code for menus. Used for the GUI and 'wildmenu'. */ #include "vim.h" #if defined(FEAT_MENU) || defined(PROTO) #define MENUDEPTH 10 /* maximum depth of menus */ #ifdef FEAT_GUI_W32 static int add_menu_path __ARGS((char_u *, vimmenu_T *, int *, char_u *, int)); #else static int add_menu_path __ARGS((char_u *, vimmenu_T *, int *, char_u *)); #endif static int menu_nable_recurse __ARGS((vimmenu_T *menu, char_u *name, int modes, int enable)); static int remove_menu __ARGS((vimmenu_T **, char_u *, int, int silent)); static void free_menu __ARGS((vimmenu_T **menup)); static void free_menu_string __ARGS((vimmenu_T *, int)); static int show_menus __ARGS((char_u *, int)); static void show_menus_recursive __ARGS((vimmenu_T *, int, int)); static int menu_name_equal __ARGS((char_u *name, vimmenu_T *menu)); static int menu_namecmp __ARGS((char_u *name, char_u *mname)); static int get_menu_cmd_modes __ARGS((char_u *, int, int *, int *)); static char_u *popup_mode_name __ARGS((char_u *name, int idx)); static char_u *menu_text __ARGS((char_u *text, int *mnemonic, char_u **actext)); #ifdef FEAT_GUI static int get_menu_mode __ARGS((void)); static void gui_update_menus_recurse __ARGS((vimmenu_T *, int)); #endif #if defined(FEAT_GUI_W32) && defined(FEAT_TEAROFF) static void gui_create_tearoffs_recurse __ARGS((vimmenu_T *menu, const char_u *pname, int *pri_tab, int pri_idx)); static void gui_add_tearoff __ARGS((char_u *tearpath, int *pri_tab, int pri_idx)); static void gui_destroy_tearoffs_recurse __ARGS((vimmenu_T *menu)); static int s_tearoffs = FALSE; #endif static int menu_is_hidden __ARGS((char_u *name)); #if defined(FEAT_CMDL_COMPL) || (defined(FEAT_GUI_W32) && defined(FEAT_TEAROFF)) static int menu_is_tearoff __ARGS((char_u *name)); #endif #if defined(FEAT_MULTI_LANG) || defined(FEAT_TOOLBAR) static char_u *menu_skip_part __ARGS((char_u *p)); #endif #ifdef FEAT_MULTI_LANG static char_u *menutrans_lookup __ARGS((char_u *name, int len)); static void menu_unescape_name __ARGS((char_u *p)); #endif static char_u *menu_translate_tab_and_shift __ARGS((char_u *arg_start)); /* The character for each menu mode */ static char_u menu_mode_chars[] = {'n', 'v', 's', 'o', 'i', 'c', 't'}; static char_u e_notsubmenu[] = N_("E327: Part of menu-item path is not sub-menu"); static char_u e_othermode[] = N_("E328: Menu only exists in another mode"); static char_u e_nomenu[] = N_("E329: No menu \"%s\""); #ifdef FEAT_TOOLBAR static const char *toolbar_names[] = { /* 0 */ "New", "Open", "Save", "Undo", "Redo", /* 5 */ "Cut", "Copy", "Paste", "Print", "Help", /* 10 */ "Find", "SaveAll", "SaveSesn", "NewSesn", "LoadSesn", /* 15 */ "RunScript", "Replace", "WinClose", "WinMax", "WinMin", /* 20 */ "WinSplit", "Shell", "FindPrev", "FindNext", "FindHelp", /* 25 */ "Make", "TagJump", "RunCtags", "WinVSplit", "WinMaxWidth", /* 30 */ "WinMinWidth", "Exit" }; # define TOOLBAR_NAME_COUNT (sizeof(toolbar_names) / sizeof(char *)) #endif /* * Do the :menu command and relatives. */ void ex_menu(eap) exarg_T *eap; /* Ex command arguments */ { char_u *menu_path; int modes; char_u *map_to; int noremap; int silent = FALSE; int special = FALSE; int unmenu; char_u *map_buf; char_u *arg; char_u *p; int i; #if defined(FEAT_GUI) && !defined(FEAT_GUI_GTK) int old_menu_height; # if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32) && !defined(FEAT_GUI_W16) int old_toolbar_height; # endif #endif int pri_tab[MENUDEPTH + 1]; int enable = MAYBE; /* TRUE for "menu enable", FALSE for "menu * disable */ #ifdef FEAT_TOOLBAR char_u *icon = NULL; #endif vimmenu_T menuarg; modes = get_menu_cmd_modes(eap->cmd, eap->forceit, &noremap, &unmenu); arg = eap->arg; for (;;) { if (STRNCMP(arg, "