From 250bd689f25fd35ef18bf61c9c597290035e6963 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 24 Nov 2020 15:04:47 +0100 Subject: [PATCH] Fix for #5231. Suppress scrolling for the PresetComboBoxes when they aren't dropped. --- src/slic3r/GUI/PresetComboBoxes.cpp | 15 +++++++++++++++ src/slic3r/GUI/PresetComboBoxes.hpp | 2 ++ 2 files changed, 17 insertions(+) diff --git a/src/slic3r/GUI/PresetComboBoxes.cpp b/src/slic3r/GUI/PresetComboBoxes.cpp index 5acf71fef..78559b937 100644 --- a/src/slic3r/GUI/PresetComboBoxes.cpp +++ b/src/slic3r/GUI/PresetComboBoxes.cpp @@ -103,6 +103,8 @@ 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, [this](wxCommandEvent& evt) { // see https://github.com/prusa3d/PrusaSlicer/issues/3889 @@ -147,6 +149,15 @@ bool PresetComboBox::set_printer_technology(PrinterTechnology pt) return false; } +bool PresetComboBox::check_event_for_suppress_change(wxCommandEvent& evt) +{ + if (m_suppress_change) { + evt.StopPropagation(); + SetSelection(m_last_selected); + } + return m_suppress_change; +} + void PresetComboBox::invalidate_selection() { m_last_selected = INT_MAX; // this value means that no one item is selected @@ -534,6 +545,8 @@ PlaterPresetComboBox::PlaterPresetComboBox(wxWindow *parent, Preset::Type preset PresetComboBox(parent, preset_type, wxSize(15 * wxGetApp().em_unit(), -1)) { Bind(wxEVT_COMBOBOX, [this](wxCommandEvent &evt) { + if (check_event_for_suppress_change(evt)) + return; auto selected_item = evt.GetSelection(); auto marker = reinterpret_cast(this->GetClientData(selected_item)); @@ -871,6 +884,8 @@ TabPresetComboBox::TabPresetComboBox(wxWindow* parent, Preset::Type preset_type) PresetComboBox(parent, preset_type, wxSize(35 * wxGetApp().em_unit(), -1)) { Bind(wxEVT_COMBOBOX, [this](wxCommandEvent& evt) { + if (check_event_for_suppress_change(evt)) + return; // 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. diff --git a/src/slic3r/GUI/PresetComboBoxes.hpp b/src/slic3r/GUI/PresetComboBoxes.hpp index 2967ff263..0bd4f036f 100644 --- a/src/slic3r/GUI/PresetComboBoxes.hpp +++ b/src/slic3r/GUI/PresetComboBoxes.hpp @@ -86,6 +86,7 @@ protected: int m_last_selected; int m_em_unit; + bool m_suppress_change { true }; // parameters for an icon's drawing int icon_height; @@ -98,6 +99,7 @@ protected: PrinterTechnology printer_technology {ptAny}; + bool check_event_for_suppress_change(wxCommandEvent& evt); void invalidate_selection(); void validate_selection(bool predicate = false); void update_selection();