From 9305535039e1b411f777b745265d6f1d100ea95f Mon Sep 17 00:00:00 2001 From: YuSanka Date: Wed, 25 Nov 2020 19:18:44 +0100 Subject: [PATCH] OSX and Linux specific: Fixed preset selection --- src/slic3r/GUI/Field.cpp | 18 +++++++++++++----- src/slic3r/GUI/PresetComboBoxes.cpp | 11 ++++++++++- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp index a0176ad4a..67bd1c455 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -861,9 +861,15 @@ void Choice::BUILD() { temp->SetItemBitmap(0, empty_bmp); #endif -// temp->Bind(wxEVT_TEXT, ([this](wxCommandEvent e) { on_change_field(); }), temp->GetId()); temp->Bind(wxEVT_COMBOBOX_DROPDOWN, [this](wxCommandEvent&) { m_is_dropped = true; }); - temp->Bind(wxEVT_COMBOBOX_CLOSEUP, [this](wxCommandEvent&) { m_is_dropped = false; }); + temp->Bind(wxEVT_COMBOBOX_CLOSEUP, [this](wxCommandEvent& evt) { + // EVT_COMBOBOX_CLOSEUP is called after EVT_COMBOBOX on Windows + // so, always set m_suppress_change to "true" +#ifndef __WXMSW__ + if (m_last_selected == evt.GetSelection()) +#endif //__WXMSW__ + m_is_dropped = false; + }); temp->Bind(wxEVT_COMBOBOX, ([this, temp](wxCommandEvent evt) { if (m_suppress_scroll) { @@ -874,6 +880,7 @@ void Choice::BUILD() { m_last_selected = evt.GetSelection(); } on_change_field(); + m_is_dropped = false; }), temp->GetId()); if (m_is_editable) { @@ -998,13 +1005,14 @@ void Choice::set_value(const boost::any& value, bool change_event) else text_value = boost::any_cast(value); size_t idx = 0; - for (auto el : m_opt.enum_values) + const std::vector& enums = m_opt.enum_values.empty() ? m_opt.enum_labels : m_opt.enum_values; + for (auto el : enums) { if (el == text_value) break; ++idx; } - if (idx == m_opt.enum_values.size()) { + if (idx == enums.size()) { // For editable Combobox under OSX is needed to set selection to -1 explicitly, // otherwise selection doesn't be changed field->SetSelection(-1); @@ -1012,7 +1020,7 @@ void Choice::set_value(const boost::any& value, bool change_event) } else field->SetSelection(idx); - if (m_suppress_scroll && idx < m_opt.enum_values.size()) m_last_selected = idx; + if (m_suppress_scroll && idx < enums.size()) m_last_selected = idx; break; } case coEnum: { diff --git a/src/slic3r/GUI/PresetComboBoxes.cpp b/src/slic3r/GUI/PresetComboBoxes.cpp index 78559b937..c60c84bad 100644 --- a/src/slic3r/GUI/PresetComboBoxes.cpp +++ b/src/slic3r/GUI/PresetComboBoxes.cpp @@ -104,7 +104,14 @@ PresetComboBox::PresetComboBox(wxWindow* parent, Preset::Type preset_type, const // parameters for an icon's drawing fill_width_height(); Bind(wxEVT_COMBOBOX_DROPDOWN, [this](wxCommandEvent& evt) { m_suppress_change = false; }); - Bind(wxEVT_COMBOBOX_CLOSEUP, [this](wxCommandEvent& evt) { m_suppress_change = true ; }); + Bind(wxEVT_COMBOBOX_CLOSEUP, [this](wxCommandEvent& evt) { + // EVT_COMBOBOX_CLOSEUP is called after EVT_COMBOBOX on Windows + // so, always set m_suppress_change to "true" +#ifndef __WXMSW__ + if (m_last_selected == evt.GetSelection()) +#endif //__WXMSW__ + m_suppress_change = true; + }); Bind(wxEVT_COMBOBOX, [this](wxCommandEvent& evt) { // see https://github.com/prusa3d/PrusaSlicer/issues/3889 @@ -572,6 +579,7 @@ PlaterPresetComboBox::PlaterPresetComboBox(wxWindow *parent, Preset::Type preset } else { evt.StopPropagation(); } + m_suppress_change = true; }); if (m_type == Preset::TYPE_FILAMENT) @@ -911,6 +919,7 @@ TabPresetComboBox::TabPresetComboBox(wxWindow* parent, Preset::Type preset_type) } evt.StopPropagation(); + m_suppress_change = true; }); }