Skip to content

Commit 8f52019

Browse files
committed
refactor: modernize IEditor interface with standard C++ types
- Replace Win32 types (BOOL, INT, LRESULT) with standard types (bool, int, intptr_t). - Update file path handling to use std::filesystem::path across the interface and implementation. - Refactor client code (Explorer, Dialogs, ContextMenu) to align with new method signatures. - Retain HWND and COLORREF for compatibility with existing UI logic. - Remove legacy SendMessage calls by abstracting them into semantic IEditor methods.
1 parent 4408823 commit 8f52019

12 files changed

Lines changed: 494 additions & 382 deletions

Explorer.vcxproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<ItemGroup Label="ProjectConfigurations">
44
<ProjectConfiguration Include="Debug|Win32">
@@ -257,7 +257,7 @@
257257
<ClCompile Include="src\Explorer\HelpDialog.cpp" />
258258
<ClCompile Include="src\Explorer\ImageListSet.cpp" />
259259
<ClCompile Include="src\Explorer\NewDlg.cpp" />
260-
<ClCompile Include="src\Explorer\NppInterface.cpp" />
260+
<ClCompile Include="src\Explorer\Editor.cpp" />
261261
<ClCompile Include="src\Explorer\OptionDialog.cpp" />
262262
<ClCompile Include="src\Explorer\pch.cpp">
263263
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
@@ -297,7 +297,8 @@
297297
<ClInclude Include="src\Explorer\HelpDialog.h" />
298298
<ClInclude Include="src\Explorer\ImageListSet.h" />
299299
<ClInclude Include="src\Explorer\NewDlg.h" />
300-
<ClInclude Include="src\Explorer\NppInterface.h" />
300+
<ClInclude Include="src\Explorer\Editor.h" />
301+
<ClInclude Include="src\Explorer\IEditor.h" />
301302
<ClInclude Include="src\Explorer\OptionDialog.h" />
302303
<ClInclude Include="src\Explorer\pch.h" />
303304
<ClInclude Include="src\Explorer\PropDlg.h" />

Explorer.vcxproj.filters

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@
7272
<ClCompile Include="src\Explorer\NewDlg.cpp">
7373
<Filter>src\Explorer</Filter>
7474
</ClCompile>
75-
<ClCompile Include="src\Explorer\NppInterface.cpp">
76-
<Filter>src\Explorer</Filter>
77-
</ClCompile>
7875
<ClCompile Include="src\Explorer\OptionDialog.cpp">
7976
<Filter>src\Explorer</Filter>
8077
</ClCompile>
@@ -105,6 +102,9 @@
105102
<ClCompile Include="src\Explorer\UTF16Stream.cpp">
106103
<Filter>src\Explorer</Filter>
107104
</ClCompile>
105+
<ClCompile Include="src\Explorer\Editor.cpp">
106+
<Filter>src\Explorer</Filter>
107+
</ClCompile>
108108
</ItemGroup>
109109
<ItemGroup>
110110
<ResourceCompile Include="src\Explorer\version.rc">
@@ -166,9 +166,6 @@
166166
<ClInclude Include="src\Explorer\NewDlg.h">
167167
<Filter>src\Explorer</Filter>
168168
</ClInclude>
169-
<ClInclude Include="src\Explorer\NppInterface.h">
170-
<Filter>src\Explorer</Filter>
171-
</ClInclude>
172169
<ClInclude Include="src\Explorer\OptionDialog.h">
173170
<Filter>src\Explorer</Filter>
174171
</ClInclude>
@@ -244,6 +241,12 @@
244241
<ClInclude Include="src\Explorer\UTF16Stream.h">
245242
<Filter>src\Explorer</Filter>
246243
</ClInclude>
244+
<ClInclude Include="src\Explorer\Editor.h">
245+
<Filter>src\Explorer</Filter>
246+
</ClInclude>
247+
<ClInclude Include="src\Explorer\IEditor.h">
248+
<Filter>src\Explorer</Filter>
249+
</ClInclude>
247250
</ItemGroup>
248251
<ItemGroup>
249252
<Image Include="src\Explorer\res\explore.bmp">

