Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

case insensitive sort for filament vendor list #6594

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions src/slic3r/GUI/CreatePresetsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ static bool str_is_all_digit(const std::string &str) {
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)
{
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format("select preset, name %1%") % delete_preset_name;
Expand Down Expand Up @@ -692,11 +701,19 @@ wxBoxSizer *CreateFilamentPresetDialog::create_vendor_item()
optionSizer->SetMinSize(OPTION_SIZE);
horizontal_sizer->Add(optionSizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(5));

// Convert all std::any to std::string
std::vector<std::string> string_vendors;
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 wxString vendor : filament_vendors) {
choices.push_back(vendor);
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);
m_filament_vendor_combobox = new ComboBox(this, wxID_ANY, wxEmptyString, wxDefaultPosition, NAME_OPTION_COMBOBOX_SIZE, 0, nullptr, wxCB_READONLY);
Expand Down