Skip to content

Commit

Permalink
Sort language list in the Preferences dialog
Browse files Browse the repository at this point in the history
Sort langlist before displaying using custom less than operator.

Fix notepad-plus-plus#14245, close notepad-plus-plus#14443
  • Loading branch information
briangood35 authored and donho committed Dec 8, 2023
1 parent ef8ad11 commit bf37d47
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
8 changes: 8 additions & 0 deletions PowerEditor/src/Parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 10 additions & 1 deletion PowerEditor/src/WinControls/Preference/preferenceDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "lesDlgs.h"
#include "EncodingMapper.h"
#include "localization.h"
#include <algorithm>

#define MyGetGValue(rgb) (LOBYTE((rgb)>>8))

Expand Down Expand Up @@ -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()));
Expand Down

0 comments on commit bf37d47

Please sign in to comment.