Make tray icon context menu translatable

Fix #11628, close #13241
This commit is contained in:
ArkadiuszMichalski 2023-02-25 20:30:54 +01:00 committed by Don Ho
parent b8291d4911
commit 52d3c36e35
5 changed files with 64 additions and 23 deletions

View File

@ -385,8 +385,6 @@ The comments are here for explanation, it's not necessary to translate them.
<Item id="11009" name="Size Larger to Smaller"/> <Item id="11009" name="Size Larger to Smaller"/>
</Commands> </Commands>
</Main> </Main>
<Splitter>
</Splitter>
<TabBar> <TabBar>
<Item CMDID="41003" name="Close"/> <Item CMDID="41003" name="Close"/>
<Item CMDID="0" name="Close Multiple Tabs"/> <Item CMDID="0" name="Close Multiple Tabs"/>
@ -424,6 +422,14 @@ The comments are here for explanation, it's not necessary to translate them.
<Item CMDID="44115" name="Apply Color 5"/> <Item CMDID="44115" name="Apply Color 5"/>
<Item CMDID="44110" name="Remove Color"/> <Item CMDID="44110" name="Remove Color"/>
</TabBar> </TabBar>
<TrayIcon>
<Item id="43101" name="Activate"/>
<Item id="43102" name="New"/>
<Item id="43103" name="New and Paste"/>
<Item id="43104" name="Open..."/>
<Item id="43013" name="Find in Files..."/>
<Item id="43105" name="Close Tray Icon"/>
</TrayIcon>
</Menu> </Menu>
<Dialog> <Dialog>

View File

@ -385,8 +385,6 @@ The comments are here for explanation, it's not necessary to translate them.
<Item id="11009" name="Size Larger to Smaller"/> <Item id="11009" name="Size Larger to Smaller"/>
</Commands> </Commands>
</Main> </Main>
<Splitter>
</Splitter>
<TabBar> <TabBar>
<Item CMDID="41003" name="Close"/> <Item CMDID="41003" name="Close"/>
<Item CMDID="0" name="Close Multiple Tabs"/> <Item CMDID="0" name="Close Multiple Tabs"/>
@ -424,6 +422,14 @@ The comments are here for explanation, it's not necessary to translate them.
<Item CMDID="44115" name="Apply Color 5"/> <Item CMDID="44115" name="Apply Color 5"/>
<Item CMDID="44110" name="Remove Color"/> <Item CMDID="44110" name="Remove Color"/>
</TabBar> </TabBar>
<TrayIcon>
<Item id="43101" name="Activate"/>
<Item id="43102" name="New"/>
<Item id="43103" name="New and Paste"/>
<Item id="43104" name="Open..."/>
<Item id="43013" name="Find in Files..."/>
<Item id="43105" name="Close Tray Icon"/>
</TrayIcon>
</Menu> </Menu>
<Dialog> <Dialog>

View File

@ -2597,6 +2597,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
HMENU hTrayIconMenu; // shortcut menu HMENU hTrayIconMenu; // shortcut menu
hmenu = ::LoadMenu(_pPublicInterface->getHinst(), MAKEINTRESOURCE(IDR_SYSTRAYPOPUP_MENU)); hmenu = ::LoadMenu(_pPublicInterface->getHinst(), MAKEINTRESOURCE(IDR_SYSTRAYPOPUP_MENU));
hTrayIconMenu = ::GetSubMenu(hmenu, 0); hTrayIconMenu = ::GetSubMenu(hmenu, 0);
_nativeLangSpeaker.changeLangTrayIconContexMenu(hTrayIconMenu);
SetForegroundWindow(hwnd); SetForegroundWindow(hwnd);
TrackPopupMenu(hTrayIconMenu, TPM_LEFTALIGN, p.x, p.y, 0, hwnd, NULL); TrackPopupMenu(hTrayIconMenu, TPM_LEFTALIGN, p.x, p.y, 0, hwnd, NULL);
PostMessage(hwnd, WM_NULL, 0, 0); PostMessage(hwnd, WM_NULL, 0, 0);

View File

