Sort language list in the Preferences dialog

Sort langlist before displaying using custom less than operator.

Fix #14245, close #14443
This commit is contained in:
briangood35 2023-12-03 22:59:17 -05:00 committed by Don Ho
parent ef8ad111e9
commit bf37d4714f
2 changed files with 18 additions and 1 deletions

View File

@ -586,6 +586,14 @@ struct LangMenuItem final
LangMenuItem(LangType lt, int cmdID = 0, const std::wstring& langName = TEXT("")):
_langType(lt), _cmdID(cmdID), _langName(langName){};
bool operator<(const LangMenuItem& rhs)
{
std::wstring lhs_lang(this->_langName.length(), ' '), rhs_lang(rhs._langName.length(), ' ');
std::transform(this->_langName.begin(), this->_langName.end(), lhs_lang.begin(), towlower);
std::transform(rhs._langName.begin(), rhs._langName.end(), rhs_lang.begin(), towlower);
return lhs_lang < rhs_lang;
}
};
struct PrintSettings final {

View File

@ -19,6 +19,7 @@
#include "lesDlgs.h"
#include "EncodingMapper.h"
#include "localization.h"
#include <algorithm>
#define MyGetGValue(rgb) (LOBYTE((rgb)>>8))
@ -2861,12 +2862,20 @@ intptr_t CALLBACK LanguageSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA
if (str.length() > 0)
{
_langList.push_back(LangMenuItem(static_cast<LangType>(i), cmdID, str));
::SendDlgItemMessage(_hSelf, IDC_LIST_ENABLEDLANG, LB_ADDSTRING, 0, reinterpret_cast<LPARAM>(str.c_str()));
}
}
}
}
std::sort(_langList.begin(), _langList.end());
for (size_t i = 0, len = _langList.size(); i < len; ++i)
{
::SendDlgItemMessage(_hSelf, IDC_LIST_ENABLEDLANG, LB_ADDSTRING, 0, reinterpret_cast<LPARAM>(_langList[i]._langName.c_str()));
}
std::sort(nppGUI._excludedLangList.begin(), nppGUI._excludedLangList.end());
for (size_t i = 0, len = nppGUI._excludedLangList.size(); i < len ; ++i)
{
::SendDlgItemMessage(_hSelf, IDC_LIST_DISABLEDLANG, LB_ADDSTRING, 0, reinterpret_cast<LPARAM>(nppGUI._excludedLangList[i]._langName.c_str()));