Mercurial > vim
comparison src/GvimExt/gvimext.cpp @ 25413:ee2808fb1be9 v8.2.3243
patch 8.2.3243: MS-Windows: "edit with multiple Vim" choice is less useful
Commit: https://github.com/vim/vim/commit/83cd0156e01b5befadf12ee66bc26436ee8d023f
Author: msoyka-of-wharton <mssr953@gmail.com>
Date: Thu Jul 29 19:18:33 2021 +0200
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)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 29 Jul 2021 19:30:04 +0200 |
parents | db65bb242582 |
children | 64dac9ff015e |
comparison
equal
deleted
inserted
replaced
25412:3b4a5b4b2bfb | 25413:ee2808fb1be9 |
---|---|
32 UINT cbFiles = 0; | 32 UINT cbFiles = 0; |
33 | 33 |
34 /* The buffers size used to be MAX_PATH (260 bytes), but that's not always | 34 /* The buffers size used to be MAX_PATH (260 bytes), but that's not always |
35 * enough */ | 35 * enough */ |
36 #define BUFSIZE 1100 | 36 #define BUFSIZE 1100 |
37 | |
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) | |
37 | 46 |
38 // | 47 // |
39 // Get the name of the Gvim executable to use, with the path. | 48 // Get the name of the Gvim executable to use, with the path. |
40 // When "runtime" is non-zero, we were called to find the runtime directory. | 49 // When "runtime" is non-zero, we were called to find the runtime directory. |
41 // Returns the path in name[BUFSIZE]. It's empty when it fails. | 50 // Returns the path in name[BUFSIZE]. It's empty when it fails. |
611 } | 620 } |
612 | 621 |
613 if (cbFiles > 1) | 622 if (cbFiles > 1) |
614 { | 623 { |
615 mii.wID = idCmd++; | 624 mii.wID = idCmd++; |
616 mii.dwTypeData = _("Edit with &multiple Vims"); | 625 mii.dwTypeData = _("Edit with Vim using &tabpages"); |
617 mii.cch = lstrlen(mii.dwTypeData); | 626 mii.cch = lstrlen(mii.dwTypeData); |
618 InsertMenuItem(hMenu, indexMenu++, TRUE, &mii); | 627 InsertMenuItem(hMenu, indexMenu++, TRUE, &mii); |
619 | 628 |
620 mii.wID = idCmd++; | 629 mii.wID = idCmd++; |
621 mii.dwTypeData = _("Edit with single &Vim"); | 630 mii.dwTypeData = _("Edit with single &Vim"); |
724 // | 733 // |
725 | 734 |
726 STDMETHODIMP CShellExt::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi) | 735 STDMETHODIMP CShellExt::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi) |
727 { | 736 { |
728 HRESULT hr = E_INVALIDARG; | 737 HRESULT hr = E_INVALIDARG; |
738 int gvimExtraOptions; | |
729 | 739 |
730 // If HIWORD(lpcmi->lpVerb) then we have been called programmatically | 740 // If HIWORD(lpcmi->lpVerb) then we have been called programmatically |
731 // and lpVerb is a command that should be invoked. Otherwise, the shell | 741 // and lpVerb is a command that should be invoked. Otherwise, the shell |
732 // has called us, and LOWORD(lpcmi->lpVerb) is the menu ID the user has | 742 // has called us, and LOWORD(lpcmi->lpVerb) is the menu ID the user has |
733 // selected. Actually, it's (menu ID - idCmdFirst) from QueryContextMenu(). | 743 // selected. Actually, it's (menu ID - idCmdFirst) from QueryContextMenu(). |
748 else | 758 else |
749 { | 759 { |
750 switch (idCmd) | 760 switch (idCmd) |
751 { | 761 { |
752 case 0: | 762 case 0: |
753 hr = InvokeGvim(lpcmi->hwnd, | 763 gvimExtraOptions = EDIT_WITH_VIM_USE_TABPAGES; |
754 lpcmi->lpDirectory, | |
755 lpcmi->lpVerb, | |
756 lpcmi->lpParameters, | |
757 lpcmi->nShow); | |
758 break; | 764 break; |
759 case 1: | 765 case 1: |
760 hr = InvokeSingleGvim(lpcmi->hwnd, | 766 gvimExtraOptions = EDIT_WITH_VIM_NO_OPTIONS; |
761 lpcmi->lpDirectory, | |
762 lpcmi->lpVerb, | |
763 lpcmi->lpParameters, | |
764 lpcmi->nShow, | |
765 0); | |
766 break; | 767 break; |
767 case 2: | 768 case 2: |
768 hr = InvokeSingleGvim(lpcmi->hwnd, | 769 gvimExtraOptions = EDIT_WITH_VIM_IN_DIFF_MODE; |
769 lpcmi->lpDirectory, | |
770 lpcmi->lpVerb, | |
771 lpcmi->lpParameters, | |
772 lpcmi->nShow, | |
773 1); | |
774 break; | 770 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; | |
775 } | 778 } |
779 hr = InvokeSingleGvim(lpcmi->hwnd, | |
780 lpcmi->lpDirectory, | |
781 lpcmi->lpVerb, | |
782 lpcmi->lpParameters, | |
783 lpcmi->nShow, | |
784 gvimExtraOptions); | |
776 } | 785 } |
777 } | 786 } |
778 return hr; | 787 return hr; |
779 } | 788 } |
780 | 789 |
871 return widename; | 880 return widename; |
872 } | 881 } |
873 return (char *)""; | 882 return (char *)""; |
874 } | 883 } |
875 | 884 |
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 | |
945 | 885 |
946 STDMETHODIMP CShellExt::InvokeSingleGvim(HWND hParent, | 886 STDMETHODIMP CShellExt::InvokeSingleGvim(HWND hParent, |
947 LPCSTR /* pszWorkingDir */, | 887 LPCSTR /* pszWorkingDir */, |
948 LPCSTR /* pszCmd */, | 888 LPCSTR /* pszCmd */, |
949 LPCSTR /* pszParam */, | 889 LPCSTR /* pszParam */, |
950 int /* iShowCmd */, | 890 int /* iShowCmd */, |
951 int useDiff) | 891 int gvimExtraOptions) |
952 { | 892 { |
953 wchar_t m_szFileUserClickedOn[BUFSIZE]; | 893 wchar_t m_szFileUserClickedOn[BUFSIZE]; |
954 wchar_t *cmdStrW; | 894 wchar_t *cmdStrW; |
955 size_t cmdlen; | 895 size_t cmdlen; |
956 size_t len; | 896 size_t len; |
960 cmdStrW = (wchar_t *) malloc(cmdlen * sizeof(wchar_t)); | 900 cmdStrW = (wchar_t *) malloc(cmdlen * sizeof(wchar_t)); |
961 if (cmdStrW == NULL) | 901 if (cmdStrW == NULL) |
962 return E_FAIL; | 902 return E_FAIL; |
963 getGvimInvocationW(cmdStrW); | 903 getGvimInvocationW(cmdStrW); |
964 | 904 |
965 if (useDiff) | 905 if (gvimExtraOptions == EDIT_WITH_VIM_IN_DIFF_MODE) |
966 wcscat(cmdStrW, L" -d"); | 906 wcscat(cmdStrW, L" -d"); |
907 else if (gvimExtraOptions == EDIT_WITH_VIM_USE_TABPAGES) | |
908 wcscat(cmdStrW, L" -p"); | |
967 for (i = 0; i < cbFiles; i++) | 909 for (i = 0; i < cbFiles; i++) |
968 { | 910 { |
969 DragQueryFileW((HDROP)medium.hGlobal, | 911 DragQueryFileW((HDROP)medium.hGlobal, |
970 i, | 912 i, |
971 m_szFileUserClickedOn, | 913 m_szFileUserClickedOn, |