From a87e89ea921dd7b992ea6aa21c9aeebf477f4c5b Mon Sep 17 00:00:00 2001 From: Don HO Date: Wed, 7 Nov 2018 23:30:59 +0100 Subject: [PATCH] Add new Plugin message NPPM_GETPLUGINHOMEPATH in API The new message NPPM_GETPLUGINHOMEPATH allows plugins to get plugin home root path. It's useful if plugins want to get its own path by appending which is the name of plugin without extension part. --- .../src/MISC/PluginsManager/Notepad_plus_msgs.h | 8 ++++++++ PowerEditor/src/NppBigSwitch.cpp | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h b/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h index 3a314d63e..fda67b8a8 100644 --- a/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h +++ b/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h @@ -419,6 +419,14 @@ enum Platform { PF_UNKNOWN, PF_X86, PF_X64, PF_IA64 }; // removes the assigned shortcut mapped to cmdID // returned value : TRUE if function call is successful, otherwise FALSE + #define NPPM_GETPLUGINHOMEPATH (NPPMSG + 97) + // INT NPPM_GETPLUGINHOMEPATH(size_t strLen, TCHAR *pluginRootPath) + // Get plugin home root path. It's useful if plugins want to get its own path + // by appending which is the name of plugin without extension part. + // Returns the number of TCHAR copied/to copy. + // Users should call it with pluginRootPath be NULL to get the required number of TCHAR (not including the terminating nul character), + // allocate pluginRootPath buffer with the return value + 1, then call it again to get the path. + #define RUNCOMMAND_USER (WM_USER + 3000) #define NPPM_GETFULLCURRENTPATH (RUNCOMMAND_USER + FULL_CURRENT_PATH) #define NPPM_GETCURRENTDIRECTORY (RUNCOMMAND_USER + CURRENT_DIRECTORY) diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index d14dc951b..1ca5deec7 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -2061,6 +2061,22 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa return TRUE; } + case NPPM_GETPLUGINHOMEPATH: + { + generic_string pluginHomePath = pNppParam->getPluginRootDir(); + if (lParam != 0) + { + if (pluginHomePath.length() >= static_cast(wParam)) + { + // Not message for users so no translation + ::MessageBox(hwnd, TEXT("Allocated buffer size is not enough to copy the string."), TEXT("NPPM_GETPLUGINHOMEPATH error"), MB_OK); + return 0; + } + lstrcpy(reinterpret_cast(lParam), pluginHomePath.c_str()); + } + return pluginHomePath.length(); + } + case NPPM_MSGTOPLUGIN : { return _pluginsManager.relayPluginMessages(message, wParam, lParam);