Skip to content

Commit 83cd015

Browse files
msoyka2024brammool
authored andcommitted
patch 8.2.3243: MS-Windows: "edit with multiple Vim" choice is less useful
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)
1 parent 0732932 commit 83cd015

File tree

3 files changed

+34
-96
lines changed

3 files changed

+34
-96
lines changed

src/GvimExt/gvimext.cpp

Lines changed: 31 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ UINT cbFiles = 0;
3535
* enough */
3636
#define BUFSIZE 1100
3737

38+
// The "Edit with Vim" shell extension provides these choices when
39+
// a new instance of Gvim is selected:
40+
// - use tabpages
41+
// - enable diff mode
42+
// - none of the above
43+
#define EDIT_WITH_VIM_USE_TABPAGES (2)
44+
#define EDIT_WITH_VIM_IN_DIFF_MODE (1)
45+
#define EDIT_WITH_VIM_NO_OPTIONS (0)
46+
3847
//
3948
// Get the name of the Gvim executable to use, with the path.
4049
// When "runtime" is non-zero, we were called to find the runtime directory.
@@ -613,7 +622,7 @@ STDMETHODIMP CShellExt::QueryContextMenu(HMENU hMenu,
613622
if (cbFiles > 1)
614623
{
615624
mii.wID = idCmd++;
616-
mii.dwTypeData = _("Edit with &multiple Vims");
625+
mii.dwTypeData = _("Edit with Vim using &tabpages");
617626
mii.cch = lstrlen(mii.dwTypeData);
618627
InsertMenuItem(hMenu, indexMenu++, TRUE, &mii);
619628

@@ -726,6 +735,7 @@ STDMETHODIMP CShellExt::QueryContextMenu(HMENU hMenu,
726735
STDMETHODIMP CShellExt::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi)
727736
{
728737
HRESULT hr = E_INVALIDARG;
738+
int gvimExtraOptions;
729739

730740
// If HIWORD(lpcmi->lpVerb) then we have been called programmatically
731741
// and lpVerb is a command that should be invoked. Otherwise, the shell
@@ -750,29 +760,28 @@ STDMETHODIMP CShellExt::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi)
750760
switch (idCmd)
751761
{
752762
case 0:
753-
hr = InvokeGvim(lpcmi->hwnd,
754-
lpcmi->lpDirectory,
755-
lpcmi->lpVerb,
756-
lpcmi->lpParameters,
757-
lpcmi->nShow);
763+
gvimExtraOptions = EDIT_WITH_VIM_USE_TABPAGES;
758764
break;
759765
case 1:
760-
hr = InvokeSingleGvim(lpcmi->hwnd,
761-
lpcmi->lpDirectory,
762-
lpcmi->lpVerb,
763-
lpcmi->lpParameters,
764-
lpcmi->nShow,
765-
0);
766+
gvimExtraOptions = EDIT_WITH_VIM_NO_OPTIONS;
766767
break;
767768
case 2:
768-
hr = InvokeSingleGvim(lpcmi->hwnd,
769-
lpcmi->lpDirectory,
770-
lpcmi->lpVerb,
771-
lpcmi->lpParameters,
772-
lpcmi->nShow,
773-
1);
769+
gvimExtraOptions = EDIT_WITH_VIM_IN_DIFF_MODE;
774770
break;
771+
default:
772+
// If execution reaches this point we likely have an
773+
// inconsistency between the code that setup the menus
774+
// and this code that determines what the user
775+
// selected. This should be detected and fixed during
776+
// development.
777+
return E_FAIL;
775778
}
779+
hr = InvokeSingleGvim(lpcmi->hwnd,
780+
lpcmi->lpDirectory,
781+
lpcmi->lpVerb,
782+
lpcmi->lpParameters,
783+
lpcmi->nShow,
784+
gvimExtraOptions);
776785
}
777786
}
778787
return hr;
@@ -873,82 +882,13 @@ searchpath(char *name)
873882
return (char *)"";
874883
}
875884

