Skip to content

Commit ce78dce

Browse files
committed
refactor: encapsulate settings management into a dedicated Settings class
1 parent 8f52019 commit ce78dce

17 files changed

Lines changed: 653 additions & 490 deletions

Explorer.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@
267267
</ClCompile>
268268
<ClCompile Include="src\Explorer\PropDlg.cpp" />
269269
<ClCompile Include="src\Explorer\QuickOpenDialog.cpp" />
270+
<ClCompile Include="src\Explorer\Settings.cpp" />
270271
<ClCompile Include="src\Explorer\ThemeRenderer.cpp" />
271272
<ClCompile Include="src\Explorer\ToolBar.cpp" />
272273
<ClCompile Include="src\Explorer\TreeView.cpp" />
@@ -304,6 +305,7 @@
304305
<ClInclude Include="src\Explorer\PropDlg.h" />
305306
<ClInclude Include="src\Explorer\QuickOpenDialog.h" />
306307
<ClInclude Include="src\Explorer\resource.h" />
308+
<ClInclude Include="src\Explorer\Settings.h" />
307309
<ClInclude Include="src\Explorer\StringUtil.h" />
308310
<ClInclude Include="src\Explorer\ThemeRenderer.h" />
309311
<ClInclude Include="src\Explorer\ToolBar.h" />

Explorer.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@
105105
<ClCompile Include="src\Explorer\Editor.cpp">
106106
<Filter>src\Explorer</Filter>
107107
</ClCompile>
108+
<ClCompile Include="src\Explorer\Settings.cpp">
109+
<Filter>src\Explorer</Filter>
110+
</ClCompile>
108111
</ItemGroup>
109112
<ItemGroup>
110113
<ResourceCompile Include="src\Explorer\version.rc">
@@ -247,6 +250,9 @@
247250
<ClInclude Include="src\Explorer\IEditor.h">
248251
<Filter>src\Explorer</Filter>
249252
</ClInclude>
253+
<ClInclude Include="src\Explorer\Settings.h">
254+
<Filter>src\Explorer</Filter>
255+
</ClInclude>
250256
</ItemGroup>
251257
<ItemGroup>
252258
<Image Include="src\Explorer\res\explore.bmp">

src/Explorer/ContextMenu.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
3737
#include "../NppPlugin/nppexec_msgs.h"
3838

3939
/* global explorer params */
40-
extern ExProp exProp;
40+
extern Settings settings;
4141

4242
namespace {
4343
constexpr UINT_PTR CONTEXT_MENU_SUBCLASS_ID = 1;
@@ -231,13 +231,13 @@ UINT ContextMenu::ShowContextMenu(HINSTANCE hInst, HWND hWndNpp, HWND hWndParent
231231
.srcModuleName = PathFindFileName(szPath),
232232
.info = &dwExecVer,
233233
};
234-
Editor::Instance().SendMsgToPlugin(exProp.nppExecProp.szAppName, &ci);
234+
Editor::Instance().SendMsgToPlugin(settings.GetNppExecProp().szAppName, &ci);
235235

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

242242
/* Add notepad menu items */
243243
if (isFolder) {
@@ -260,14 +260,14 @@ UINT ContextMenu::ShowContextMenu(HINSTANCE hInst, HWND hWndNpp, HWND hWndParent
260260
_strNppScripts.clear();
261261

262262
/* add backslash if necessary */
263-
if ((exProp.nppExecProp.szScriptPath[0] == '.') &&
264-
(exProp.nppExecProp.szScriptPath[1] == '.')) {
263+
if ((settings.GetNppExecProp().szScriptPath[0] == '.') &&
264+
(settings.GetNppExecProp().szScriptPath[1] == '.')) {
265265
/* module path of notepad */
266266
GetModuleFileName(hInst, TEMP, sizeof(TEMP));
267267
PathRemoveFileSpec(TEMP);
268-
PathAppend(TEMP, exProp.nppExecProp.szScriptPath);
268+
PathAppend(TEMP, settings.GetNppExecProp().szScriptPath.c_str());
269269
} else {
270-
_tcsncpy(TEMP, exProp.nppExecProp.szScriptPath, MAX_PATH-1);
270+
_tcsncpy(TEMP, settings.GetNppExecProp().szScriptPath.c_str(), MAX_PATH-1);
271271
}
272272
if (TEMP[wcslen(TEMP) - 1] != '\\') {
273273
wcscat(TEMP, L"\\");
@@ -298,7 +298,7 @@ UINT ContextMenu::ShowContextMenu(HINSTANCE hInst, HWND hWndNpp, HWND hWndParent
298298
}
299299
::AppendMenu(hMainMenu, MF_STRING, CTX_OPEN_CMD, L"Open Command Window Here");
300300
::AppendMenu(hMainMenu, MF_STRING, CTX_SET_AS_ROOT_FOLDER, L"Set as Root Folder");
301-
if (!exProp.rootFolder.empty()) {
301+
if (!settings.GetRootFolder().empty()) {
302302
::AppendMenu(hMainMenu, MF_STRING, CTX_GO_TO_ROOT_FOLDER, L"Go to Root Folder");
303303
::AppendMenu(hMainMenu, MF_STRING, CTX_CLEAR_ROOT_FOLDER, L"Clear Root Folder");
304304
}
@@ -848,7 +848,7 @@ void ContextMenu::openPrompt()
848848
path.erase(pos, path.size());
849849
}
850850
}
851-
::ShellExecute(_hWndNpp, L"open", exProp.cphProgram.szAppName, nullptr, path.c_str(), SW_SHOW);
851+
::ShellExecute(_hWndNpp, L"open", settings.GetCphProgram().szAppName.c_str(), nullptr, path.c_str(), SW_SHOW);
852852
}
853853
}
854854

@@ -864,18 +864,18 @@ void ContextMenu::setRootFolder()
864864
}
865865
}
866866

