diff --git a/src/libslic3r/Config.hpp b/src/libslic3r/Config.hpp index f0f37c2771..c327779755 100644 --- a/src/libslic3r/Config.hpp +++ b/src/libslic3r/Config.hpp @@ -1812,6 +1812,8 @@ public: legend, // Vector value, but edited as a single string. one_string, + // Close parameter, string value could be one of the list values. + select_close, }; // Identifier of this option. It is stored here so that it is accessible through the by_serialization_key_ordinal map. diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index ea44ea4f64..3a5a772ad0 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -334,7 +334,7 @@ void PrintConfigDef::init_common_params() def = this->add("printhost_port", coString); def->label = L("Printer"); def->tooltip = L("Name of the printer"); -// def->gui_type = ConfigOptionDef::GUIType::select_open; + def->gui_type = ConfigOptionDef::GUIType::select_close; def->mode = comAdvanced; def->cli = ConfigOptionDef::nocli; def->set_default_value(new ConfigOptionString("")); diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp index 86d1df9845..70fc3d53dc 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -991,7 +991,9 @@ void Choice::BUILD() { if (m_opt.width >= 0) size.SetWidth(m_opt.width*m_em_unit); choice_ctrl* temp; - if (m_opt.gui_type != ConfigOptionDef::GUIType::undefined && m_opt.gui_type != ConfigOptionDef::GUIType::select_open) { + if (m_opt.gui_type != ConfigOptionDef::GUIType::undefined + && m_opt.gui_type != ConfigOptionDef::GUIType::select_open + && m_opt.gui_type != ConfigOptionDef::GUIType::select_close) { m_is_editable = true; temp = new choice_ctrl(m_parent, wxID_ANY, wxString(""), wxDefaultPosition, size, 0, nullptr, wxTE_PROCESS_ENTER); } @@ -1021,11 +1023,13 @@ void Choice::BUILD() { // recast as a wxWindow to fit the calling convention window = dynamic_cast(temp); - if (auto &labels = m_opt.enum_def->labels(); ! labels.empty()) { - bool localized = m_opt.enum_def->has_labels(); - for (const std::string &el : labels) - temp->Append(localized ? _(wxString::FromUTF8(el)) : wxString::FromUTF8(el)); - set_selection(); + if (m_opt.enum_def) { + if (auto& labels = m_opt.enum_def->labels(); !labels.empty()) { + bool localized = m_opt.enum_def->has_labels(); + for (const std::string& el : labels) + temp->Append(localized ? _(from_u8(el)) : from_u8(el)); + set_selection(); + } } temp->Bind(wxEVT_MOUSEWHEEL, [this](wxMouseEvent& e) { @@ -1171,9 +1175,17 @@ void Choice::set_value(const boost::any& value, bool change_event) wxString text_value = m_opt.type == coInt ? wxString::Format(_T("%i"), int(boost::any_cast(value))) : boost::any_cast(value); - if (auto idx = m_opt.enum_def->label_to_index(into_u8(text_value)); idx.has_value()) { - field->SetSelection(idx.value()); - } else { + int sel_idx = -1; + if (m_opt.enum_def) { + if (auto idx = m_opt.enum_def->label_to_index(into_u8(text_value)); idx.has_value()) + sel_idx = idx.value(); + else if (idx = m_opt.enum_def->value_to_index(into_u8(text_value)); idx.has_value()) + sel_idx = idx.value(); + } + + if (sel_idx >= 0 ) + field->SetSelection(sel_idx); + else { // For editable Combobox under OSX is needed to set selection to -1 explicitly, // otherwise selection doesn't be changed field->SetSelection(-1); @@ -1305,22 +1317,19 @@ void Choice::msw_rescale() // Set rescaled size field->SetSize(size); - size_t idx = 0; - if (m_opt.enum_def && ! m_opt.enum_def->labels().empty()) { - size_t counter = 0; - bool localized = m_opt.enum_def->has_labels(); - for (const std::string &el : m_opt.enum_def->labels()) { - wxString text = localized ? _(el) : from_u8(el); - field->Append(text); - if (text == selection) - idx = counter; - ++ counter; + if (m_opt.enum_def) { + if (auto& labels = m_opt.enum_def->labels(); !labels.empty()) { + const bool localized = m_opt.enum_def->has_labels(); + for (const std::string& el : labels) + field->Append(localized ? _(from_u8(el)) : from_u8(el)); + + if (auto opt = m_opt.enum_def->label_to_index(into_u8(selection)); opt.has_value()) + // This enum has a value field of the same content as text_value. Select it. + field->SetSelection(opt.value()); + else + field->SetValue(selection); } } - - idx == m_opt.enum_values.size() ? - field->SetValue(selection) : - field->SetSelection(idx); #else #ifdef _WIN32 field->Rescale(); diff --git a/src/slic3r/GUI/OptionsGroup.cpp b/src/slic3r/GUI/OptionsGroup.cpp index d9ddf5e89b..0ca0bf9db5 100644 --- a/src/slic3r/GUI/OptionsGroup.cpp +++ b/src/slic3r/GUI/OptionsGroup.cpp @@ -32,16 +32,15 @@ const t_field& OptionsGroup::build_field(const t_config_option_key& id, const Co // Check the gui_type field first, fall through // is the normal type. switch (opt.gui_type) { + case ConfigOptionDef::GUIType::select_close: case ConfigOptionDef::GUIType::select_open: + case ConfigOptionDef::GUIType::f_enum_open: + case ConfigOptionDef::GUIType::i_enum_open: m_fields.emplace(id, Choice::Create(this->ctrl_parent(), opt, id)); break; case ConfigOptionDef::GUIType::color: m_fields.emplace(id, ColourPicker::Create(this->ctrl_parent(), opt, id)); break; - case ConfigOptionDef::GUIType::f_enum_open: - case ConfigOptionDef::GUIType::i_enum_open: - m_fields.emplace(id, Choice::Create(this->ctrl_parent(), opt, id)); - break; case ConfigOptionDef::GUIType::slider: m_fields.emplace(id, SliderCtrl::Create(this->ctrl_parent(), opt, id)); break;