Mercurial > vim
comparison src/menu.c @ 13369:244ff1b6d2ad v8.0.1558
patch 8.0.1558: no right-click menu in a terminal
commit https://github.com/vim/vim/commit/aef8c3da2ba59285b7cfde559ae21cdce6ba6919
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Mar 3 18:59:16 2018 +0100
patch 8.0.1558: no right-click menu in a terminal
Problem: No right-click menu in a terminal.
Solution: Implement the right click menu for the terminal.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 03 Mar 2018 19:00:06 +0100 |
parents | ac42c4b11dbc |
children | 69517d67421f |
comparison
equal
deleted
inserted
replaced
13368:a68814ee7449 | 13369:244ff1b6d2ad |
---|---|
32 static int menu_name_equal(char_u *name, vimmenu_T *menu); | 32 static int menu_name_equal(char_u *name, vimmenu_T *menu); |
33 static int menu_namecmp(char_u *name, char_u *mname); | 33 static int menu_namecmp(char_u *name, char_u *mname); |
34 static int get_menu_cmd_modes(char_u *, int, int *, int *); | 34 static int get_menu_cmd_modes(char_u *, int, int *, int *); |
35 static char_u *popup_mode_name(char_u *name, int idx); | 35 static char_u *popup_mode_name(char_u *name, int idx); |
36 static char_u *menu_text(char_u *text, int *mnemonic, char_u **actext); | 36 static char_u *menu_text(char_u *text, int *mnemonic, char_u **actext); |
37 #ifdef FEAT_GUI | |
38 static int get_menu_mode(void); | |
39 static void gui_update_menus_recurse(vimmenu_T *, int); | |
40 #endif | |
41 | 37 |
42 #if defined(FEAT_GUI_W32) && defined(FEAT_TEAROFF) | 38 #if defined(FEAT_GUI_W32) && defined(FEAT_TEAROFF) |
43 static void gui_create_tearoffs_recurse(vimmenu_T *menu, const char_u *pname, int *pri_tab, int pri_idx); | 39 static void gui_create_tearoffs_recurse(vimmenu_T *menu, const char_u *pname, int *pri_tab, int pri_idx); |
44 static void gui_add_tearoff(char_u *tearpath, int *pri_tab, int pri_idx); | 40 static void gui_add_tearoff(char_u *tearpath, int *pri_tab, int pri_idx); |
45 static void gui_destroy_tearoffs_recurse(vimmenu_T *menu); | 41 static void gui_destroy_tearoffs_recurse(vimmenu_T *menu); |
1869 return FALSE; | 1865 return FALSE; |
1870 #endif | 1866 #endif |
1871 } | 1867 } |
1872 #endif | 1868 #endif |
1873 | 1869 |
1874 #ifdef FEAT_GUI | 1870 #if defined(FEAT_GUI) || defined(FEAT_TERM_POPUP_MENU) || defined(PROTO) |
1875 | 1871 |
1876 static int | 1872 static int |
1877 get_menu_mode(void) | 1873 get_menu_mode(void) |
1878 { | 1874 { |
1879 if (VIsual_active) | 1875 if (VIsual_active) |
1894 return MENU_INDEX_INSERT; | 1890 return MENU_INDEX_INSERT; |
1895 return MENU_INDEX_INVALID; | 1891 return MENU_INDEX_INVALID; |
1896 } | 1892 } |
1897 | 1893 |
1898 /* | 1894 /* |
1895 * Display the Special "PopUp" menu as a pop-up at the current mouse | |
1896 * position. The "PopUpn" menu is for Normal mode, "PopUpi" for Insert mode, | |
1897 * etc. | |
1898 */ | |
1899 void | |
1900 show_popupmenu(void) | |
1901 { | |
1902 vimmenu_T *menu; | |
1903 int mode; | |
1904 | |
1905 mode = get_menu_mode(); | |
1906 if (mode == MENU_INDEX_INVALID) | |
1907 return; | |
1908 mode = menu_mode_chars[mode]; | |
1909 | |
1910 # ifdef FEAT_AUTOCMD | |
1911 { | |
1912 char_u ename[2]; | |
1913 | |
1914 ename[0] = mode; | |
1915 ename[1] = NUL; | |
1916 apply_autocmds(EVENT_MENUPOPUP, ename, NULL, FALSE, curbuf); | |
1917 } | |
1918 # endif | |
1919 | |
1920 for (menu = root_menu; menu != NULL; menu = menu->next) | |
1921 if (STRNCMP("PopUp", menu->name, 5) == 0 && menu->name[5] == mode) | |
1922 break; | |
1923 | |
1924 /* Only show a popup when it is defined and has entries */ | |
1925 if (menu != NULL && menu->children != NULL) | |
1926 { | |
1927 # if defined(FEAT_GUI) | |
1928 if (gui.in_use) | |
1929 { | |
1930 /* Update the menus now, in case the MenuPopup autocommand did | |
1931 * anything. */ | |
1932 gui_update_menus(0); | |
1933 gui_mch_show_popupmenu(menu); | |
1934 } | |
1935 # endif | |
1936 # if defined(FEAT_GUI) && defined(FEAT_TERM_POPUP_MENU) | |
1937 else | |
1938 # endif | |
1939 # if defined(FEAT_TERM_POPUP_MENU) | |
1940 pum_show_popupmenu(menu); | |
1941 # endif | |
1942 } | |
1943 } | |
1944 #endif | |
1945 | |
1946 #if defined(FEAT_GUI) || defined(PROTO) | |
1947 | |
1948 /* | |
1899 * Check that a pointer appears in the menu tree. Used to protect from using | 1949 * Check that a pointer appears in the menu tree. Used to protect from using |
1900 * a menu that was deleted after it was selected but before the event was | 1950 * a menu that was deleted after it was selected but before the event was |
1901 * handled. | 1951 * handled. |
1902 * Return OK or FAIL. Used recursively. | 1952 * Return OK or FAIL. Used recursively. |
1903 */ | 1953 */ |
1953 int grey; | 2003 int grey; |
1954 | 2004 |
1955 while (menu) | 2005 while (menu) |
1956 { | 2006 { |
1957 if ((menu->modes & menu->enabled & mode) | 2007 if ((menu->modes & menu->enabled & mode) |
1958 #if defined(FEAT_GUI_W32) && defined(FEAT_TEAROFF) | 2008 # if defined(FEAT_GUI_W32) && defined(FEAT_TEAROFF) |
1959 || menu_is_tearoff(menu->dname) | 2009 || menu_is_tearoff(menu->dname) |
1960 #endif | 2010 # endif |
1961 ) | 2011 ) |
1962 grey = FALSE; | 2012 grey = FALSE; |
1963 else | 2013 else |
1964 grey = TRUE; | 2014 grey = TRUE; |
1965 #ifdef FEAT_GUI_ATHENA | 2015 # ifdef FEAT_GUI_ATHENA |
1966 /* Hiding menus doesn't work for Athena, it can cause a crash. */ | 2016 /* Hiding menus doesn't work for Athena, it can cause a crash. */ |
1967 gui_mch_menu_grey(menu, grey); | 2017 gui_mch_menu_grey(menu, grey); |
1968 #else | 2018 # else |
1969 /* Never hide a toplevel menu, it may make the menubar resize or | 2019 /* Never hide a toplevel menu, it may make the menubar resize or |
1970 * disappear. Same problem for ToolBar items. */ | 2020 * disappear. Same problem for ToolBar items. */ |
1971 if (vim_strchr(p_go, GO_GREY) != NULL || menu->parent == NULL | 2021 if (vim_strchr(p_go, GO_GREY) != NULL || menu->parent == NULL |
1972 # ifdef FEAT_TOOLBAR | 2022 # ifdef FEAT_TOOLBAR |
1973 || menu_is_toolbar(menu->parent->name) | 2023 || menu_is_toolbar(menu->parent->name) |
1974 # endif | 2024 # endif |
1975 ) | 2025 ) |
1976 gui_mch_menu_grey(menu, grey); | 2026 gui_mch_menu_grey(menu, grey); |
1977 else | 2027 else |
1978 gui_mch_menu_hidden(menu, grey); | 2028 gui_mch_menu_hidden(menu, grey); |
1979 #endif | 2029 # endif |
1980 gui_update_menus_recurse(menu->children, mode); | 2030 gui_update_menus_recurse(menu->children, mode); |
1981 menu = menu->next; | 2031 menu = menu->next; |
1982 } | 2032 } |
1983 } | 2033 } |
1984 | 2034 |
2008 { | 2058 { |
2009 gui_update_menus_recurse(root_menu, mode); | 2059 gui_update_menus_recurse(root_menu, mode); |
2010 gui_mch_draw_menubar(); | 2060 gui_mch_draw_menubar(); |
2011 prev_mode = mode; | 2061 prev_mode = mode; |
2012 force_menu_update = FALSE; | 2062 force_menu_update = FALSE; |
2013 #ifdef FEAT_GUI_W32 | 2063 # ifdef FEAT_GUI_W32 |
2014 /* This can leave a tearoff as active window - make sure we | 2064 /* This can leave a tearoff as active window - make sure we |
2015 * have the focus <negri>*/ | 2065 * have the focus <negri>*/ |
2016 gui_mch_activate_window(); | 2066 gui_mch_activate_window(); |
2017 #endif | 2067 # endif |
2018 } | 2068 } |
2019 } | 2069 } |
2020 | 2070 |
2021 #if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_MOTIF) \ | 2071 # if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_MOTIF) \ |
2022 || defined(FEAT_GUI_GTK) || defined(FEAT_GUI_PHOTON) || defined(PROTO) | 2072 || defined(FEAT_GUI_GTK) || defined(FEAT_GUI_PHOTON) || defined(PROTO) |
2023 /* | 2073 /* |
2024 * Check if a key is used as a mnemonic for a toplevel menu. | 2074 * Check if a key is used as a mnemonic for a toplevel menu. |
2025 * Case of the key is ignored. | 2075 * Case of the key is ignored. |
2026 */ | 2076 */ |
2035 if (menu->mnemonic == key | 2085 if (menu->mnemonic == key |
2036 || (menu->mnemonic < 256 && TOLOWER_LOC(menu->mnemonic) == key)) | 2086 || (menu->mnemonic < 256 && TOLOWER_LOC(menu->mnemonic) == key)) |
2037 return TRUE; | 2087 return TRUE; |
2038 return FALSE; | 2088 return FALSE; |
2039 } | 2089 } |
2040 #endif | 2090 # endif |
2041 | |
2042 /* | |
2043 * Display the Special "PopUp" menu as a pop-up at the current mouse | |
2044 * position. The "PopUpn" menu is for Normal mode, "PopUpi" for Insert mode, | |
2045 * etc. | |
2046 */ | |
2047 void | |
2048 gui_show_popupmenu(void) | |
2049 { | |
2050 vimmenu_T *menu; | |
2051 int mode; | |
2052 | |
2053 mode = get_menu_mode(); | |
2054 if (mode == MENU_INDEX_INVALID) | |
2055 return; | |
2056 mode = menu_mode_chars[mode]; | |
2057 | |
2058 #ifdef FEAT_AUTOCMD | |
2059 { | |
2060 char_u ename[2]; | |
2061 | |
2062 ename[0] = mode; | |
2063 ename[1] = NUL; | |
2064 apply_autocmds(EVENT_MENUPOPUP, ename, NULL, FALSE, curbuf); | |
2065 } | |
2066 #endif | |
2067 | |
2068 for (menu = root_menu; menu != NULL; menu = menu->next) | |
2069 if (STRNCMP("PopUp", menu->name, 5) == 0 && menu->name[5] == mode) | |
2070 break; | |
2071 | |
2072 /* Only show a popup when it is defined and has entries */ | |
2073 if (menu != NULL && menu->children != NULL) | |
2074 { | |
2075 /* Update the menus now, in case the MenuPopup autocommand did | |
2076 * anything. */ | |
2077 gui_update_menus(0); | |
2078 gui_mch_show_popupmenu(menu); | |
2079 } | |
2080 } | |
2081 #endif /* FEAT_GUI */ | 2091 #endif /* FEAT_GUI */ |
2082 | 2092 |
2083 #if (defined(FEAT_GUI_W32) && defined(FEAT_TEAROFF)) || defined(PROTO) | 2093 #if (defined(FEAT_GUI_W32) && defined(FEAT_TEAROFF)) || defined(PROTO) |
2084 | 2094 |
2085 /* | 2095 /* |
2236 | 2246 |
2237 /* | 2247 /* |
2238 * Execute "menu". Use by ":emenu" and the window toolbar. | 2248 * Execute "menu". Use by ":emenu" and the window toolbar. |
2239 * "eap" is NULL for the window toolbar. | 2249 * "eap" is NULL for the window toolbar. |
2240 */ | 2250 */ |
2241 static void | 2251 void |
2242 execute_menu(exarg_T *eap, vimmenu_T *menu) | 2252 execute_menu(exarg_T *eap, vimmenu_T *menu) |
2243 { | 2253 { |
2244 char_u *mode; | 2254 char_u *mode; |
2245 int idx = -1; | 2255 int idx = -1; |
2246 | 2256 |