]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.3243: MS-Windows: "edit with multiple Vim" choice is less useful v8.2.3243
authormsoyka-of-wharton <mssr953@gmail.com>
Thu, 29 Jul 2021 17:18:33 +0000 (19:18 +0200)
committerBram Moolenaar <Bram@vim.org>
Thu, 29 Jul 2021 17:18:33 +0000 (19:18 +0200)
Problem:    MS-Windows: the "edit with multiple Vim" choice is not that
            useful.
Solution:   Change it to "Edit with multiple tabs". (Michael Soyka,
            closes #8645)

src/GvimExt/gvimext.cpp
src/GvimExt/gvimext.h
src/version.c

index 24ad9412fe90fc7a6507b606c13677a97652db6f..e56379caef54b97f4992ac3d9ad797f4f488cfba 100644 (file)
@@ -35,6 +35,15 @@ UINT cbFiles = 0;
  * enough */
 #define BUFSIZE 1100
 
+// The "Edit with Vim" shell extension provides these choices when
+// a new instance of Gvim is selected:
+//   - use tabpages
+//   - enable diff mode
+//   - none of the above
+#define EDIT_WITH_VIM_USE_TABPAGES (2)
+#define EDIT_WITH_VIM_IN_DIFF_MODE (1)
+#define EDIT_WITH_VIM_NO_OPTIONS   (0)
+
 //
 // Get the name of the Gvim executable to use, with the path.
 // When "runtime" is non-zero, we were called to find the runtime directory.
@@ -613,7 +622,7 @@ STDMETHODIMP CShellExt::QueryContextMenu(HMENU hMenu,
     if (cbFiles > 1)
     {
        mii.wID = idCmd++;
-       mii.dwTypeData = _("Edit with &multiple Vims");
+       mii.dwTypeData = _("Edit with Vim using &tabpages");
        mii.cch = lstrlen(mii.dwTypeData);
        InsertMenuItem(hMenu, indexMenu++, TRUE, &mii);
 
@@ -726,6 +735,7 @@ STDMETHODIMP CShellExt::QueryContextMenu(HMENU hMenu,
 STDMETHODIMP CShellExt::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi)
 {
     HRESULT hr = E_INVALIDARG;
+    int gvimExtraOptions;
 
     // If HIWORD(lpcmi->lpVerb) then we have been called programmatically
     // and lpVerb is a command that should be invoked.  Otherwise, the shell
@@ -750,29 +760,28 @@ STDMETHODIMP CShellExt::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi)
            switch (idCmd)
            {
                case 0:
-                   hr = InvokeGvim(lpcmi->hwnd,
-                           lpcmi->lpDirectory,
-                           lpcmi->lpVerb,
-                           lpcmi->lpParameters,
-                           lpcmi->nShow);
+                   gvimExtraOptions = EDIT_WITH_VIM_USE_TABPAGES;
                    break;
                case 1:
-                   hr = InvokeSingleGvim(lpcmi->hwnd,
-                           lpcmi->lpDirectory,
-                           lpcmi->lpVerb,
-                           lpcmi->lpParameters,
-                           lpcmi->nShow,
-                           0);
+                   gvimExtraOptions = EDIT_WITH_VIM_NO_OPTIONS;
                    break;
                case 2:
-                   hr = InvokeSingleGvim(lpcmi->hwnd,
-                           lpcmi->lpDirectory,
-                           lpcmi->lpVerb,
-                           lpcmi->lpParameters,
-                           lpcmi->nShow,
-                           1);
+                   gvimExtraOptions = EDIT_WITH_VIM_IN_DIFF_MODE;
                    break;
+               default:
+                   // If execution reaches this point we likely have an
+                   // inconsistency between the code that setup the menus
+                   // and this code that determines what the user
+                   // selected.  This should be detected and fixed during 
+                   // development.
+                   return E_FAIL;
            }
+           hr = InvokeSingleGvim(lpcmi->hwnd,
+                   lpcmi->lpDirectory,
+                   lpcmi->lpVerb,
+                   lpcmi->lpParameters,
+                   lpcmi->nShow,
+                   gvimExtraOptions);
        }
     }
     return hr;
@@ -873,82 +882,13 @@ searchpath(char *name)
     return (char *)"";
 }
 
