1
+ #include " pch.h"
2
+ #include " EditWithNppExplorerCommandHandler.h"
3
+
4
+ #include " Helpers.h"
5
+
6
+ using namespace NppShell ::CommandHandlers;
7
+ using namespace NppShell ::Helpers;
8
+
9
+ const wstring EditWithNppExplorerCommandHandler::GetNppExecutableFullPath ()
10
+ {
11
+ const wstring path = GetInstallationPath ();
12
+ const wstring fileName = L" \\ notepad++.exe" ;
13
+
14
+ return L" \" " + path + fileName + L" \" " ;
15
+ }
16
+
17
+ const wstring EditWithNppExplorerCommandHandler::Title ()
18
+ {
19
+ return L" Edit with Notepad++" ;
20
+ }
21
+
22
+ const wstring EditWithNppExplorerCommandHandler::Icon ()
23
+ {
24
+ const wstring fileName = GetNppExecutableFullPath ();
25
+
26
+ return fileName;
27
+ }
28
+
29
+ const wstring EditWithNppExplorerCommandHandler::GetCommandLine ()
30
+ {
31
+ const wstring fileName = GetNppExecutableFullPath ();
32
+ const wstring parameters = L" \" %1\" " ;
33
+
34
+ return fileName + L" " + parameters;
35
+ }
36
+
37
+ IFACEMETHODIMP EditWithNppExplorerCommandHandler::Invoke (IShellItemArray* psiItemArray, IBindCtx* pbc) noexcept try
38
+ {
39
+ UNREFERENCED_PARAMETER (pbc);
40
+
41
+ if (!psiItemArray)
42
+ {
43
+ return S_OK;
44
+ }
45
+
46
+ DWORD count;
47
+ RETURN_IF_FAILED (psiItemArray->GetCount (&count));
48
+
49
+ IShellItem* psi = nullptr ;
50
+ LPWSTR itemName;
51
+
52
+ for (DWORD i = 0 ; i < count; ++i)
53
+ {
54
+ psiItemArray->GetItemAt (i, &psi);
55
+ RETURN_IF_FAILED (psi->GetDisplayName (SIGDN_FILESYSPATH, &itemName));
56
+
57
+ std::wstring cmdline = this ->GetCommandLine ();
58
+ cmdline = cmdline.replace (cmdline.find (L" %1" ), 2 , itemName);
59
+
60
+ STARTUPINFO si;
61
+ PROCESS_INFORMATION pi ;
62
+
63
+ ZeroMemory (&si, sizeof (si));
64
+ si.cb = sizeof (si);
65
+ ZeroMemory (&pi , sizeof (pi ));
66
+
67
+ wchar_t * command = (LPWSTR)cmdline.c_str ();
68
+
69
+ if (!CreateProcess (nullptr , command, nullptr , nullptr , false , CREATE_NEW_PROCESS_GROUP, nullptr , nullptr , &si, &pi ))
70
+ {
71
+ return S_OK;
72
+ }
73
+
74
+ CloseHandle (pi .hProcess );
75
+ CloseHandle (pi .hThread );
76
+ }
77
+
78
+ return S_OK;
79
+ }
80
+ CATCH_RETURN ();
0 commit comments