Merge remote-tracking branch 'origin/ys_fix_cb_selection'

This commit is contained in:
YuSanka 2020-03-25 11:12:37 +01:00
commit de06c5d659
5 changed files with 22 additions and 8 deletions

View file

@ -263,7 +263,7 @@ PresetBitmapComboBox(parent, wxSize(15 * wxGetApp().em_unit(), -1)),
EnableTextChangedEvents(false);
#endif /* _WIN32 */
Bind(wxEVT_COMBOBOX, [this](wxCommandEvent &evt) {
auto selected_item = this->GetSelection();
auto selected_item = evt.GetSelection();
auto marker = reinterpret_cast<Marker>(this->GetClientData(selected_item));
if (marker >= LABEL_ITEM_MARKER && marker < LABEL_ITEM_MAX) {
@ -383,9 +383,9 @@ void PresetComboBox::set_label_marker(int item, LabelItemType label_item_type)
this->SetClientData(item, (void*)label_item_type);
}
void PresetComboBox::check_selection()
void PresetComboBox::check_selection(int selection)
{
this->last_selected = GetSelection();
this->last_selected = selection;
}
void PresetComboBox::msw_rescale()
@ -3532,6 +3532,14 @@ void Plater::priv::on_select_preset(wxCommandEvent &evt)
auto preset_type = static_cast<Preset::Type>(evt.GetInt());
auto *combo = static_cast<PresetComboBox*>(evt.GetEventObject());
// see https://github.com/prusa3d/PrusaSlicer/issues/3889
// Under OSX: in case of use of a same names written in different case (like "ENDER" and "Ender"),
// m_presets_choice->GetSelection() will return first item, because search in PopupListCtrl is case-insensitive.
// So, use GetSelection() from event parameter
// But in this function we couldn't use evt.GetSelection(), because m_commandInt is used for preset_type
// Thus, get selection in this way:
int selection = combo->FindString(evt.GetString(), true);
auto idx = combo->get_extruder_idx();
//! Because of The MSW and GTK version of wxBitmapComboBox derived from wxComboBox,
@ -3542,7 +3550,7 @@ void Plater::priv::on_select_preset(wxCommandEvent &evt)
//! combo->GetStringSelection().ToUTF8().data());
const std::string preset_name = wxGetApp().preset_bundle->get_preset_name_by_alias(preset_type,
Preset::remove_suffix_modified(combo->GetString(combo->GetSelection()).ToUTF8().data()));
Preset::remove_suffix_modified(combo->GetString(selection).ToUTF8().data()));
if (preset_type == Preset::TYPE_FILAMENT) {
wxGetApp().preset_bundle->set_filament_preset(idx, preset_name);

View file

@ -69,7 +69,7 @@ public:
void set_extruder_idx(const int extr_idx) { extruder_idx = extr_idx; }
int get_extruder_idx() const { return extruder_idx; }
int em_unit() const { return m_em_unit; }
void check_selection();
void check_selection(int selection);
void msw_rescale();

View file

@ -1254,7 +1254,7 @@ void PresetCollection::update_plater_ui(GUI::PresetComboBox *ui)
ui->SetSelection(selected_preset_item);
ui->SetToolTip(tooltip.IsEmpty() ? ui->GetString(selected_preset_item) : tooltip);
ui->check_selection();
ui->check_selection(selected_preset_item);
ui->Thaw();
// Update control min size after rescale (changed Display DPI under MSW)

View file

@ -1737,7 +1737,7 @@ void PresetBundle::update_plater_filament_ui(unsigned int idx_extruder, GUI::Pre
ui->SetSelection(selected_preset_item);
ui->SetToolTip(tooltip.IsEmpty() ? ui->GetString(selected_preset_item) : tooltip);
ui->check_selection();
ui->check_selection(selected_preset_item);
ui->Thaw();
// Update control min size after rescale (changed Display DPI under MSW)

View file

@ -230,7 +230,13 @@ void Tab::create_preset_tab()
//! but the OSX version derived from wxOwnerDrawnCombo, instead of:
//! select_preset(m_presets_choice->GetStringSelection().ToUTF8().data());
//! we doing next:
int selected_item = m_presets_choice->GetSelection();
// int selected_item = m_presets_choice->GetSelection();
// see https://github.com/prusa3d/PrusaSlicer/issues/3889
// Under OSX: in case of use of a same names written in different case (like "ENDER" and "Ender")
// m_presets_choice->GetSelection() will return first item, because search in PopupListCtrl is case-insensitive.
// So, use GetSelection() from event parameter
int selected_item = e.GetSelection();
if (m_selected_preset_item == size_t(selected_item) && !m_presets->current_is_dirty())
return;
if (selected_item >= 0) {