@ -489,6 +489,33 @@ void NativeLangSpeaker::changeLangTabDropContextMenu(HMENU hCM)
} }
} }
void NativeLangSpeaker::changeLangTrayIconContexMenu(HMENU hCM)
{
if (!_nativeLangA) return;
TiXmlNodeA *tryIconMenu = _nativeLangA->FirstChild("Menu");
if (!tryIconMenu) return;
tryIconMenu = tryIconMenu->FirstChild("TrayIcon");
if (!tryIconMenu) return;
WcharMbcsConvertor& wmc = WcharMbcsConvertor::getInstance();
for (TiXmlNodeA *childNode = tryIconMenu->FirstChildElement("Item");
childNode ;
childNode = childNode->NextSibling("Item") )
{
TiXmlElementA *element = childNode->ToElement();
int id;
const char *sentinel = element->Attribute("id", &id);
const char *name = element->Attribute("name");
if (sentinel && (name && name[0]))
{
const wchar_t *nameW = wmc.char2wchar(name, _nativeLangEncoding);
::ModifyMenu(hCM, id, MF_BYCOMMAND, id, nameW);
}
}
}
void NativeLangSpeaker::changeConfigLang(HWND hDlg) void NativeLangSpeaker::changeConfigLang(HWND hDlg)
{ {

View File

@ -38,13 +38,14 @@ public:
class NativeLangSpeaker { class NativeLangSpeaker {
public: public:
NativeLangSpeaker():_nativeLangA(NULL), _nativeLangEncoding(CP_ACP), _isRTL(false), _fileName(NULL){}; NativeLangSpeaker():_nativeLangA(NULL), _nativeLangEncoding(CP_ACP), _isRTL(false), _fileName(NULL){};
void init(TiXmlDocumentA *nativeLangDocRootA, bool loadIfEnglish = false); void init(TiXmlDocumentA *nativeLangDocRootA, bool loadIfEnglish = false);
void changeConfigLang(HWND hDlg); void changeConfigLang(HWND hDlg);
void changeLangTabContextMenu(HMENU hCM); void changeLangTabContextMenu(HMENU hCM);
TiXmlNodeA * searchDlgNode(TiXmlNodeA *node, const char *dlgTagName); TiXmlNodeA * searchDlgNode(TiXmlNodeA *node, const char *dlgTagName);
bool changeDlgLang(HWND hDlg, const char *dlgTagName, char *title = NULL, size_t titleMaxSize = 0); bool changeDlgLang(HWND hDlg, const char *dlgTagName, char *title = NULL, size_t titleMaxSize = 0);
void changeLangTabDropContextMenu(HMENU hCM); void changeLangTabDropContextMenu(HMENU hCM);
void changeLangTrayIconContexMenu(HMENU hCM);
generic_string getSubMenuEntryName(const char *nodeName) const; generic_string getSubMenuEntryName(const char *nodeName) const;
generic_string getNativeLangMenuString(int itemID) const; generic_string getNativeLangMenuString(int itemID) const;
generic_string getShortcutNameString(int itemID) const; generic_string getShortcutNameString(int itemID) const;
@ -52,29 +53,29 @@ public:
void changeMenuLang(HMENU menuHandle); void changeMenuLang(HMENU menuHandle);
void changeShortcutLang(); void changeShortcutLang();
void changeStyleCtrlsLang(HWND hDlg, int *idArray, const char **translatedText); void changeStyleCtrlsLang(HWND hDlg, int *idArray, const char **translatedText);
void changeUserDefineLang(UserDefineDialog *userDefineDlg); void changeUserDefineLang(UserDefineDialog *userDefineDlg);
void changeUserDefineLangPopupDlg(HWND hDlg); void changeUserDefineLangPopupDlg(HWND hDlg);
void changeFindReplaceDlgLang(FindReplaceDlg & findReplaceDlg); void changeFindReplaceDlgLang(FindReplaceDlg & findReplaceDlg);
void changePrefereceDlgLang(PreferenceDlg & preference); void changePrefereceDlgLang(PreferenceDlg & preference);
void changePluginsAdminDlgLang(PluginsAdminDlg & pluginsAdminDlg); void changePluginsAdminDlgLang(PluginsAdminDlg & pluginsAdminDlg);
bool getDoSaveOrNotStrings(generic_string& title, generic_string& msg); bool getDoSaveOrNotStrings(generic_string& title, generic_string& msg);
bool isRTL() const { bool isRTL() const {
return _isRTL; return _isRTL;
}; };
const char * getFileName() const { const char * getFileName() const {
return _fileName; return _fileName;
}; };
const TiXmlNodeA * getNativeLangA() { const TiXmlNodeA * getNativeLangA() {
return _nativeLangA; return _nativeLangA;
}; };
int getLangEncoding() const { int getLangEncoding() const {
return _nativeLangEncoding; return _nativeLangEncoding;
}; };
bool getMsgBoxLang(const char *msgBoxTagName, generic_string & title, generic_string & message); bool getMsgBoxLang(const char *msgBoxTagName, generic_string & title, generic_string & message);
generic_string getShortcutMapperLangStr(const char *nodeName, const TCHAR *defaultStr) const; generic_string getShortcutMapperLangStr(const char *nodeName, const TCHAR *defaultStr) const;
generic_string getProjectPanelLangMenuStr(const char * nodeName, int cmdID, const TCHAR *defaultStr) const; generic_string getProjectPanelLangMenuStr(const char * nodeName, int cmdID, const TCHAR *defaultStr) const;
@ -87,8 +88,8 @@ public:
private: private:
TiXmlNodeA *_nativeLangA; TiXmlNodeA *_nativeLangA;
int _nativeLangEncoding; int _nativeLangEncoding;
bool _isRTL; bool _isRTL;
const char *_fileName; const char *_fileName;
}; };