]> granicus.if.org Git - vim/commitdiff
patch 8.0.1570: can't use :popup for a menu in the terminal v8.0.1570
authorBram Moolenaar <Bram@vim.org>
Mon, 5 Mar 2018 20:06:23 +0000 (21:06 +0100)
committerBram Moolenaar <Bram@vim.org>
Mon, 5 Mar 2018 20:06:23 +0000 (21:06 +0100)
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.

src/ex_docmd.c
src/menu.c
src/popupmnu.c
src/proto/menu.pro
src/proto/popupmnu.pro
src/version.c

index 0a51d8eb7da4513a8f42176ce9019912709ac794..f913fb527816ee0e64f863b0306bf5efce001076 100644 (file)
@@ -204,7 +204,8 @@ static void ex_tearoff(exarg_T *eap);
 #else
 # define ex_tearoff            ex_ni
 #endif
-#if (defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_GTK)) && defined(FEAT_MENU)
+#if (defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_GTK) \
+       || defined(FEAT_TERM_POPUP_MENU)) && defined(FEAT_MENU)
 static void    ex_popup(exarg_T *eap);
 #else
 # define ex_popup              ex_ni
@@ -8741,11 +8742,21 @@ ex_tearoff(exarg_T *eap)
 }
 #endif
 
-#if (defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_GTK)) && defined(FEAT_MENU)
+#if (defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_GTK) \
+       || defined(FEAT_TERM_POPUP_MENU)) && defined(FEAT_MENU)
     static void
 ex_popup(exarg_T *eap)
 {
-    gui_make_popup(eap->arg, eap->forceit);
+# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_GTK)
+    if (gui.in_use)
+       gui_make_popup(eap->arg, eap->forceit);
+#  ifdef FEAT_TERM_POPUP_MENU
+    else
+#  endif
+# endif
+# ifdef FEAT_TERM_POPUP_MENU
+       pum_make_popup(eap->arg, eap->forceit);
+# endif
 }
 #endif
 
index 107cabce6c472e5a62389671aa3fdee43647f535..c04cd49bbdeb99fb02097842eb89d259e6dccd84 100644 (file)
@@ -1891,6 +1891,16 @@ get_menu_mode(void)
     return MENU_INDEX_INVALID;
 }
 
+    int
+get_menu_mode_flag(void)
+{
+    int mode = get_menu_mode();
+
+    if (mode == MENU_INDEX_INVALID)
+       return 0;
+    return 1 << mode;
+}
+
 /*
  * Display the Special "PopUp" menu as a pop-up at the current mouse
  * position.  The "PopUpn" menu is for Normal mode, "PopUpi" for Insert mode,
@@ -2044,13 +2054,7 @@ gui_update_menus(int modes)
     if (modes != 0x0)
        mode = modes;
     else
-    {
-       mode = get_menu_mode();
-       if (mode == MENU_INDEX_INVALID)
-           mode = 0;
-       else
-           mode = (1 << mode);
-    }
+       mode = get_menu_mode_flag();
 
     if (force_menu_update || mode != prev_mode)
     {
index 6cfd95a4e97a8e939312782bfe10e8a3c5dbe29d..9b5f750f88ddde233961df5abf5e2813f7570109 100644 (file)
@@ -1132,12 +1132,16 @@ pum_show_popupmenu(vimmenu_T *menu)
 #ifdef FEAT_BEVAL_TERM
     int                save_bevalterm = p_bevalterm;
 #endif
+    int                mode;
 
     pum_undisplay();
     pum_size = 0;
+    mode = get_menu_mode_flag();
 
     for (mp = menu->children; mp != NULL; mp = mp->next)
-       ++pum_size;
+       if (menu_is_separator(mp->dname)
+               || (mp->modes & mp->enabled & mode))
+           ++pum_size;
 
     array = (pumitem_T *)alloc_clear((unsigned)sizeof(pumitem_T) * pum_size);
     if (array == NULL)
@@ -1146,7 +1150,7 @@ pum_show_popupmenu(vimmenu_T *menu)
     for (mp = menu->children; mp != NULL; mp = mp->next)
        if (menu_is_separator(mp->dname))
            array[idx++].pum_text = (char_u *)"";
-       else
+       else if (mp->modes & mp->enabled & mode)
            array[idx++].pum_text = mp->dname;
 
     pum_array = array;
@@ -1231,6 +1235,24 @@ pum_show_popupmenu(vimmenu_T *menu)
     p_bevalterm = save_bevalterm;
     mch_setmouse(TRUE);
 #  endif
+}
+
+    void
+pum_make_popup(char_u *path_name, int use_mouse_pos)
+{
+    vimmenu_T *menu;
+
+    if (!use_mouse_pos)
+    {
+       /* Hack: set mouse position at the cursor so that the menu pops up
+        * around there. */
+       mouse_row = curwin->w_winrow + curwin->w_wrow;
+       mouse_col = curwin->w_wincol + curwin->w_wcol;
+    }
+
+    menu = gui_find_menu(path_name);
+    if (menu != NULL)
+       pum_show_popupmenu(menu);
 }
 # endif
 
index 4c8e710d8f0d7530d8abcc72e44dd64b3540a015..63f8d11bddb1bd3ba7998ea92ac13c7057917e1e 100644 (file)
@@ -12,6 +12,7 @@ int menu_is_popup(char_u *name);
 int menu_is_child_of_popup(vimmenu_T *menu);
 int menu_is_toolbar(char_u *name);
 int menu_is_separator(char_u *name);
+int get_menu_mode_flag(void);
 void show_popupmenu(void);
 int check_menu_pointer(vimmenu_T *root, vimmenu_T *menu_to_check);
 void gui_create_initial_menus(vimmenu_T *menu);
index d2f6baf46bea71c829937ca5b741c2033c93130c..8fd4ac90f9494dd0ab9c3c9c7e2f294e5196d439 100644 (file)
@@ -10,4 +10,5 @@ void ui_remove_balloon(void);
 void ui_post_balloon(char_u *mesg, list_T *list);
 void ui_may_remove_balloon(void);
 void pum_show_popupmenu(vimmenu_T *menu);
+void pum_make_popup(char_u *path_name, int mouse_pos);
 /* vim: set ft=c : */
index 2b64f3692469937363c0ab0eddc74ce7f11a02ad..6f498aa9716244312625b04cb2b9e2a532754d5c 100644 (file)
@@ -766,6 +766,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1570,
 /**/
     1569,
 /**/