Explorer.vcxproj.user

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3-
43
<!--
54
Rename PROJECTNAME to the same as the *.vcxproj file in your project.
65
@@ -17,14 +16,23 @@
1716
set ZIPCMD=zip
1817
set ZIPCMD=7z a -tzip
1918
-->
20-
19+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
20+
<LocalDebuggerCommand>C:\Program Files\Notepad++\notepad++.exe</LocalDebuggerCommand>
21+
<LocalDebuggerWorkingDirectory>C:\Program Files\Notepad++\</LocalDebuggerWorkingDirectory>
22+
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
23+
</PropertyGroup>
24+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
25+
<LocalDebuggerCommand>C:\Program Files\Notepad++\notepad++.exe</LocalDebuggerCommand>
26+
<LocalDebuggerWorkingDirectory>C:\Program Files\Notepad++\</LocalDebuggerWorkingDirectory>
27+
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
28+
</PropertyGroup>
2129
<Target Name="Zip" DependsOnTargets="Build">
2230
<PropertyGroup>
23-
<ZipCmd Condition="'$(ZIPCMD)' == ''">zip</ZipCmd>
31+
<ZipCmd Condition="'$(ZIPCMD)' == ''">zip</ZipCmd>
2432
</PropertyGroup>
25-
<Exec Command="if not exist $(OutDir)$(TargetName) mkdir $(OutDir)$(TargetName)"/>
26-
<Exec Command="copy $(OutDir)$(TargetName)$(TargetExt) $(OutDir)$(TargetName)"/>
27-
<Exec Command="for /f %%i in ('powershell -NoProfile -Command &quot;(Get-Item $(OutDir)$(TargetName)$(TargetExt)).VersionInfo.ProductVersion&quot;') do del $(OutDir)$(TargetName)-v%%i-$(Platform).zip"/>
28-
<Exec Command="for /f %%i in ('powershell -NoProfile -Command &quot;(Get-Item $(OutDir)$(TargetName)$(TargetExt)).VersionInfo.ProductVersion&quot;') do cd $(OutDir)$(TargetName) %26%26 $(ZIPCMD) -r ..\$(TargetName)-v%%i-$(Platform).zip *"/>
33+
<Exec Command="if not exist $(OutDir)$(TargetName) mkdir $(OutDir)$(TargetName)" />
34+
<Exec Command="copy $(OutDir)$(TargetName)$(TargetExt) $(OutDir)$(TargetName)" />
35+
<Exec Command="for /f %%i in ('powershell -NoProfile -Command &quot;(Get-Item $(OutDir)$(TargetName)$(TargetExt)).VersionInfo.ProductVersion&quot;') do del $(OutDir)$(TargetName)-v%%i-$(Platform).zip" />
36+
<Exec Command="for /f %%i in ('powershell -NoProfile -Command &quot;(Get-Item $(OutDir)$(TargetName)$(TargetExt)).VersionInfo.ProductVersion&quot;') do cd $(OutDir)$(TargetName) %26%26 $(ZIPCMD) -r ..\$(TargetName)-v%%i-$(Platform).zip *" />
2937
</Target>
30-
</Project>
38+
</Project>

src/Explorer/ContextMenu.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/***********************************************************\
1+
/***********************************************************\
22
* Original in MFC by Roman Engels Copyright 2003 *
33
* *
44
* http://www.codeproject.com/shell/shellcontextmenu.asp *
@@ -31,7 +31,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
3131
#include "ExplorerDialog.h"
3232
#include "FavesDialog.h"
3333
#include "NewDlg.h"
34-
#include "NppInterface.h"
34+
#include "Editor.h"
3535
#include "QuickOpenDialog.h"
3636
#include "../NppPlugin/menuCmdID.h"
3737
#include "../NppPlugin/nppexec_msgs.h"
@@ -231,13 +231,13 @@ UINT ContextMenu::ShowContextMenu(HINSTANCE hInst, HWND hWndNpp, HWND hWndParent
231231
.srcModuleName = PathFindFileName(szPath),
232232
.info = &dwExecVer,
233233
};
234-
::SendMessage(hWndNpp, NPPM_MSGTOPLUGIN, (WPARAM)exProp.nppExecProp.szAppName, (LPARAM)&ci);
234+
Editor::Instance().SendMsgToPlugin(exProp.nppExecProp.szAppName, &ci);
235235

236236
/* get acivity state of NppExec */
237237
ci.internalMsg = NPEM_GETSTATE;
238238
ci.srcModuleName = PathFindFileName(szPath);
239239
ci.info = &dwExecState;
240-
::SendMessage(hWndNpp, NPPM_MSGTOPLUGIN, (WPARAM)exProp.nppExecProp.szAppName, (LPARAM)&ci);
240+
Editor::Instance().SendMsgToPlugin(exProp.nppExecProp.szAppName, &ci);
241241

