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
This commit is contained in:
Daniel Fuchs 2022-02-01 10:40:42 +01:00 committed by Don Ho
parent 987a944ada
commit dee3bad29d
2 changed files with 21 additions and 21 deletions

View File

@ -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<LPARAM>(TEXT("Full file name path")));
::SendDlgItemMessage(_hSelf, IDC_COMBO_VARLIST, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(TEXT("File name")));
::SendDlgItemMessage(_hSelf, IDC_COMBO_VARLIST, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(TEXT("File directory")));
::SendDlgItemMessage(_hSelf, IDC_COMBO_VARLIST, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(TEXT("Page")));
::SendDlgItemMessage(_hSelf, IDC_COMBO_VARLIST, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(TEXT("Short date format")));
::SendDlgItemMessage(_hSelf, IDC_COMBO_VARLIST, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(TEXT("Long date format")));
::SendDlgItemMessage(_hSelf, IDC_COMBO_VARLIST, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(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<LPARAM>(varList[i]._varDesc.c_str()));
::SendDlgItemMessage(_hSelf, IDC_COMBO_VARLIST, CB_SETITEMDATA, j, reinterpret_cast<LPARAM>(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<WPARAM>(&selStart), reinterpret_cast<LPARAM>(&selEnd));

View File

@ -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<strCouple> varList;
std::vector<generic_string> varList;
int _focusedEditCtrl = 0;
};