From 13cd4acad687cea7d5afcdea72b59373a66b3d7b Mon Sep 17 00:00:00 2001 From: Don Ho Date: Tue, 27 Feb 2024 18:22:05 +0100 Subject: [PATCH] Fix "Save a Copy As" dialog's wrong title 1. Use appropriated localized title on some main save/open dialogs. 2. Reuse menu localized string and remove some redundent entries from localization files. Fix #14737, fix #11860, close #14808 --- PowerEditor/installer/nativeLang/english.xml | 4 -- .../nativeLang/english_customizable.xml | 4 -- PowerEditor/installer/nativeLang/french.xml | 4 -- .../nativeLang/taiwaneseMandarin.xml | 2 - PowerEditor/src/Notepad_plus.cpp | 6 +- PowerEditor/src/Notepad_plus.rc | 2 +- PowerEditor/src/NppCommands.cpp | 2 +- PowerEditor/src/NppIO.cpp | 24 +++++-- PowerEditor/src/Parameters.cpp | 2 +- .../src/ScintillaComponent/FindReplaceDlg.cpp | 6 +- PowerEditor/src/localization.cpp | 62 ++++++++++++++++--- PowerEditor/src/localization.h | 2 +- PowerEditor/src/menuCmdID.h | 2 +- 13 files changed, 86 insertions(+), 36 deletions(-) diff --git a/PowerEditor/installer/nativeLang/english.xml b/PowerEditor/installer/nativeLang/english.xml index ac6c4704a..ded4384ee 100644 --- a/PowerEditor/installer/nativeLang/english.xml +++ b/PowerEditor/installer/nativeLang/english.xml @@ -1644,7 +1644,6 @@ NOTE: Choosing not to create the placeholders or closing them later, your sessio - - - @@ -1719,7 +1716,6 @@ Find in all files but exclude all folders log or logs recursively: - diff --git a/PowerEditor/installer/nativeLang/english_customizable.xml b/PowerEditor/installer/nativeLang/english_customizable.xml index dba6e7445..1073030cd 100644 --- a/PowerEditor/installer/nativeLang/english_customizable.xml +++ b/PowerEditor/installer/nativeLang/english_customizable.xml @@ -1643,7 +1643,6 @@ NOTE: Choosing not to create the placeholders or closing them later, your sessio - - - @@ -1718,7 +1715,6 @@ Find in all files but exclude all folders log or logs recursively: - diff --git a/PowerEditor/installer/nativeLang/french.xml b/PowerEditor/installer/nativeLang/french.xml index 48d6b9b25..57092b33d 100644 --- a/PowerEditor/installer/nativeLang/french.xml +++ b/PowerEditor/installer/nativeLang/french.xml @@ -1640,7 +1640,6 @@ NOTE : Si vous choisissez de ne pas créer d'espaces réservés ou de les fermer - - - @@ -1715,7 +1712,6 @@ Rechercher dans tous les fichiers mais pas dans les dossiers log ou logs récurs - diff --git a/PowerEditor/installer/nativeLang/taiwaneseMandarin.xml b/PowerEditor/installer/nativeLang/taiwaneseMandarin.xml index 7823e2661..a44e4f0f7 100644 --- a/PowerEditor/installer/nativeLang/taiwaneseMandarin.xml +++ b/PowerEditor/installer/nativeLang/taiwaneseMandarin.xml @@ -1560,8 +1560,6 @@ - - diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 5a93d6ad9..a84bd4f32 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -7357,8 +7357,9 @@ void Notepad_plus::launchFileBrowser(const vector & folders, con NativeLangSpeaker *pNativeSpeaker = nppParams.getNativeLangSpeaker(); generic_string title_temp = pNativeSpeaker->getAttrNameStr(FB_PANELTITLE, FOLDERASWORKSPACE_NODE, "PanelTitle"); - static TCHAR title[32]; - if (title_temp.length() < 32) + const int titleLen = 64; + static TCHAR title[titleLen]; + if (title_temp.length() < titleLen) { wcscpy_s(title, title_temp.c_str()); data.pszName = title; @@ -7645,6 +7646,7 @@ static const QuoteParams quotes[] = {TEXT("Darth Vader #2"), QuoteParams::rapid, true, SC_CP_UTF8, L_TEXT, TEXT("You don't get to 500 million star systems without making a few enemies.")}, {TEXT("Doug Linder"), QuoteParams::rapid, true, SC_CP_UTF8, L_TEXT, TEXT("A good programmer is someone who always looks both ways before crossing a one-way street.")}, {TEXT("Jean-Claude van Damme"), QuoteParams::rapid, true, SC_CP_UTF8, L_TEXT, TEXT("A cookie has no soul, it's just a cookie. But before it was milk and eggs.\nAnd in eggs there's the potential for life.")}, + {TEXT("Mark Zuckerberg"), QuoteParams::slow, false, SC_CP_UTF8, L_TEXT, TEXT("\"Black lives matter\" doesn't mean other lives don't - it's simply asking that the black community also achieves the justice they deserve.")}, {TEXT("Michael Feldman"), QuoteParams::slow, false, SC_CP_UTF8, L_TEXT, TEXT("Java is, in many ways, C++--.")}, {TEXT("Don Ho"), QuoteParams::slow, false, SC_CP_UTF8, L_TEXT, TEXT("Je mange donc je chie.")}, {TEXT("Don Ho #2"), QuoteParams::rapid, true, SC_CP_UTF8, L_TEXT, TEXT("RTFM is the true path of every developer.\nBut it would happen only if there's no way out.")}, diff --git a/PowerEditor/src/Notepad_plus.rc b/PowerEditor/src/Notepad_plus.rc index e7ad0017e..e13f1d8b6 100644 --- a/PowerEditor/src/Notepad_plus.rc +++ b/PowerEditor/src/Notepad_plus.rc @@ -1186,7 +1186,7 @@ BEGIN POPUP "Import" BEGIN MENUITEM "Import plugin(s)...", IDM_SETTING_IMPORTPLUGIN - MENUITEM "Import style theme(s)...", IDM_SETTING_IMPORTSTYLETHEMS + MENUITEM "Import style theme(s)...", IDM_SETTING_IMPORTSTYLETHEMES END MENUITEM SEPARATOR MENUITEM "Edit Popup ContextMenu", IDM_SETTING_EDITCONTEXTMENU diff --git a/PowerEditor/src/NppCommands.cpp b/PowerEditor/src/NppCommands.cpp index 863e022d8..7a0abb6f9 100644 --- a/PowerEditor/src/NppCommands.cpp +++ b/PowerEditor/src/NppCommands.cpp @@ -3181,7 +3181,7 @@ void Notepad_plus::command(int id) break; } - case IDM_SETTING_IMPORTSTYLETHEMS : + case IDM_SETTING_IMPORTSTYLETHEMES : { // get plugin source path const TCHAR *extFilterName = TEXT("Notepad++ style theme"); diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index f76b4af8b..431929de1 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -1792,6 +1792,17 @@ bool Notepad_plus::fileSaveAs(BufferID id, bool isSaveCopy) fDlg.setExtIndex(langTypeIndex + 1); // +1 for "All types" + generic_string localizedTitle; + if (isSaveCopy) + { + localizedTitle = _nativeLangSpeaker.getNativeLangMenuString(IDM_FILE_SAVECOPYAS, L"Save a Copy As", true); + } + else + { + localizedTitle = _nativeLangSpeaker.getNativeLangMenuString(IDM_FILE_SAVEAS, L"Save As", true); + } + fDlg.setTitle(localizedTitle.c_str()); + const generic_string checkboxLabel = _nativeLangSpeaker.getLocalizedStrFromID("file-save-assign-type", TEXT("&Append extension")); fDlg.enableFileTypeCheckbox(checkboxLabel, !defaultAllTypes); @@ -1875,8 +1886,8 @@ bool Notepad_plus::fileRename(BufferID id) fDlg.setFolder(buf->getFullPathName()); fDlg.setDefFileName(buf->getFileName()); - std::wstring title = _nativeLangSpeaker.getLocalizedStrFromID("file-rename-title", L"Rename"); - fDlg.setTitle(title.c_str()); + wstring localizedRename = _nativeLangSpeaker.getNativeLangMenuString(IDM_FILE_RENAME, L"Rename", true); + fDlg.setTitle(localizedRename.c_str()); std::wstring fn = fDlg.doSaveDlg(); @@ -2011,6 +2022,8 @@ bool Notepad_plus::fileDelete(BufferID id) void Notepad_plus::fileOpen() { CustomFileDialog fDlg(_pPublicInterface->getHSelf()); + wstring localizedTitle = _nativeLangSpeaker.getNativeLangMenuString(IDM_FILE_OPEN, L"Open", true); + fDlg.setTitle(localizedTitle.c_str()); fDlg.setExtFilter(TEXT("All types"), TEXT(".*")); setFileOpenSaveDlgFilters(fDlg, true); @@ -2460,6 +2473,8 @@ bool Notepad_plus::fileLoadSession(const TCHAR *fn) fDlg.setDefExt(ext); } fDlg.setExtFilter(TEXT("All types"), TEXT(".*")); + wstring localizedTitle = _nativeLangSpeaker.getNativeLangMenuString(IDM_FILE_LOADSESSION, L"Load Session", true); + fDlg.setTitle(localizedTitle.c_str()); sessionFileName = fDlg.doOpenSingleFileDlg(); } else @@ -2558,9 +2573,10 @@ const TCHAR * Notepad_plus::fileSaveSession(size_t nbFile, TCHAR ** fileNames) } fDlg.setExtFilter(TEXT("All types"), TEXT(".*")); const bool isCheckboxActive = _pFileBrowser && !_pFileBrowser->isClosed(); - const generic_string checkboxLabel = _nativeLangSpeaker.getLocalizedStrFromID("session-save-folder-as-workspace", - TEXT("Save Folder as Workspace")); + const generic_string checkboxLabel = _nativeLangSpeaker.getLocalizedStrFromID("session-save-folder-as-workspace", L"Save Folder as Workspace"); fDlg.setCheckbox(checkboxLabel.c_str(), isCheckboxActive); + wstring localizedTitle = _nativeLangSpeaker.getNativeLangMenuString(IDM_FILE_SAVESESSION, L"Save Session", true); + fDlg.setTitle(localizedTitle.c_str()); generic_string sessionFileName = fDlg.doSaveDlg(); if (!sessionFileName.empty()) diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index 7751a6806..3f1b9f236 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -417,7 +417,7 @@ static const WinMenuKeyDefinition winKeyDefs[] = { VK_NULL, IDM_LANGSTYLE_CONFIG_DLG, false, false, false, nullptr }, { VK_NULL, IDM_SETTING_SHORTCUT_MAPPER, false, false, false, nullptr }, { VK_NULL, IDM_SETTING_IMPORTPLUGIN, false, false, false, nullptr }, - { VK_NULL, IDM_SETTING_IMPORTSTYLETHEMS, false, false, false, nullptr }, + { VK_NULL, IDM_SETTING_IMPORTSTYLETHEMES, false, false, false, nullptr }, { VK_NULL, IDM_SETTING_EDITCONTEXTMENU, false, false, false, nullptr }, { VK_R, IDC_EDIT_TOGGLEMACRORECORDING, true, false, true, TEXT("Toggle macro recording")}, diff --git a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp index 61f36aad3..6937f9c48 100644 --- a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp +++ b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp @@ -5258,10 +5258,10 @@ intptr_t CALLBACK Finder::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam generic_string collapseAll = pNativeSpeaker->getLocalizedStrFromID("finder-collapse-all", TEXT("Fold all")); generic_string uncollapseAll = pNativeSpeaker->getLocalizedStrFromID("finder-uncollapse-all", TEXT("Unfold all")); generic_string copyLines = pNativeSpeaker->getLocalizedStrFromID("finder-copy", TEXT("Copy Selected Line(s)")); - generic_string copyVerbatim = pNativeSpeaker->getLocalizedStrFromID("finder-copy-verbatim", TEXT("Copy")); + generic_string copyVerbatim = pNativeSpeaker->getNativeLangMenuString(IDM_EDIT_COPY, L"Rename", true); copyVerbatim += TEXT("\tCtrl+C"); generic_string copyPaths = pNativeSpeaker->getLocalizedStrFromID("finder-copy-paths", TEXT("Copy Pathname(s)")); - generic_string selectAll = pNativeSpeaker->getLocalizedStrFromID("finder-select-all", TEXT("Select all")); + generic_string selectAll = pNativeSpeaker->getNativeLangMenuString(IDM_EDIT_SELECTALL, L"Select all", true); selectAll += TEXT("\tCtrl+A"); generic_string clearAll = pNativeSpeaker->getLocalizedStrFromID("finder-clear-all", TEXT("Clear all")); generic_string purgeForEverySearch = pNativeSpeaker->getLocalizedStrFromID("finder-purge-for-every-search", TEXT("Purge for every search")); @@ -5897,7 +5897,7 @@ int Progress::createProgressWindow() ::SendMessage(_hPBar, PBM_SETBARCOLOR, 0, static_cast(NppDarkMode::getDarkerTextColor())); } - generic_string cancel = pNativeSpeaker->getLocalizedStrFromID("progress-cancel-button", TEXT("Cancel")); + generic_string cancel = pNativeSpeaker->getLocalizedStrFromID("common-cancel", TEXT("Cancel")); _hBtn = ::CreateWindowEx(0, TEXT("BUTTON"), cancel.c_str(), WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON | BS_TEXT, diff --git a/PowerEditor/src/localization.cpp b/PowerEditor/src/localization.cpp index 8635d5093..a895e3d89 100644 --- a/PowerEditor/src/localization.cpp +++ b/PowerEditor/src/localization.cpp @@ -198,19 +198,59 @@ generic_string NativeLangSpeaker::getSubMenuEntryName(const char *nodeName) cons return TEXT(""); } -generic_string NativeLangSpeaker::getNativeLangMenuString(int itemID) const +void purifyMenuString(string& s) +{ + // Remove & for CJK localization + size_t posAndCJK = s.find("(&", 0); + if (posAndCJK != string::npos) + { + if (posAndCJK + 3 < s.length()) + { + if (s[posAndCJK + 3] == ')') + s.erase(posAndCJK, 4); + } + } + + // Remove & and transform && to & for all localizations + for (int i = static_cast(s.length()) - 1; i >= 0; --i) + { + if (s[i] == '&') + { + if (i-1 >= 0 && s[i-1] == '&') + { + s.erase(i, 1); + i -= 1; + } + else + { + s.erase(i, 1); + } + } + } + + // Remove ellipsis... + size_t len = s.length(); + if (len <= 3) + return; + size_t posEllipsis = len - 3; + if (s.substr(posEllipsis) == "...") + s.erase(posEllipsis, 3); + +} + +generic_string NativeLangSpeaker::getNativeLangMenuString(int itemID, generic_string inCaseOfFailureStr, bool removeMarkAnd) const { if (!_nativeLangA) - return TEXT(""); + return inCaseOfFailureStr; TiXmlNodeA *node = _nativeLangA->FirstChild("Menu"); - if (!node) return TEXT(""); + if (!node) return inCaseOfFailureStr; node = node->FirstChild("Main"); - if (!node) return TEXT(""); + if (!node) return inCaseOfFailureStr; node = node->FirstChild("Commands"); - if (!node) return TEXT(""); + if (!node) return inCaseOfFailureStr; WcharMbcsConvertor& wmc = WcharMbcsConvertor::getInstance(); @@ -225,11 +265,17 @@ generic_string NativeLangSpeaker::getNativeLangMenuString(int itemID) const const char *name = element->Attribute("name"); if (name) { - return wmc.char2wchar(name, _nativeLangEncoding); + string nameStr = name; + + if (removeMarkAnd) + { + purifyMenuString(nameStr); + } + return wmc.char2wchar(nameStr.c_str(), _nativeLangEncoding); } } } - return TEXT(""); + return inCaseOfFailureStr; } generic_string NativeLangSpeaker::getShortcutNameString(int itemID) const @@ -1436,7 +1482,7 @@ generic_string NativeLangSpeaker::getAttrNameStr(const TCHAR *defaultStr, const return defaultStr; } - generic_string NativeLangSpeaker::getAttrNameByIdStr(const TCHAR *defaultStr, TiXmlNodeA *targetNode, const char *nodeL1Value, const char *nodeL1Name, const char *nodeL2Name) const +generic_string NativeLangSpeaker::getAttrNameByIdStr(const TCHAR *defaultStr, TiXmlNodeA *targetNode, const char *nodeL1Value, const char *nodeL1Name, const char *nodeL2Name) const { if (!targetNode) return defaultStr; diff --git a/PowerEditor/src/localization.h b/PowerEditor/src/localization.h index 68105c6dd..beea5e494 100644 --- a/PowerEditor/src/localization.h +++ b/PowerEditor/src/localization.h @@ -47,7 +47,7 @@ public: void changeLangTabDropContextMenu(HMENU hCM); void changeLangTrayIconContexMenu(HMENU hCM); generic_string getSubMenuEntryName(const char *nodeName) const; - generic_string getNativeLangMenuString(int itemID) const; + generic_string getNativeLangMenuString(int itemID, generic_string inCaseOfFailureStr = L"", bool removeMarkAnd = false) const; generic_string getShortcutNameString(int itemID) const; void changeMenuLang(HMENU menuHandle); diff --git a/PowerEditor/src/menuCmdID.h b/PowerEditor/src/menuCmdID.h index bb29a6373..e6bdcdd8f 100644 --- a/PowerEditor/src/menuCmdID.h +++ b/PowerEditor/src/menuCmdID.h @@ -592,7 +592,7 @@ // #define IDM_SETTING_HISTORY_SIZE (IDM_SETTING + 3) // #define IDM_SETTING_EDGE_SIZE (IDM_SETTING + 4) #define IDM_SETTING_IMPORTPLUGIN (IDM_SETTING + 5) - #define IDM_SETTING_IMPORTSTYLETHEMS (IDM_SETTING + 6) + #define IDM_SETTING_IMPORTSTYLETHEMES (IDM_SETTING + 6) #define IDM_SETTING_TRAYICON (IDM_SETTING + 8) #define IDM_SETTING_SHORTCUT_MAPPER (IDM_SETTING + 9) #define IDM_SETTING_REMEMBER_LAST_SESSION (IDM_SETTING + 10)