From 5501485c0bce1f5f8e3402374d96e5b830ef413e Mon Sep 17 00:00:00 2001 From: ozone10 Date: Mon, 1 Jul 2024 19:56:21 +0200 Subject: [PATCH] Add ability to pre-populate the predefined color sets to the custom tone Allow to reset custom tone colors with other predefined color sets. Fix #15055, close #15387 --- PowerEditor/src/NppDarkMode.cpp | 51 ++++++--- PowerEditor/src/NppDarkMode.h | 10 +- .../WinControls/ContextMenu/ContextMenu.cpp | 51 ++++++--- .../src/WinControls/ContextMenu/ContextMenu.h | 17 ++- .../src/WinControls/Preference/preference.rc | 2 +- .../WinControls/Preference/preferenceDlg.cpp | 107 ++++++++++++++++++ .../WinControls/Preference/preferenceDlg.h | 6 + .../WinControls/Preference/preference_rc.h | 6 + PowerEditor/src/localization.cpp | 48 +++++++- PowerEditor/src/localization.h | 1 + 10 files changed, 256 insertions(+), 43 deletions(-) diff --git a/PowerEditor/src/NppDarkMode.cpp b/PowerEditor/src/NppDarkMode.cpp index 5ba302762132..b2f3402af1d2 100644 --- a/PowerEditor/src/NppDarkMode.cpp +++ b/PowerEditor/src/NppDarkMode.cpp @@ -503,7 +503,7 @@ namespace NppDarkMode g_advOptions._enableWindowsMode = enable; } - void setThemeName(const generic_string& newThemeName) + void setThemeName(const std::wstring& newThemeName) { if (NppDarkMode::isEnabled()) g_advOptions._darkDefaults._xmlFileName = newThemeName; @@ -511,7 +511,7 @@ namespace NppDarkMode g_advOptions._lightDefaults._xmlFileName = newThemeName; } - generic_string getThemeName() + std::wstring getThemeName() { auto& theme = NppDarkMode::isEnabled() ? g_advOptions._darkDefaults._xmlFileName : g_advOptions._lightDefaults._xmlFileName; return (lstrcmp(theme.c_str(), L"stylers.xml") == 0) ? L"" : theme; @@ -728,11 +728,36 @@ namespace NppDarkMode getTheme().change(clrs); } - Colors getDarkModeDefaultColors() + Colors getDarkModeDefaultColors(ColorTone colorTone) { - return darkColors; + switch (colorTone) + { + case NppDarkMode::ColorTone::redTone: + return darkRedColors; + + case NppDarkMode::ColorTone::greenTone: + return darkGreenColors; + + case NppDarkMode::ColorTone::blueTone: + return darkBlueColors; + + case NppDarkMode::ColorTone::purpleTone: + return darkPurpleColors; + + case NppDarkMode::ColorTone::cyanTone: + return darkCyanColors; + + case NppDarkMode::ColorTone::oliveTone: + return darkOliveColors; + + case NppDarkMode::ColorTone::customizedTone: + case NppDarkMode::ColorTone::blackTone: + default: + return darkColors; + } } + void changeCustomTheme(const Colors& colors) { tCustom.change(colors); @@ -1612,7 +1637,7 @@ namespace NppDarkMode SetBkMode(hdc, TRANSPARENT); - TCHAR label[MAX_PATH]{}; + wchar_t label[MAX_PATH]{}; TCITEM tci{}; tci.mask = TCIF_TEXT; tci.pszText = label; @@ -1971,7 +1996,7 @@ namespace NppDarkMode ::SetTextColor(hdc, isWindowEnabled ? NppDarkMode::getTextColor() : NppDarkMode::getDisabledTextColor()); ::SetBkColor(hdc, NppDarkMode::getBackgroundColor()); auto bufferLen = static_cast(::SendMessage(hWnd, CB_GETLBTEXTLEN, index, 0)); - TCHAR* buffer = new TCHAR[(bufferLen + 1)]; + wchar_t* buffer = new wchar_t[(bufferLen + 1)]; ::SendMessage(hWnd, CB_GETLBTEXT, index, reinterpret_cast(buffer)); RECT rcText = rcTextBg; @@ -2002,7 +2027,7 @@ namespace NppDarkMode ::SetTextColor(hdc, isWindowEnabled ? colorEnabledText : NppDarkMode::getDisabledTextColor()); ::SetBkColor(hdc, isHot ? NppDarkMode::getHotBackgroundColor() : NppDarkMode::getBackgroundColor()); ::FillRect(hdc, &rcArrow, isHot ? NppDarkMode::getHotBackgroundBrush() : NppDarkMode::getBackgroundBrush()); - TCHAR arrow[] = L"˅"; + wchar_t arrow[] = L"˅"; ::DrawText(hdc, arrow, -1, &rcArrow, DT_NOPREFIX | DT_CENTER | DT_VCENTER | DT_SINGLELINE | DT_NOCLIP); ::SetBkColor(hdc, NppDarkMode::getBackgroundColor()); @@ -2275,7 +2300,7 @@ namespace NppDarkMode bool subclassTabUpDownControl(HWND hwnd) { constexpr size_t classNameLen = 16; - TCHAR className[classNameLen]{}; + wchar_t className[classNameLen]{}; GetClassName(hwnd, className, classNameLen); if (wcscmp(className, UPDOWN_CLASS) == 0) { @@ -2301,7 +2326,7 @@ namespace NppDarkMode EnumChildWindows(hwndParent, [](HWND hwnd, LPARAM lParam) WINAPI_LAMBDA { auto& p = *reinterpret_cast(lParam); constexpr size_t classNameLen = 32; - TCHAR className[classNameLen]{}; + wchar_t className[classNameLen]{}; GetClassName(hwnd, className, classNameLen); if (wcscmp(className, WC_BUTTON) == 0) @@ -2881,7 +2906,7 @@ namespace NppDarkMode if (NppDarkMode::isEnabled()) { constexpr size_t classNameLen = 16; - TCHAR className[classNameLen]{}; + wchar_t className[classNameLen]{}; auto hwndEdit = reinterpret_cast(lParam); GetClassName(hwndEdit, className, classNameLen); if (wcscmp(className, WC_EDIT) == 0) @@ -2910,7 +2935,7 @@ namespace NppDarkMode case NM_CUSTOMDRAW: { constexpr size_t classNameLen = 16; - TCHAR className[classNameLen]{}; + wchar_t className[classNameLen]{}; GetClassName(nmhdr->hwndFrom, className, classNameLen); if (wcscmp(className, TOOLBARCLASSNAME) == 0) @@ -3059,7 +3084,7 @@ namespace NppDarkMode auto nmhdr = reinterpret_cast(lParam); constexpr size_t classNameLen = 16; - TCHAR className[classNameLen]{}; + wchar_t className[classNameLen]{}; GetClassName(nmhdr->hwndFrom, className, classNameLen); switch (nmhdr->code) @@ -3305,7 +3330,7 @@ namespace NppDarkMode static BOOL CALLBACK enumAutocompleteProc(HWND hwnd, LPARAM /*lParam*/) { constexpr size_t classNameLen = 16; - TCHAR className[classNameLen]{}; + wchar_t className[classNameLen]{}; GetClassName(hwnd, className, classNameLen); if ((wcscmp(className, L"ListBoxX") == 0)) { diff --git a/PowerEditor/src/NppDarkMode.h b/PowerEditor/src/NppDarkMode.h index 8dbab843ae6b..a5ddfed94702 100644 --- a/PowerEditor/src/NppDarkMode.h +++ b/PowerEditor/src/NppDarkMode.h @@ -16,9 +16,9 @@ #pragma once +#include #include -#include "Common.h" // for generic_string namespace NppDarkMode { @@ -81,7 +81,7 @@ namespace NppDarkMode struct AdvOptDefaults { - generic_string _xmlFileName; + std::wstring _xmlFileName; int _toolBarIconSet = -1; int _tabIconSet = -1; bool _tabUseTheme = false; @@ -110,8 +110,8 @@ namespace NppDarkMode bool isWindowsModeEnabled(); void setWindowsMode(bool enable); - generic_string getThemeName(); - void setThemeName(const generic_string& newThemeName); + std::wstring getThemeName(); + void setThemeName(const std::wstring& newThemeName); int getToolBarIconSet(bool useDark); void setToolBarIconSet(int state2Set, bool useDark); int getTabIconSet(bool useDark); @@ -173,7 +173,7 @@ namespace NppDarkMode void setHotEdgeColor(COLORREF c); void setDisabledEdgeColor(COLORREF c); - Colors getDarkModeDefaultColors(); + Colors getDarkModeDefaultColors(ColorTone colorTone = ColorTone::blackTone); void changeCustomTheme(const Colors& colors); // handle events diff --git a/PowerEditor/src/WinControls/ContextMenu/ContextMenu.cpp b/PowerEditor/src/WinControls/ContextMenu/ContextMenu.cpp index 01638db4c678..2db0d04cd836 100644 --- a/PowerEditor/src/WinControls/ContextMenu/ContextMenu.cpp +++ b/PowerEditor/src/WinControls/ContextMenu/ContextMenu.cpp @@ -20,7 +20,7 @@ #include "Parameters.h" #include "localization.h" -MenuItemUnit::MenuItemUnit(unsigned long cmdID, const TCHAR *itemName, const TCHAR *parentFolderName) : _cmdID(cmdID) +MenuItemUnit::MenuItemUnit(unsigned long cmdID, const wchar_t* itemName, const wchar_t* parentFolderName) : _cmdID(cmdID) { if (!itemName) _itemName.clear(); @@ -33,27 +33,15 @@ MenuItemUnit::MenuItemUnit(unsigned long cmdID, const TCHAR *itemName, const TCH _parentFolderName = parentFolderName; } - -ContextMenu::~ContextMenu() -{ - if (isCreated()) - { - for (size_t i = 0, len = _subMenus.size(); i < len; ++i) - ::DestroyMenu(_subMenus[i]); - ::DestroyMenu(_hMenu); - } -} - - void ContextMenu::create(HWND hParent, const std::vector & menuItemArray, const HMENU mainMenuHandle, bool copyLink) { _hParent = hParent; _hMenu = ::CreatePopupMenu(); bool lastIsSep = false; HMENU hParentFolder = NULL; - generic_string currentParentFolderStr; + std::wstring currentParentFolderStr; int j = 0; - MENUITEMINFO mii; + MENUITEMINFO mii{}; for (size_t i = 0, len = menuItemArray.size(); i < len; ++i) { @@ -127,17 +115,46 @@ void ContextMenu::create(HWND hParent, const std::vector & menuIte if (copyLink && (item._cmdID == IDM_EDIT_COPY)) { NativeLangSpeaker* nativeLangSpeaker = NppParameters::getInstance().getNativeLangSpeaker(); - generic_string localized = nativeLangSpeaker->getNativeLangMenuString(IDM_EDIT_COPY_LINK); + std::wstring localized = nativeLangSpeaker->getNativeLangMenuString(IDM_EDIT_COPY_LINK); if (localized.length() == 0) localized = L"Copy link"; memset(&mii, 0, sizeof(mii)); mii.cbSize = sizeof(MENUITEMINFO); mii.fMask = MIIM_ID | MIIM_STRING | MIIM_STATE; mii.wID = IDM_EDIT_COPY_LINK; - mii.dwTypeData = (TCHAR*) localized.c_str(); + mii.dwTypeData = (wchar_t*) localized.c_str(); mii.fState = MFS_ENABLED; int c = GetMenuItemCount(_hMenu); SetMenuItemInfo(_hMenu, c - 1, TRUE, & mii); } } } + +void ContextMenu::display(HWND hwnd) const +{ + RECT rcItem{}; + ::GetClientRect(hwnd, &rcItem); + ::MapWindowPoints(hwnd, HWND_DESKTOP, reinterpret_cast(&rcItem), 2); + + TPMPARAMS tpm{}; + tpm.cbSize = sizeof(TPMPARAMS); + tpm.rcExclude = rcItem; + + const NativeLangSpeaker* nativeLangSpeaker = NppParameters::getInstance().getNativeLangSpeaker(); + const UINT flags = nativeLangSpeaker->isRTL() ? (TPM_RIGHTALIGN | TPM_RIGHTBUTTON | TPM_LAYOUTRTL) : (TPM_LEFTALIGN | TPM_LEFTBUTTON); + ::TrackPopupMenuEx(_hMenu, flags | TPM_VERTICAL, rcItem.left, rcItem.bottom, _hParent, &tpm); +} + +void ContextMenu::destroy() +{ + if (isCreated()) + { + for (size_t i = 0, len = _subMenus.size(); i < len; ++i) + { + ::DestroyMenu(_subMenus[i]); + _subMenus[i] = nullptr; + } + ::DestroyMenu(_hMenu); + _hMenu = nullptr; + } +} diff --git a/PowerEditor/src/WinControls/ContextMenu/ContextMenu.h b/PowerEditor/src/WinControls/ContextMenu/ContextMenu.h index e3f3d97fce01..94566054e52d 100644 --- a/PowerEditor/src/WinControls/ContextMenu/ContextMenu.h +++ b/PowerEditor/src/WinControls/ContextMenu/ContextMenu.h @@ -21,20 +21,22 @@ struct MenuItemUnit final { unsigned long _cmdID = 0; - generic_string _itemName; - generic_string _parentFolderName; + std::wstring _itemName; + std::wstring _parentFolderName; MenuItemUnit() = default; - MenuItemUnit(unsigned long cmdID, const generic_string& itemName, const generic_string& parentFolderName = generic_string()) + MenuItemUnit(unsigned long cmdID, const std::wstring& itemName, const std::wstring& parentFolderName = std::wstring()) : _cmdID(cmdID), _itemName(itemName), _parentFolderName(parentFolderName){}; - MenuItemUnit(unsigned long cmdID, const TCHAR *itemName, const TCHAR *parentFolderName = nullptr); + MenuItemUnit(unsigned long cmdID, const wchar_t* itemName, const wchar_t* parentFolderName = nullptr); }; class ContextMenu final { public: - ~ContextMenu(); + ~ContextMenu() { + destroy(); + } void create(HWND hParent, const std::vector & menuItemArray, const HMENU mainMenuHandle = NULL, bool copyLink = false); bool isCreated() const {return _hMenu != NULL;} @@ -43,6 +45,8 @@ class ContextMenu final ::TrackPopupMenu(_hMenu, TPM_LEFTALIGN, p.x, p.y, 0, _hParent, NULL); } + void display(HWND hwnd) const; + void enableItem(int cmdID, bool doEnable) const { int flag = doEnable ? (MF_ENABLED | MF_BYCOMMAND) : (MF_DISABLED | MF_GRAYED | MF_BYCOMMAND); @@ -59,9 +63,10 @@ class ContextMenu final return _hMenu; } + void destroy(); + private: HWND _hParent = NULL; HMENU _hMenu = NULL; std::vector _subMenus; - }; diff --git a/PowerEditor/src/WinControls/Preference/preference.rc b/PowerEditor/src/WinControls/Preference/preference.rc index 2e02d9eaa9da..eb13e77cfd9d 100644 --- a/PowerEditor/src/WinControls/Preference/preference.rc +++ b/PowerEditor/src/WinControls/Preference/preference.rc @@ -160,7 +160,7 @@ BEGIN LTEXT "Edge",IDD_CUSTOMIZED_COLOR9_STATIC,342,80,94,8 LTEXT "Edge highlight",IDD_CUSTOMIZED_COLOR11_STATIC,342,100,94,8 LTEXT "Edge disabled",IDD_CUSTOMIZED_COLOR12_STATIC,342,120,94,8 - PUSHBUTTON "Reset",IDD_CUSTOMIZED_RESET_BUTTON,340,158,45,14 + CONTROL "Reset",IDD_CUSTOMIZED_RESET_BUTTON,"Button",BS_SPLITBUTTON | WS_TABSTOP,330,158,65,14 END diff --git a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp index eb4550859af2..dd658d34f22b 100644 --- a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp +++ b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp @@ -1662,6 +1662,8 @@ intptr_t CALLBACK DarkModeSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA delete _pHotEdgeColorPicker; delete _pDisabledEdgeColorPicker; + destroyResetMenu(); + return TRUE; } @@ -1685,6 +1687,51 @@ intptr_t CALLBACK DarkModeSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA return TRUE; } + case WM_NOTIFY: + { + auto lpnmhdr = reinterpret_cast(lParam); + switch (lpnmhdr->code) + { + case BCN_DROPDOWN: + { + switch (lpnmhdr->idFrom) + { + case IDD_CUSTOMIZED_RESET_BUTTON: + { + if (!_resetPopupMenu.isCreated()) + { + NativeLangSpeaker* pNativeSpeaker = nppParam.getNativeLangSpeaker(); + std::vector nodeNames{ "Dialog", "Preference", "DarkMode" }; + + std::vector itemUnitArray; + itemUnitArray.push_back(MenuItemUnit(IDD_CUSTOMIZED_RESET_BUTTON, pNativeSpeaker->getCmdLangStr(nodeNames, IDC_RADIO_DARKMODE_BLACK ,L"Black"))); + itemUnitArray.push_back(MenuItemUnit(IDD_DROPDOWN_RESET_RED, pNativeSpeaker->getCmdLangStr(nodeNames, IDC_RADIO_DARKMODE_RED, L"Red"))); + itemUnitArray.push_back(MenuItemUnit(IDD_DROPDOWN_RESET_GREEN, pNativeSpeaker->getCmdLangStr(nodeNames, IDC_RADIO_DARKMODE_GREEN, L"Green"))); + itemUnitArray.push_back(MenuItemUnit(IDD_DROPDOWN_RESET_BLUE, pNativeSpeaker->getCmdLangStr(nodeNames, IDC_RADIO_DARKMODE_BLUE, L"Blue"))); + itemUnitArray.push_back(MenuItemUnit(IDD_DROPDOWN_RESET_PURPLE, pNativeSpeaker->getCmdLangStr(nodeNames, IDC_RADIO_DARKMODE_PURPLE, L"Purple"))); + itemUnitArray.push_back(MenuItemUnit(IDD_DROPDOWN_RESET_CYAN, pNativeSpeaker->getCmdLangStr(nodeNames, IDC_RADIO_DARKMODE_CYAN, L"Cyan"))); + itemUnitArray.push_back(MenuItemUnit(IDD_DROPDOWN_RESET_OLIVE, pNativeSpeaker->getCmdLangStr(nodeNames, IDC_RADIO_DARKMODE_OLIVE, L"Olive"))); + + _resetPopupMenu.create(_hSelf, itemUnitArray); + } + + _resetPopupMenu.display(lpnmhdr->hwndFrom); + + return TRUE; + } + + default: + break; + } + return FALSE; + } + + default: + break; + } + return FALSE; + } + case WM_COMMAND: { bool changed = false; @@ -1734,6 +1781,12 @@ intptr_t CALLBACK DarkModeSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA case IDC_RADIO_DARKMODE_OLIVE: case IDC_RADIO_DARKMODE_CUSTOMIZED: case IDD_CUSTOMIZED_RESET_BUTTON: + case IDD_DROPDOWN_RESET_RED: + case IDD_DROPDOWN_RESET_GREEN: + case IDD_DROPDOWN_RESET_BLUE: + case IDD_DROPDOWN_RESET_PURPLE: + case IDD_DROPDOWN_RESET_CYAN: + case IDD_DROPDOWN_RESET_OLIVE: { if (wParam == IDC_RADIO_DARKMODE_BLACK) { @@ -1791,7 +1844,61 @@ intptr_t CALLBACK DarkModeSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA NppDarkMode::changeCustomTheme(nppGUI._darkmode._customColors); doEnableCustomizedColorCtrls = true; } + else + { + doEnableCustomizedColorCtrls = true; + switch (wParam) + { + case IDD_CUSTOMIZED_RESET_BUTTON: + { + nppGUI._darkmode._customColors = NppDarkMode::getDarkModeDefaultColors(); + break; + } + + case IDD_DROPDOWN_RESET_RED: + { + nppGUI._darkmode._customColors = NppDarkMode::getDarkModeDefaultColors(NppDarkMode::ColorTone::redTone); + break; + } + + case IDD_DROPDOWN_RESET_GREEN: + { + nppGUI._darkmode._customColors = NppDarkMode::getDarkModeDefaultColors(NppDarkMode::ColorTone::greenTone); + break; + } + + case IDD_DROPDOWN_RESET_BLUE: + { + nppGUI._darkmode._customColors = NppDarkMode::getDarkModeDefaultColors(NppDarkMode::ColorTone::blueTone); + break; + } + + case IDD_DROPDOWN_RESET_PURPLE: + { + nppGUI._darkmode._customColors = NppDarkMode::getDarkModeDefaultColors(NppDarkMode::ColorTone::purpleTone); + break; + } + + case IDD_DROPDOWN_RESET_CYAN: + { + nppGUI._darkmode._customColors = NppDarkMode::getDarkModeDefaultColors(NppDarkMode::ColorTone::cyanTone); + break; + } + case IDD_DROPDOWN_RESET_OLIVE: + { + nppGUI._darkmode._customColors = NppDarkMode::getDarkModeDefaultColors(NppDarkMode::ColorTone::oliveTone); + break; + } + + default: + doEnableCustomizedColorCtrls = false; + break; + } + + if (doEnableCustomizedColorCtrls) + NppDarkMode::changeCustomTheme(nppGUI._darkmode._customColors); + } // switch to chosen dark mode nppGUI._darkmode._isEnabled = true; diff --git a/PowerEditor/src/WinControls/Preference/preferenceDlg.h b/PowerEditor/src/WinControls/Preference/preferenceDlg.h index 2b3d2a94b795..152ec2cdf878 100644 --- a/PowerEditor/src/WinControls/Preference/preferenceDlg.h +++ b/PowerEditor/src/WinControls/Preference/preferenceDlg.h @@ -94,6 +94,10 @@ class DarkModeSubDlg : public StaticDialog public: DarkModeSubDlg() = default; + void destroyResetMenu() { + _resetPopupMenu.destroy(); + } + private: ColourPicker* _pBackgroundColorPicker = nullptr; ColourPicker* _pSofterBackgroundColorPicker = nullptr; @@ -108,6 +112,8 @@ class DarkModeSubDlg : public StaticDialog ColourPicker* _pHotEdgeColorPicker = nullptr; ColourPicker* _pDisabledEdgeColorPicker = nullptr; + ContextMenu _resetPopupMenu; + intptr_t CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) override; void enableCustomizedColorCtrls(bool doEnable); void move2CtrlLeft(int ctrlID, HWND handle2Move, int handle2MoveWidth, int handle2MoveHeight); diff --git a/PowerEditor/src/WinControls/Preference/preference_rc.h b/PowerEditor/src/WinControls/Preference/preference_rc.h index b5b11e13090d..564ea8e68c2e 100644 --- a/PowerEditor/src/WinControls/Preference/preference_rc.h +++ b/PowerEditor/src/WinControls/Preference/preference_rc.h @@ -481,6 +481,12 @@ #define IDC_RADIO_DARKMODE_DARKMODE (IDD_PREFERENCE_SUB_DARKMODE + 32) #define IDC_RADIO_DARKMODE_FOLLOWWINDOWS (IDD_PREFERENCE_SUB_DARKMODE + 33) #define IDC_DARKMODE_TONES_GB_STATIC (IDD_PREFERENCE_SUB_DARKMODE + 35) + #define IDD_DROPDOWN_RESET_RED (IDD_PREFERENCE_SUB_DARKMODE + 36) + #define IDD_DROPDOWN_RESET_GREEN (IDD_PREFERENCE_SUB_DARKMODE + 37) + #define IDD_DROPDOWN_RESET_BLUE (IDD_PREFERENCE_SUB_DARKMODE + 38) + #define IDD_DROPDOWN_RESET_PURPLE (IDD_PREFERENCE_SUB_DARKMODE + 39) + #define IDD_DROPDOWN_RESET_CYAN (IDD_PREFERENCE_SUB_DARKMODE + 40) + #define IDD_DROPDOWN_RESET_OLIVE (IDD_PREFERENCE_SUB_DARKMODE + 41) #define IDD_PREFERENCE_SUB_PERFORMANCE 7140 //(IDD_PREFERENCE_BOX + 1100) #define IDC_GROUPSTATIC_PERFORMANCE_RESTRICTION (IDD_PREFERENCE_SUB_PERFORMANCE + 1) diff --git a/PowerEditor/src/localization.cpp b/PowerEditor/src/localization.cpp index 4d77c812ac58..89b9457fb82f 100644 --- a/PowerEditor/src/localization.cpp +++ b/PowerEditor/src/localization.cpp @@ -1124,6 +1124,8 @@ void NativeLangSpeaker::changePrefereceDlgLang(PreferenceDlg & preference) preference.renameDialogTitle(L"SearchEngine", nameW); } + preference._darkModeSubDlg.destroyResetMenu(); + preference.setListSelection(currentSel); } @@ -1428,7 +1430,51 @@ wstring NativeLangSpeaker::getDlgLangMenuStr(const char* firstLevelNodeName, con return defaultStr; } -wstring NativeLangSpeaker::getProjectPanelLangMenuStr(const char * nodeName, int cmdID, const wchar_t *defaultStr) const +std::wstring NativeLangSpeaker::getCmdLangStr(std::vector nodeNames, int cmdID, const wchar_t* defaultStr) const +{ + if (!_nativeLangA) return defaultStr; + TiXmlNodeA* targetNode = _nativeLangA->FirstChild(nodeNames.at(0)); + if (targetNode == nullptr) + return defaultStr; + + auto it = nodeNames.begin(); + ++it; + + for (auto end = nodeNames.end(); it != end; ++it) + { + targetNode = targetNode->FirstChild(*it); + if (targetNode == nullptr) + return defaultStr; + } + + if (targetNode == nullptr) + return defaultStr; + + const char* name = nullptr; + for (TiXmlNodeA* childNode = targetNode->FirstChildElement("Item"); + childNode; + childNode = childNode->NextSibling("Item")) + { + TiXmlElementA* element = childNode->ToElement(); + int id = 0; + const char* idStr = element->Attribute("id", &id); + + if (idStr && id == cmdID) + { + name = element->Attribute("name"); + break; + } + } + + if (name && name[0]) + { + WcharMbcsConvertor& wmc = WcharMbcsConvertor::getInstance(); + return wmc.char2wchar(name, _nativeLangEncoding); + } + return defaultStr; +} + +std::wstring NativeLangSpeaker::getProjectPanelLangMenuStr(const char * nodeName, int cmdID, const wchar_t *defaultStr) const { if (!_nativeLangA) return defaultStr; diff --git a/PowerEditor/src/localization.h b/PowerEditor/src/localization.h index 9df50a10193b..fac7a8860754 100644 --- a/PowerEditor/src/localization.h +++ b/PowerEditor/src/localization.h @@ -84,6 +84,7 @@ class NativeLangSpeaker { std::wstring getShortcutMapperLangStr(const char *nodeName, const wchar_t *defaultStr) const; std::wstring getProjectPanelLangMenuStr(const char * nodeName, int cmdID, const wchar_t *defaultStr) const; std::wstring getDlgLangMenuStr(const char* firstLevelNodeName, const char* secondLevelNodeName, int cmdID, const wchar_t *defaultStr) const; + std::wstring getCmdLangStr(std::vector nodeNames, int cmdID, const wchar_t* defaultStr) const; std::wstring getAttrNameStr(const wchar_t *defaultStr, const char *nodeL1Name, const char *nodeL2Name, const char *nodeL3Name = "name") const; std::wstring getAttrNameByIdStr(const wchar_t *defaultStr, TiXmlNodeA *targetNode, const char *nodeL1Value, const char *nodeL1Name = "id", const char *nodeL2Name = "name") const; std::wstring getLocalizedStrFromID(const char *strID, const std::wstring& defaultString) const;