From 349ce7fd50dbb775765ecb450a21b599e51ed22b Mon Sep 17 00:00:00 2001 From: YuSanka Date: Wed, 17 Feb 2021 14:34:35 +0100 Subject: [PATCH] Fix of #6056 - Purging Volumes dialog doesn't save pasted values --- src/slic3r/GUI/WipeTowerDialog.cpp | 34 ++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/slic3r/GUI/WipeTowerDialog.cpp b/src/slic3r/GUI/WipeTowerDialog.cpp index 970cd8528..329ee58ce 100644 --- a/src/slic3r/GUI/WipeTowerDialog.cpp +++ b/src/slic3r/GUI/WipeTowerDialog.cpp @@ -263,9 +263,39 @@ WipingPanel::WipingPanel(wxWindow* parent, const std::vector& matrix, con gridsizer_simple->Add(new wxStaticText(m_page_simple, wxID_ANY, wxString(_(L("unloaded")))), 0, wxALIGN_CENTER | wxALIGN_CENTER_VERTICAL); gridsizer_simple->Add(new wxStaticText(m_page_simple,wxID_ANY,wxString(_(L("loaded")))), 0, wxALIGN_CENTER | wxALIGN_CENTER_VERTICAL); + auto add_spin_ctrl = [this](std::vector& vec, float initial) + { + wxSpinCtrl* spin_ctrl = new wxSpinCtrl(m_page_simple, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(ITEM_WIDTH(), -1), wxSP_ARROW_KEYS | wxALIGN_RIGHT, 0, 300, (int)initial); + vec.push_back(spin_ctrl); + +#ifdef __WXOSX__ + // On OSX / Cocoa, wxSpinCtrl::GetValue() doesn't return the new value + // when it was changed from the text control, so the on_change callback + // gets the old one, and on_kill_focus resets the control to the old value. + // As a workaround, we get the new value from $event->GetString and store + // here temporarily so that we can return it from get_value() + spin_ctrl->Bind(wxEVT_TEXT, ([this, spin_ctrl](wxCommandEvent e) + { + long value; + const bool parsed = e.GetString().ToLong(&value); + int tmp_value = parsed && value >= INT_MIN && value <= INT_MAX ? (int)value : INT_MIN; + + // Forcibly set the input value for SpinControl, since the value + // inserted from the keyboard or clipboard is not updated under OSX + if (tmp_value != INT_MIN) { + spin_ctrl->SetValue(tmp_value); + + // But in SetValue() is executed m_text_ctrl->SelectAll(), so + // discard this selection and set insertion point to the end of string + spin_ctrl->GetText()->SetInsertionPointEnd(); + } + }), spin_ctrl->GetId()); +#endif + }; + for (unsigned int i=0;i