summaryrefslogtreecommitdiffstats
path: root/src/GvimExt
diff options
context:
space:
mode:
authormsoyka-of-wharton <mssr953@gmail.com>2021-07-29 19:18:33 +0200
committerBram Moolenaar <Bram@vim.org>2021-07-29 19:18:33 +0200
commit83cd0156e01b5befadf12ee66bc26436ee8d023f (patch)
tree68451dbfa99a42bdd4066c3f6f629298e7842397 /src/GvimExt
parent0732932553e54e9bfca07e55b47201b8f30b2c4f (diff)
patch 8.2.3243: MS-Windows: "edit with multiple Vim" choice is less usefulv8.2.3243
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)
Diffstat (limited to 'src/GvimExt')
-rw-r--r--src/GvimExt/gvimext.cpp120
-rw-r--r--src/GvimExt/gvimext.h8
2 files changed, 32 insertions, 96 deletions
diff --git a/src/GvimExt/gvimext.cpp b/src/GvimExt/gvimext.cpp
index 24ad9412fe..e56379caef 100644
--- a/src/GvimExt/gvimext.cpp
+++ b/src/GvimExt/gvimext.cpp
@@ -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,
diff --git a/src/GvimExt/gvimext.h b/src/GvimExt/gvimext.h
index e43e75fdd7..3ad797e76b 100644
--- a/src/GvimExt/gvimext.h
+++ b/src/GvimExt/gvimext.h
@@ -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;