Skip to content

Commit 29a2c08

Browse files
committed
patch 8.0.1570: can't use :popup for a menu in the terminal
Problem: Can't use :popup for a menu in the terminal. (Wei Zhang) Solution: Make :popup work in the terminal. Also fix that entries were included that don't work in the current state.
1 parent 28ada69 commit 29a2c08

6 files changed

Lines changed: 53 additions & 12 deletions

File tree

src/ex_docmd.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ static void ex_tearoff(exarg_T *eap);
204204
#else
205205
# define ex_tearoff ex_ni
206206
#endif
207-
#if (defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_GTK)) && defined(FEAT_MENU)
207+
#if (defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_GTK) \
208+
|| defined(FEAT_TERM_POPUP_MENU)) && defined(FEAT_MENU)
208209
static void ex_popup(exarg_T *eap);
209210
#else
210211
# define ex_popup ex_ni
@@ -8741,11 +8742,21 @@ ex_tearoff(exarg_T *eap)
87418742
}
87428743
#endif
87438744

8744-
#if (defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_GTK)) && defined(FEAT_MENU)
8745+
#if (defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_GTK) \
8746+
|| defined(FEAT_TERM_POPUP_MENU)) && defined(FEAT_MENU)
87458747
static void
87468748
ex_popup(exarg_T *eap)
87478749
{
8748-
gui_make_popup(eap->arg, eap->forceit);
8750+
# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_GTK)
8751+
if (gui.in_use)
8752+
gui_make_popup(eap->arg, eap->forceit);
8753+
# ifdef FEAT_TERM_POPUP_MENU
8754+
else
8755+
# endif
8756+
# endif
8757+
# ifdef FEAT_TERM_POPUP_MENU
8758+
pum_make_popup(eap->arg, eap->forceit);
8759+
# endif
87498760
}
87508761
#endif
87518762

src/menu.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,6 +1891,16 @@ get_menu_mode(void)
18911891
return MENU_INDEX_INVALID;
18921892
}
18931893

1894+
int
1895+
get_menu_mode_flag(void)
1896+
{
1897+
int mode = get_menu_mode();
1898+
1899+
if (mode == MENU_INDEX_INVALID)
1900+
return 0;
1901+
return 1 << mode;
1902+
}
1903+
18941904
/*
18951905
* Display the Special "PopUp" menu as a pop-up at the current mouse
18961906
* position. The "PopUpn" menu is for Normal mode, "PopUpi" for Insert mode,
@@ -2044,13 +2054,7 @@ gui_update_menus(int modes)
20442054
if (modes != 0x0)
20452055
mode = modes;
20462056
else
2047-
{
2048-
mode = get_menu_mode();
2049-
if (mode == MENU_INDEX_INVALID)
2050-
mode = 0;
2051-
else
2052-
mode = (1 << mode);
2053-
}
2057+
mode = get_menu_mode_flag();
20542058

20552059
if (force_menu_update || mode != prev_mode)
20562060
{

src/popupmnu.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,12 +1132,16 @@ pum_show_popupmenu(vimmenu_T *menu)
11321132
#ifdef FEAT_BEVAL_TERM
11331133
int save_bevalterm = p_bevalterm;
11341134
#endif
1135+
int mode;
11351136

11361137
pum_undisplay();
11371138
pum_size = 0;
1139+
mode = get_menu_mode_flag();
11381140

11391141
for (mp = menu->children; mp != NULL; mp = mp->next)
1140-
++pum_size;
1142+
if (menu_is_separator(mp->dname)
1143+
|| (mp->modes & mp->enabled & mode))
1144+
++pum_size;
11411145

11421146
array = (pumitem_T *)alloc_clear((unsigned)sizeof(pumitem_T) * pum_size);
11431147
if (array == NULL)
@@ -1146,7 +1150,7 @@ pum_show_popupmenu(vimmenu_T *menu)
11461150
for (mp = menu->children; mp != NULL; mp = mp->next)
11471151
if (menu_is_separator(mp->dname))
11481152
array[idx++].pum_text = (char_u *)"";
1149-
else
1153+
else if (mp->modes & mp->enabled & mode)
11501154
array[idx++].pum_text = mp->dname;
11511155

11521156
pum_array = array;
@@ -1231,6 +1235,24 @@ pum_show_popupmenu(vimmenu_T *menu)
12311235
p_bevalterm = save_bevalterm;
12321236
mch_setmouse(TRUE);
12331237
# endif
1238+
}
1239+
1240+
void
1241+
pum_make_popup(char_u *path_name, int use_mouse_pos)
1242+
{
1243+
vimmenu_T *menu;
1244+
1245+
if (!use_mouse_pos)
1246+
{
1247+
/* Hack: set mouse position at the cursor so that the menu pops up
1248+
* around there. */
1249+
mouse_row = curwin->w_winrow + curwin->w_wrow;
1250+
mouse_col = curwin->w_wincol + curwin->w_wcol;
1251+
}
1252+
1253+
menu = gui_find_menu(path_name);
1254+
if (menu != NULL)
1255+
pum_show_popupmenu(menu);
12341256
}
12351257
# endif
12361258

src/proto/menu.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ int menu_is_popup(char_u *name);
1212
int menu_is_child_of_popup(vimmenu_T *menu);
1313
int menu_is_toolbar(char_u *name);
1414
int menu_is_separator(char_u *name);
15+
int get_menu_mode_flag(void);
1516
void show_popupmenu(void);
1617
int check_menu_pointer(vimmenu_T *root, vimmenu_T *menu_to_check);
1718
void gui_create_initial_menus(vimmenu_T *menu);

src/proto/popupmnu.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ void ui_remove_balloon(void);
1010
void ui_post_balloon(char_u *mesg, list_T *list);
1111
void ui_may_remove_balloon(void);
1212
void pum_show_popupmenu(vimmenu_T *menu);
13+
void pum_make_popup(char_u *path_name, int mouse_pos);
1314
/* vim: set ft=c : */

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,8 @@ static char *(features[]) =
766766

767767
static int included_patches[] =
768768
{ /* Add new patch number below this line */
769+
/**/
770+
1570,
769771
/**/
770772
1569,
771773
/**/

0 commit comments

Comments
 (0)