@@ -708,11 +708,26 @@ STDMETHODIMP CShellExt::QueryContextMenu(HMENU hMenu,
708708 m_edit_existing_off = 1 ;
709709 }
710710
711+ HMENU hSubMenu = NULL ;
712+ if (m_cntOfHWnd > 1 )
713+ {
714+ hSubMenu = CreatePopupMenu ();
715+ mii.fMask |= MIIM_SUBMENU;
716+ mii.wID = idCmd;
717+ mii.dwTypeData = _ (" Edit with existing Vim" );
718+ mii.cch = lstrlen (mii.dwTypeData );
719+ mii.hSubMenu = hSubMenu;
720+ InsertMenuItem (hMenu, indexMenu++, TRUE , &mii);
721+ mii.fMask = mii.fMask & ~MIIM_SUBMENU;
722+ mii.hSubMenu = NULL ;
723+ }
711724 // Now display all the vim instances
712725 for (int i = 0 ; i < m_cntOfHWnd; i++)
713726 {
714727 char title[BUFSIZE];
715728 char temp[BUFSIZE];
729+ int index;
730+ HMENU hmenu;
716731
717732 // Obtain window title, continue if can not
718733 if (GetWindowText (m_hWnd[i], title, BUFSIZE - 1 ) == 0 )
@@ -726,15 +741,30 @@ STDMETHODIMP CShellExt::QueryContextMenu(HMENU hMenu,
726741 *pos = 0 ;
727742 }
728743 // Now concatenate
729- strncpy (temp, _ (" Edit with existing Vim - " ), BUFSIZE - 1 );
730- temp[BUFSIZE - 1 ] = ' \0 ' ;
744+ if (m_cntOfHWnd > 1 )
745+ temp[0 ] = ' \0 ' ;
746+ else
747+ {
748+ strncpy (temp, _ (" Edit with existing Vim - " ), BUFSIZE - 1 );
749+ temp[BUFSIZE - 1 ] = ' \0 ' ;
750+ }
731751 strncat (temp, title, BUFSIZE - 1 - strlen (temp));
732752 temp[BUFSIZE - 1 ] = ' \0 ' ;
733753
734754 mii.wID = idCmd++;
735755 mii.dwTypeData = temp;
736756 mii.cch = lstrlen (mii.dwTypeData );
737- InsertMenuItem (hMenu, indexMenu++, TRUE , &mii);
757+ if (m_cntOfHWnd > 1 )
758+ {
759+ hmenu = hSubMenu;
760+ index = i;
761+ }
762+ else
763+ {
764+ hmenu = hMenu;
765+ index = indexMenu++;
766+ }
767+ InsertMenuItem (hmenu, index, TRUE , &mii);
738768 }
739769 // InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL);
740770
0 commit comments