-STDMETHODIMP CShellExt::InvokeGvim(HWND hParent,
-                                  LPCSTR  /* pszWorkingDir */,
-                                  LPCSTR  /* pszCmd */,
-                                  LPCSTR  /* pszParam */,
-                                  int  /* iShowCmd */)
-{
-    wchar_t m_szFileUserClickedOn[BUFSIZE];
-    wchar_t cmdStrW[BUFSIZE];
-    UINT i;
-
-    for (i = 0; i < cbFiles; i++)
-    {
-       DragQueryFileW((HDROP)medium.hGlobal,
-               i,
-               m_szFileUserClickedOn,
-               sizeof(m_szFileUserClickedOn));
-
-       getGvimInvocationW(cmdStrW);
-       wcscat(cmdStrW, L" \"");
-
-       if ((wcslen(cmdStrW) + wcslen(m_szFileUserClickedOn) + 2) < BUFSIZE)
-       {
-           wcscat(cmdStrW, m_szFileUserClickedOn);
-           wcscat(cmdStrW, L"\"");
-
-           STARTUPINFOW si;
-           PROCESS_INFORMATION pi;
-
-           ZeroMemory(&si, sizeof(si));
-           si.cb = sizeof(si);
-
-           // Start the child process.
-           if (!CreateProcessW(NULL,   // No module name (use command line).
-                       cmdStrW,        // Command line.
-                       NULL,           // Process handle not inheritable.
-                       NULL,           // Thread handle not inheritable.
-                       FALSE,          // Set handle inheritance to FALSE.
-                       0,              // No creation flags.
-                       NULL,           // Use parent's environment block.
-                       NULL,           // Use parent's starting directory.
-                       &si,            // Pointer to STARTUPINFO structure.
-                       &pi)            // Pointer to PROCESS_INFORMATION structure.
-              )
-           {
-               MessageBox(
-                   hParent,
-                   _("Error creating process: Check if gvim is in your path!"),
-                   _("gvimext.dll error"),
-                   MB_OK);
-           }
-           else
-           {
-               CloseHandle( pi.hProcess );
-               CloseHandle( pi.hThread );
-           }
-       }
-       else
-       {
-           MessageBox(
-               hParent,
-               _("Path length too long!"),
-               _("gvimext.dll error"),
-               MB_OK);
-       }
-    }
-
-    return NOERROR;
-}
-
 
 STDMETHODIMP CShellExt::InvokeSingleGvim(HWND hParent,
                                   LPCSTR  /* pszWorkingDir */,
                                   LPCSTR  /* pszCmd */,
                                   LPCSTR  /* pszParam */,
                                   int  /* iShowCmd */,
-                                  int useDiff)
+                                  int gvimExtraOptions)
 {
     wchar_t    m_szFileUserClickedOn[BUFSIZE];
     wchar_t    *cmdStrW;
@@ -962,8 +902,10 @@ STDMETHODIMP CShellExt::InvokeSingleGvim(HWND hParent,
        return E_FAIL;
     getGvimInvocationW(cmdStrW);
 
-    if (useDiff)
+    if (gvimExtraOptions == EDIT_WITH_VIM_IN_DIFF_MODE)
        wcscat(cmdStrW, L" -d");
+    else if (gvimExtraOptions == EDIT_WITH_VIM_USE_TABPAGES)
+       wcscat(cmdStrW, L" -p");
     for (i = 0; i < cbFiles; i++)
     {
        DragQueryFileW((HDROP)medium.hGlobal,
index e43e75fdd786d69e8b0e3c31cde372239bf59395..3ad797e76b926edd513c51db202d05f1cc688cff 100644 (file)
@@ -129,18 +129,12 @@ protected:
            int iShowCmd,
            int idHWnd);
 
-    STDMETHODIMP InvokeGvim(HWND hParent,
-           LPCSTR pszWorkingDir,
-           LPCSTR pszCmd,
-           LPCSTR pszParam,
-           int iShowCmd);
-
     STDMETHODIMP InvokeSingleGvim(HWND hParent,
            LPCSTR pszWorkingDir,
            LPCSTR pszCmd,
            LPCSTR pszParam,
            int iShowCmd,
-           int useDiff);
+           int gvimExtraOptions);
 
 public:
     int                 m_cntOfHWnd;
index 7f0d8c8f9d678f441862e12bbdcc5fe7a35d5659..c0aa0d99813aa877f229564785d933a59fb8afd1 100644 (file)
@@ -755,6 +755,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3243,
 /**/
     3242,
 /**/