case insensitive sort for filament vendor list (#6594)
* case insensitive sort for filament vendor list * Merge branch 'main' into case-insensitive-filament-vendor-sort
This commit is contained in:
parent
3e6d2d0f45
commit
a1e2267fdf
1 changed files with 21 additions and 4 deletions
|
@ -143,6 +143,15 @@ static bool str_is_all_digit(const std::string &str) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Custom comparator for case-insensitive sorting
|
||||||
|
static bool caseInsensitiveCompare(const std::string& a, const std::string& b) {
|
||||||
|
std::string lowerA = a;
|
||||||
|
std::string lowerB = b;
|
||||||
|
std::transform(lowerA.begin(), lowerA.end(), lowerA.begin(), ::tolower);
|
||||||
|
std::transform(lowerB.begin(), lowerB.end(), lowerB.begin(), ::tolower);
|
||||||
|
return lowerA < lowerB;
|
||||||
|
}
|
||||||
|
|
||||||
static bool delete_filament_preset_by_name(std::string delete_preset_name, std::string &selected_preset_name)
|
static bool delete_filament_preset_by_name(std::string delete_preset_name, std::string &selected_preset_name)
|
||||||
{
|
{
|
||||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format("select preset, name %1%") % delete_preset_name;
|
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format("select preset, name %1%") % delete_preset_name;
|
||||||
|
@ -692,11 +701,19 @@ wxBoxSizer *CreateFilamentPresetDialog::create_vendor_item()
|
||||||
optionSizer->SetMinSize(OPTION_SIZE);
|
optionSizer->SetMinSize(OPTION_SIZE);
|
||||||
horizontal_sizer->Add(optionSizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(5));
|
horizontal_sizer->Add(optionSizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(5));
|
||||||
|
|
||||||
wxArrayString choices;
|
// Convert all std::any to std::string
|
||||||
for (const wxString vendor : filament_vendors) {
|
std::vector<std::string> string_vendors;
|
||||||
choices.push_back(vendor);
|
for (const auto& vendor_any : filament_vendors) {
|
||||||
|
string_vendors.push_back(std::any_cast<std::string>(vendor_any));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort the vendors alphabetically
|
||||||
|
std::sort(string_vendors.begin(), string_vendors.end(), caseInsensitiveCompare);
|
||||||
|
|
||||||
|
wxArrayString choices;
|
||||||
|
for (const std::string &vendor : string_vendors) {
|
||||||
|
choices.push_back(wxString(vendor)); // Convert std::string to wxString before adding
|
||||||
}
|
}
|
||||||
choices.Sort();
|
|
||||||
|
|
||||||
wxBoxSizer *vendor_sizer = new wxBoxSizer(wxHORIZONTAL);
|
wxBoxSizer *vendor_sizer = new wxBoxSizer(wxHORIZONTAL);
|
||||||
m_filament_vendor_combobox = new ComboBox(this, wxID_ANY, wxEmptyString, wxDefaultPosition, NAME_OPTION_COMBOBOX_SIZE, 0, nullptr, wxCB_READONLY);
|
m_filament_vendor_combobox = new ComboBox(this, wxID_ANY, wxEmptyString, wxDefaultPosition, NAME_OPTION_COMBOBOX_SIZE, 0, nullptr, wxCB_READONLY);
|
||||||
|
|
Loading…
Reference in a new issue