From dee3bad29dc224b44e58ec43eb78aef29194fb86 Mon Sep 17 00:00:00 2001 From: Daniel Fuchs Date: Tue, 1 Feb 2022 10:40:42 +0100 Subject: [PATCH] Make variable list combobox translatable in printing preferences The list of variables defined under Preferences > Print can be translated using the following method: https://github.com/notepad-plus-plus/notepad-plus-plus/pull/11093/files#diff-a6ac7ceba70d88bf1547fd1defd760bd55052dcdb78c44f9d46d99ef1f450472R999-R1007 However as pointed out by others this will break the "Add" button, so translation is currently not possible. The result is, that nothing is added to the current field. This commit makes translation possible without breaking "Add" feature. Fix #11114, close #11115 --- .../WinControls/Preference/preferenceDlg.cpp | 34 +++++++++++-------- .../WinControls/Preference/preferenceDlg.h | 8 +---- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp index ff084af02..3b199b41e 100644 --- a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp +++ b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp @@ -3027,19 +3027,22 @@ intptr_t CALLBACK PrintSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM) ::SendDlgItemMessage(_hSelf, IDC_CHECK_FBOLD, BM_SETCHECK, nppGUI._printSettings._footerFontStyle & FONTSTYLE_BOLD, 0); ::SendDlgItemMessage(_hSelf, IDC_CHECK_FITALIC, BM_SETCHECK, nppGUI._printSettings._footerFontStyle & FONTSTYLE_ITALIC, 0); - varList.push_back(strCouple(TEXT("Full file name path"), TEXT("$(FULL_CURRENT_PATH)"))); - varList.push_back(strCouple(TEXT("File name"), TEXT("$(FILE_NAME)"))); - varList.push_back(strCouple(TEXT("File directory"), TEXT("$(CURRENT_DIRECTORY)"))); - varList.push_back(strCouple(TEXT("Page"), TEXT("$(CURRENT_PRINTING_PAGE)"))); - varList.push_back(strCouple(TEXT("Short date format"), TEXT("$(SHORT_DATE)"))); - varList.push_back(strCouple(TEXT("Long date format"), TEXT("$(LONG_DATE)"))); - varList.push_back(strCouple(TEXT("Time"), TEXT("$(TIME)"))); + ::SendDlgItemMessage(_hSelf, IDC_COMBO_VARLIST, CB_ADDSTRING, 0, reinterpret_cast(TEXT("Full file name path"))); + ::SendDlgItemMessage(_hSelf, IDC_COMBO_VARLIST, CB_ADDSTRING, 0, reinterpret_cast(TEXT("File name"))); + ::SendDlgItemMessage(_hSelf, IDC_COMBO_VARLIST, CB_ADDSTRING, 0, reinterpret_cast(TEXT("File directory"))); + ::SendDlgItemMessage(_hSelf, IDC_COMBO_VARLIST, CB_ADDSTRING, 0, reinterpret_cast(TEXT("Page"))); + ::SendDlgItemMessage(_hSelf, IDC_COMBO_VARLIST, CB_ADDSTRING, 0, reinterpret_cast(TEXT("Short date format"))); + ::SendDlgItemMessage(_hSelf, IDC_COMBO_VARLIST, CB_ADDSTRING, 0, reinterpret_cast(TEXT("Long date format"))); + ::SendDlgItemMessage(_hSelf, IDC_COMBO_VARLIST, CB_ADDSTRING, 0, reinterpret_cast(TEXT("Time"))); + + varList.push_back(TEXT("$(FULL_CURRENT_PATH)")); + varList.push_back(TEXT("$(FILE_NAME)")); + varList.push_back(TEXT("$(CURRENT_DIRECTORY)")); + varList.push_back(TEXT("$(CURRENT_PRINTING_PAGE)")); + varList.push_back(TEXT("$(SHORT_DATE)")); + varList.push_back(TEXT("$(LONG_DATE)")); + varList.push_back(TEXT("$(TIME)")); - for (size_t i = 0, len = varList.size() ; i < len ; ++i) - { - auto j = ::SendDlgItemMessage(_hSelf, IDC_COMBO_VARLIST, CB_ADDSTRING, 0, reinterpret_cast(varList[i]._varDesc.c_str())); - ::SendDlgItemMessage(_hSelf, IDC_COMBO_VARLIST, CB_SETITEMDATA, j, reinterpret_cast(varList[i]._var.c_str())); - } ::SendDlgItemMessage(_hSelf, IDC_COMBO_VARLIST, CB_SETCURSEL, 0, 0); break; @@ -3270,8 +3273,11 @@ intptr_t CALLBACK PrintSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM) if (!_focusedEditCtrl) return TRUE; - auto iSel = ::SendDlgItemMessage(_hSelf, IDC_COMBO_VARLIST, CB_GETCURSEL, 0, 0); - TCHAR *varStr = (TCHAR *)::SendDlgItemMessage(_hSelf, IDC_COMBO_VARLIST, CB_GETITEMDATA, iSel, 0); + size_t iSel = ::SendDlgItemMessage(_hSelf, IDC_COMBO_VARLIST, CB_GETCURSEL, 0, 0); + if (iSel >= varList.size()) + return TRUE; + + TCHAR *varStr = (TCHAR*)varList[iSel].c_str(); size_t selStart = 0; size_t selEnd = 0; ::SendDlgItemMessage(_hSelf, _focusedEditCtrl, EM_GETSEL, reinterpret_cast(&selStart), reinterpret_cast(&selEnd)); diff --git a/PowerEditor/src/WinControls/Preference/preferenceDlg.h b/PowerEditor/src/WinControls/Preference/preferenceDlg.h index d13dfb19a..4a37074b4 100644 --- a/PowerEditor/src/WinControls/Preference/preferenceDlg.h +++ b/PowerEditor/src/WinControls/Preference/preferenceDlg.h @@ -166,12 +166,6 @@ private: intptr_t CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam); }; -struct strCouple { - generic_string _varDesc; - generic_string _var; - strCouple(const TCHAR *varDesc, const TCHAR *var): _varDesc(varDesc), _var(var){}; -}; - class PrintSubDlg : public StaticDialog { public : @@ -179,7 +173,7 @@ public : private : intptr_t CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam); - std::vector varList; + std::vector varList; int _focusedEditCtrl = 0; };