876-
STDMETHODIMP CShellExt::InvokeGvim(HWND hParent,
877-
LPCSTR /* pszWorkingDir */,
878-
LPCSTR /* pszCmd */,
879-
LPCSTR /* pszParam */,
880-
int /* iShowCmd */)
881-
{
882-
wchar_t m_szFileUserClickedOn[BUFSIZE];
883-
wchar_t cmdStrW[BUFSIZE];
884-
UINT i;
885-
886-
for (i = 0; i < cbFiles; i++)
887-
{
888-
DragQueryFileW((HDROP)medium.hGlobal,
889-
i,
890-
m_szFileUserClickedOn,
891-
sizeof(m_szFileUserClickedOn));
892-
893-
getGvimInvocationW(cmdStrW);
894-
wcscat(cmdStrW, L" \"");
895-
896-
if ((wcslen(cmdStrW) + wcslen(m_szFileUserClickedOn) + 2) < BUFSIZE)
897-
{
898-
wcscat(cmdStrW, m_szFileUserClickedOn);
899-
wcscat(cmdStrW, L"\"");
900-
901-
STARTUPINFOW si;
902-
PROCESS_INFORMATION pi;
903-
904-
ZeroMemory(&si, sizeof(si));
905-
si.cb = sizeof(si);
906-
907-
// Start the child process.
908-
if (!CreateProcessW(NULL, // No module name (use command line).
909-
cmdStrW, // Command line.
910-
NULL, // Process handle not inheritable.
911-
NULL, // Thread handle not inheritable.
912-
FALSE, // Set handle inheritance to FALSE.
913-
0, // No creation flags.
914-
NULL, // Use parent's environment block.
915-
NULL, // Use parent's starting directory.
916-
&si, // Pointer to STARTUPINFO structure.
917-
&pi) // Pointer to PROCESS_INFORMATION structure.
918-
)
919-
{
920-
MessageBox(
921-
hParent,
922-
_("Error creating process: Check if gvim is in your path!"),
923-
_("gvimext.dll error"),
924-
MB_OK);
925-
}
926-
else
927-
{
928-
CloseHandle( pi.hProcess );
929-
CloseHandle( pi.hThread );
930-
}
931-
}
932-
else
933-
{
934-
MessageBox(
935-
hParent,
936-
_("Path length too long!"),
937-
_("gvimext.dll error"),
938-
MB_OK);
939-
}
940-
}
941-
942-
return NOERROR;
943-
}
944-
945885

946886
STDMETHODIMP CShellExt::InvokeSingleGvim(HWND hParent,
947887
LPCSTR /* pszWorkingDir */,
948888
LPCSTR /* pszCmd */,
949889
LPCSTR /* pszParam */,
950890
int /* iShowCmd */,
951-
int useDiff)
891+
int gvimExtraOptions)
952892
{
953893
wchar_t m_szFileUserClickedOn[BUFSIZE];
954894
wchar_t *cmdStrW;
@@ -962,8 +902,10 @@ STDMETHODIMP CShellExt::InvokeSingleGvim(HWND hParent,
962902
return E_FAIL;
963903
getGvimInvocationW(cmdStrW);
964904

965-
if (useDiff)
905+
if (gvimExtraOptions == EDIT_WITH_VIM_IN_DIFF_MODE)
966906
wcscat(cmdStrW, L" -d");
907+
else if (gvimExtraOptions == EDIT_WITH_VIM_USE_TABPAGES)
908+
wcscat(cmdStrW, L" -p");
967909
for (i = 0; i < cbFiles; i++)
968910
{
969911
DragQueryFileW((HDROP)medium.hGlobal,

src/GvimExt/gvimext.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,18 +129,12 @@ class CShellExt : public IContextMenu,
129129
int iShowCmd,
130130
int idHWnd);
131131

132-
STDMETHODIMP InvokeGvim(HWND hParent,
133-
LPCSTR pszWorkingDir,
134-
LPCSTR pszCmd,
135-
LPCSTR pszParam,
136-
int iShowCmd);
137-
138132
STDMETHODIMP InvokeSingleGvim(HWND hParent,
139133
LPCSTR pszWorkingDir,
140134
LPCSTR pszCmd,
141135
LPCSTR pszParam,
142136
int iShowCmd,
143-
int useDiff);
137+
int gvimExtraOptions);
144138

145139
public:
146140
int m_cntOfHWnd;

src/version.c

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

756756
static int included_patches[] =
757757
{ /* Add new patch number below this line */
758+
/**/
759+
3243,
758760
/**/
759761
3242,
760762
/**/

0 commit comments

Comments
 (0)