Skip to content

Commit

Permalink
Add new plugin command & notification while native lang being changed
Browse files Browse the repository at this point in the history
  • Loading branch information
donho committed Aug 27, 2024
1 parent 8e26e08 commit 52f306e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
16 changes: 16 additions & 0 deletions PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,15 @@ enum Platform { PF_UNKNOWN, PF_X86, PF_X64, PF_IA64, PF_ARM64 };
// lParam[in]: newName - the desired new name of the tab
// Return TRUE upon success; FALSE upon failure

#define NPPM_GETNATIVELANGFILENAME (NPPMSG + 116)
// int NPPM_GETNATIVELANGFILENAME(size_t strLen, char* nativeLangFileName)
// Get the Current native language file name string.
// Users should call it with nativeLangFileName as NULL to get the required number of char (not including the terminating nul character),
// allocate commandLineStr buffer with the return value + 1, then call it again to get the current native language file name string.
// wParam[in]: strLen is "commandLineStr" buffer length
// lParam[out]: commandLineStr recieves all copied native language file name string
// Return the number of char copied/to copy

// For RUNCOMMAND_USER
#define VAR_NOT_RECOGNIZED 0
#define FULL_CURRENT_PATH 1
Expand Down Expand Up @@ -1196,3 +1205,10 @@ enum Platform { PF_UNKNOWN, PF_X86, PF_X64, PF_IA64, PF_ARM64 };
//scnNotification->nmhdr.code = NPPN_GLOBALMODIFIED;
//scnNotification->nmhdr.hwndFrom = BufferID;
//scnNotification->nmhdr.idFrom = 0; // preserved for the future use, must be zero

#define NPPN_NATIVELANGCHANGED (NPPN_FIRST + 31) // To notify plugins that the current native language is just changed to another one.
// Use NPPM_GETNATIVELANGFILENAME to get current native language file name.
// Use NPPM_GETMENUHANDLE(NPPPLUGINMENU, 0) to get submenu "Plugins" handle (HMENU)
//scnNotification->nmhdr.code = NPPN_NATIVELANGCHANGED;
//scnNotification->nmhdr.hwndFrom = hwndNpp
//scnNotification->nmhdr.idFrom = 0; // preserved for the future use, must be zero
7 changes: 7 additions & 0 deletions PowerEditor/src/Notepad_plus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7248,6 +7248,13 @@ bool Notepad_plus::reloadLang()
}

_lastRecentFileList.setLangEncoding(_nativeLangSpeaker.getLangEncoding());

SCNotification scnN{};
scnN.nmhdr.code = NPPN_NATIVELANGCHANGED;
scnN.nmhdr.hwndFrom = _pPublicInterface->getHSelf();
scnN.nmhdr.idFrom = 0;
_pluginsManager.notify(&scnN);

return true;
}

Expand Down
14 changes: 14 additions & 0 deletions PowerEditor/src/NppBigSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3747,6 +3747,20 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
return TRUE;
}

case NPPM_GETNATIVELANGFILENAME:
{
string fileName = _nativeLangSpeaker.getFileName();
if (lParam != 0)
{
if (fileName.length() >= static_cast<size_t>(wParam))
{
return 0;
}
strcpy(reinterpret_cast<char*>(lParam), fileName.c_str());
}
return fileName.length();
}

default:
{
if (message == WDN_NOTIFY)
Expand Down

0 comments on commit 52f306e

Please sign in to comment.