Skip to content

Commit b3884c1

Browse files
pryrtdonho
authored andcommitted
Add NPPM_GETNPPSETTINGSDIRPATH message to get Notepad++ settings directory path
Fix notepad-plus-plus#16944, close notepad-plus-plus#16946
1 parent 4b0fc8d commit b3884c1

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,20 @@ enum Platform { PF_UNKNOWN, PF_X86, PF_X64, PF_IA64, PF_ARM64 };
10251025
// Return toolbar icon set choice as an integer value. Here are 5 possible values:
10261026
// 0 (Fluent UI: small), 1 (Fluent UI: large), 2 (Filled Fluent UI: small), 3 (Filled Fluent UI: large) and 4 (Standard icons: small).
10271027

1028-
// For RUNCOMMAND_USER
1028+
#define NPPM_GETNPPSETTINGSDIRPATH (NPPMSG + 119)
1029+
// int NPPM_GETNPPSETTINGSDIRPATH(size_t strLen, wchar_t *settingsDirPath)
1030+
// Get path for the active Notepad++ settings: it will use -settingsDir path if that's defined; if not, it will use Cloud directory if that's defined;
1031+
// if not, it will use the AppData settings directory, or finally the installation path. This allows plugins to have one interface to find out
1032+
// where the active Notepad++ settings are stored, whichever location they are currently set to.
1033+
// wParam[in]: strLen - size of allocated buffer "settingsDirPath"
1034+
// lParam[out]: settingsDirPath - Users should call it with settingsDirPath be NULL to get the required number of wchar_t (not including the terminating nul character),
1035+
// allocate settingsDirPath buffer with the return value + 1, then call it again to get the path.
1036+
// Returns the number of wchar_t copied/to copy. If the return value is 0, then the "strLen" is not enough to copy the path, or the settings path could not be determined.
1037+
//
1038+
// Note: This message is for the active Notepad++ configuration location. If you are looking for the settings directory for plugins (...\Plugins\Config\),
1039+
// use NPPM_GETPLUGINSCONFIGDIR instead.
1040+
1041+
// For RUNCOMMAND_USER
10291042
#define VAR_NOT_RECOGNIZED 0
10301043
#define FULL_CURRENT_PATH 1
10311044
#define CURRENT_DIRECTORY 2

PowerEditor/src/NppBigSwitch.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3218,6 +3218,23 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
32183218
return settingsOnCloudPath.length();
32193219
}
32203220

3221+
case NPPM_GETNPPSETTINGSDIRPATH:
3222+
{
3223+
// get the path (-settingsDir, Cloud directory, AppData or NppDir selection handled by _userPath, returned by .getUserPath())
3224+
wstring settingsDirPath = nppParam.getUserPath();
3225+
3226+
// if the LPARAM is a big enough non-null pointer, populate that memory with the path string
3227+
if (lParam != 0)
3228+
{
3229+
if (settingsDirPath.length() >= static_cast<size_t>(wParam))
3230+
return 0;
3231+
lstrcpy(reinterpret_cast<wchar_t*>(lParam), settingsDirPath.c_str());
3232+
}
3233+
3234+
// the message returns the string length
3235+
return settingsDirPath.length();
3236+
}
3237+
32213238
case NPPM_SETLINENUMBERWIDTHMODE:
32223239
{
32233240
if (lParam != LINENUMWIDTH_DYNAMIC && lParam != LINENUMWIDTH_CONSTANT)

0 commit comments

Comments
 (0)