From 5215b2ecb2074b488cabca172a495d327cedd4a2 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Mon, 23 Mar 2020 22:47:35 +0100 Subject: [PATCH] Fix of #3889 --- src/slic3r/GUI/Plater.cpp | 16 ++++++++++++---- src/slic3r/GUI/Plater.hpp | 2 +- src/slic3r/GUI/Preset.cpp | 2 +- src/slic3r/GUI/PresetBundle.cpp | 2 +- src/slic3r/GUI/Tab.cpp | 8 +++++++- 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 8388c1cfd..ddd1a086d 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -268,7 +268,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(this->GetClientData(selected_item)); if (marker >= LABEL_ITEM_MARKER && marker < LABEL_ITEM_MAX) { @@ -388,9 +388,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() @@ -3627,6 +3627,14 @@ void Plater::priv::on_select_preset(wxCommandEvent &evt) auto preset_type = static_cast(evt.GetInt()); auto *combo = static_cast(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, @@ -3637,7 +3645,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); diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index 32709a4bd..889cbe4fb 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -71,7 +71,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(); diff --git a/src/slic3r/GUI/Preset.cpp b/src/slic3r/GUI/Preset.cpp index 1b03a558d..fda7adbc8 100644 --- a/src/slic3r/GUI/Preset.cpp +++ b/src/slic3r/GUI/Preset.cpp @@ -1253,7 +1253,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) diff --git a/src/slic3r/GUI/PresetBundle.cpp b/src/slic3r/GUI/PresetBundle.cpp index 3a48cd675..8eb14fdc4 100644 --- a/src/slic3r/GUI/PresetBundle.cpp +++ b/src/slic3r/GUI/PresetBundle.cpp @@ -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) diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index adfae9024..66b689e08 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -229,7 +229,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) {