242242
/* Add notepad menu items */
243243
if (isFolder) {
@@ -306,7 +306,7 @@ UINT ContextMenu::ShowContextMenu(HINSTANCE hInst, HWND hWndNpp, HWND hWndParent
306306
::AppendMenu(hMainMenu, MF_STRING, CTX_QUICK_OPEN, L"Quick Open...");
307307
::InsertMenu(hMainMenu, 3, MF_BYPOSITION | MF_SEPARATOR, 0, 0);
308308
::AppendMenu(hMainMenu, MF_STRING, CTX_ADD_TO_FAVES, L"Add to 'Favorites'...");
309-
std::wstring currentDirectory = NppInterface::getCurrentDirectory();
309+
std::wstring currentDirectory = Editor::Instance().GetCurrentDirectory().wstring();
310310
if (!currentDirectory.empty()) {
311311
::AppendMenu(hMainMenu, MF_STRING, CTX_RELATIVE_PATH, L"Relative File Path(s) to Clipboard");
312312
}
@@ -754,7 +754,7 @@ void ContextMenu::newFile()
754754
newFilePath /= szFileName;
755755

756756
::CloseHandle(::CreateFile(newFilePath.c_str(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr));
757-
::SendMessage(_hWndNpp, NPPM_DOOPEN, 0, (LPARAM)newFilePath.c_str());
757+
Editor::Instance().DoOpen(newFilePath);
758758
bLeave = TRUE;
759759
}
760760
}
@@ -798,23 +798,23 @@ void ContextMenu::newFolder()
798798

799799
void ContextMenu::findInFiles()
800800
{
801-
::SendMessage(_hWndNpp, NPPM_LAUNCHFINDINFILESDLG, (WPARAM)_strFirstElement.c_str(), NULL);
801+
Editor::Instance().LaunchFindFileDialog(_strFirstElement);
802802
}
803803

804804
void ContextMenu::openFile()
805805
{
806806
for (const auto &path : _strArray) {
807-
::SendMessage(_hWndNpp, NPPM_DOOPEN, 0, (LPARAM)path.c_str());
807+
Editor::Instance().DoOpen(path);
808808
}
809809
}
810810

811811
void ContextMenu::openFileInOtherView()
812812
{
813813
BOOL isFirstItem = TRUE;
814814
for (const auto &path : _strArray) {
815-
::SendMessage(_hWndNpp, NPPM_DOOPEN, 0, (LPARAM)path.c_str());
815+
Editor::Instance().DoOpen(path);
816816
if (isFirstItem) {
817-
::SendMessage(_hWndNpp, WM_COMMAND, IDM_VIEW_GOTO_ANOTHER_VIEW, 0);
817+
Editor::Instance().RunMenuCommand(IDM_VIEW_GOTO_ANOTHER_VIEW);
818818
isFirstItem = FALSE;
819819
}
820820
}
@@ -902,7 +902,7 @@ void ContextMenu::addToFaves()
902902

903903
void ContextMenu::addRelativePathsCB()
904904
{
905-
const std::wstring currentDirectory = NppInterface::getCurrentDirectory();
905+
const std::wstring currentDirectory = Editor::Instance().GetCurrentDirectory().wstring();
906906
if (currentDirectory.empty()) {
907907
return;
908908
}
@@ -1054,7 +1054,7 @@ void ContextMenu::startNppExec(HMODULE hInst, UINT cmdID)
10541054
.srcModuleName = PathFindFileName(szPath),
10551055
.info = &npep,
10561056
};
1057-
::SendMessage(_hWndNpp, NPPM_MSGTOPLUGIN, (WPARAM)szAppName, (LPARAM)&ci);
1057+
Editor::Instance().SendMsgToPlugin(szAppName, &ci);
10581058

10591059
if (npep.dwResult != NPE_NPPEXEC_OK) {
10601060
::MessageBox(_hWndNpp, L"NppExec currently in use!", L"Error", MB_OK);

0 commit comments

Comments
 (0)