From ed25d5c53de20a86f9c719dabf709e36c71a53f9 Mon Sep 17 00:00:00 2001 From: Oleksandra Yushchenko Date: Tue, 10 Aug 2021 12:32:00 +0200 Subject: [PATCH] Fix for #6692 - Slice button not appearing after infill change --- src/slic3r/GUI/Field.cpp | 88 +++++++++++++++++++++++++--------------- src/slic3r/GUI/Field.hpp | 4 ++ 2 files changed, 60 insertions(+), 32 deletions(-) diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp index 49771081d..76fd857fb 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -935,7 +935,7 @@ void Choice::BUILD() { choice_ctrl* temp; if (m_opt.gui_type != ConfigOptionDef::GUIType::undefined && m_opt.gui_type != ConfigOptionDef::GUIType::select_open) { m_is_editable = true; - temp = new choice_ctrl(m_parent, wxID_ANY, wxString(""), wxDefaultPosition, size); + temp = new choice_ctrl(m_parent, wxID_ANY, wxString(""), wxDefaultPosition, size, 0, nullptr, wxTE_PROCESS_ENTER); } else { #ifdef __WXOSX__ @@ -988,46 +988,70 @@ void Choice::BUILD() { temp->Bind(wxEVT_COMBOBOX, [this](wxCommandEvent&) { on_change_field(); }, temp->GetId()); if (m_is_editable) { - temp->Bind(wxEVT_KILL_FOCUS, ([this](wxEvent& e) { + temp->Bind(wxEVT_KILL_FOCUS, [this](wxEvent& e) { e.Skip(); - if (m_opt.type == coStrings) { - on_change_field(); + if (bKilledFocus) return; - } - if (is_defined_input_value(window, m_opt.type)) { - switch (m_opt.type) { - case coFloatOrPercent: - { - std::string old_val = !m_value.empty() ? boost::any_cast(m_value) : ""; - if (old_val == boost::any_cast(get_value())) - return; - break; - } - case coInt: - { - int old_val = !m_value.empty() ? boost::any_cast(m_value) : 0; - if (old_val == boost::any_cast(get_value())) - return; - break; - } - default: - { - double old_val = !m_value.empty() ? boost::any_cast(m_value) : -99999; - if (fabs(old_val - boost::any_cast(get_value())) <= 0.0001) - return; - } - } - on_change_field(); - } + bKilledFocus = true; + + if (bEnterPressed) + bEnterPressed = false; else - on_kill_focus(); - }), temp->GetId()); + propagate_value(); + // After processing of KILL_FOCUS event we should to invalidate a bKilledFocus flag + bKilledFocus = false; + } ); + + temp->Bind(wxEVT_TEXT_ENTER, [this, temp](wxEvent& e) { +#ifdef _WIN32 + temp->SetFocus(); +#else + bEnterPressed = true; + propagate_value(); +#endif //_WIN32 + } ); } temp->SetToolTip(get_tooltip_text(temp->GetValue())); } +void Choice::propagate_value() +{ + if (m_opt.type == coStrings) { + on_change_field(); + return; + } + + if (is_defined_input_value(window, m_opt.type)) { + switch (m_opt.type) { + case coFloatOrPercent: + { + std::string old_val = !m_value.empty() ? boost::any_cast(m_value) : ""; + if (old_val == boost::any_cast(get_value())) + return; + break; + } + case coInt: + { + int old_val = !m_value.empty() ? boost::any_cast(m_value) : 0; + if (old_val == boost::any_cast(get_value())) + return; + break; + } + default: + { + double old_val = !m_value.empty() ? boost::any_cast(m_value) : -99999; + if (fabs(old_val - boost::any_cast(get_value())) <= 0.0001) + return; + } + } + on_change_field(); + } + else + on_kill_focus(); +} + void Choice::suppress_scroll() { m_suppress_scroll = true; diff --git a/src/slic3r/GUI/Field.hpp b/src/slic3r/GUI/Field.hpp index 0693091ad..34a2481b5 100644 --- a/src/slic3r/GUI/Field.hpp +++ b/src/slic3r/GUI/Field.hpp @@ -342,6 +342,8 @@ public: class Choice : public Field { using Field::Field; + bool bKilledFocus = false; + public: Choice(const ConfigOptionDef& opt, const t_config_option_key& id) : Field(opt, id) {} Choice(wxWindow* parent, const ConfigOptionDef& opt, const t_config_option_key& id) : Field(parent, opt, id) {} @@ -349,6 +351,8 @@ public: wxWindow* window{ nullptr }; void BUILD() override; + // Propagate value from field to the OptionGroupe and Config after kill_focus/ENTER + void propagate_value(); /* Under OSX: wxBitmapComboBox->GetWindowStyle() returns some weard value, * so let use a flag, which has TRUE value for a control without wxCB_READONLY style