867-
exProp.rootFolder = path;
867+
settings.SetRootFolder(path);
868868
}
869869

870870
void ContextMenu::gotoRootFolder()
871871
{
872872
extern ExplorerDialog explorerDlg;
873-
explorerDlg.gotoFileLocation(exProp.rootFolder);
873+
explorerDlg.gotoFileLocation(settings.GetRootFolder());
874874
}
875875

876876
void ContextMenu::clearRootFolder()
877877
{
878-
exProp.rootFolder.clear();
878+
settings.SetRootFolder(L"");
879879
}
880880

881881

@@ -974,14 +974,14 @@ void ContextMenu::openScriptPath(HMODULE hInst)
974974
{
975975
WCHAR TEMP[MAX_PATH];
976976

977-
if (exProp.nppExecProp.szScriptPath[0] == '.') {
977+
if (settings.GetNppExecProp().szScriptPath[0] == '.') {
978978
/* module path of notepad */
979979
GetModuleFileName(hInst, TEMP, _countof(TEMP));
980980
PathRemoveFileSpec(TEMP);
981-
PathAppend(TEMP, exProp.nppExecProp.szScriptPath);
981+
PathAppend(TEMP, settings.GetNppExecProp().szScriptPath.c_str());
982982
}
983983
else {
984-
wcscpy(TEMP, exProp.nppExecProp.szScriptPath);
984+
wcscpy(TEMP, settings.GetNppExecProp().szScriptPath.c_str());
985985
}
986986
::SendMessage(_hWndParent, EXM_OPENDIR, 0, (LPARAM)TEMP);
987987
}
@@ -991,14 +991,14 @@ void ContextMenu::startNppExec(HMODULE hInst, UINT cmdID)
991991
WCHAR szScriptPath[MAX_PATH];
992992

993993
/* concatinate execute command */
994-
if (exProp.nppExecProp.szScriptPath[0] == '.') {
994+
if (settings.GetNppExecProp().szScriptPath[0] == '.') {
995995
/* module path of notepad */
996996
GetModuleFileName(hInst, szScriptPath, _countof(szScriptPath));
997997
PathRemoveFileSpec(szScriptPath);
998-
PathAppend(szScriptPath, exProp.nppExecProp.szScriptPath);
998+
PathAppend(szScriptPath, settings.GetNppExecProp().szScriptPath.c_str());
999999
}
10001000
else {
1001-
wcscpy(szScriptPath, exProp.nppExecProp.szScriptPath);
1001+
wcscpy(szScriptPath, settings.GetNppExecProp().szScriptPath.c_str());
10021002
}
10031003
if (szScriptPath[wcslen(szScriptPath) - 1] != '\\') {
10041004
wcscat(szScriptPath, L"\\");

0 commit comments

Comments
 (0)