Follow-up of 908c48ae6a -> Fixed update after switching tab after editing custom g-code in settings tabs (#6258)

This commit is contained in:
Oleksandra Yushchenko 2021-03-24 11:20:57 +01:00 committed by GitHub
parent 991fa67fd1
commit 4496e2a8ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 32 deletions

View file

@ -1738,7 +1738,7 @@ bool Tab::validate_custom_gcode(const wxString& title, const std::string& gcode)
}
static void validate_custom_gcode_cb(Tab* tab, ConfigOptionsGroupShp opt_group, const t_config_option_key& opt_key, const boost::any& value) {
Tab::validate_custom_gcode(opt_group->title, boost::any_cast<std::string>(value));
tab->validate_custom_gcodes_was_shown = !Tab::validate_custom_gcode(opt_group->title, boost::any_cast<std::string>(value));
tab->update_dirty();
tab->on_value_change(opt_key, value);
}
@ -3837,27 +3837,18 @@ bool Tab::validate_custom_gcodes()
if (m_active_page->title() != L("Custom G-code"))
return true;
// When we switch Settings tab after editing of the custom g-code, then warning message could ba already shown after KillFocus event
// and then it's no need to show it again
if (validate_custom_gcodes_was_shown) {
validate_custom_gcodes_was_shown = false;
return true;
}
bool valid = true;
for (auto opt_group : m_active_page->m_optgroups) {
assert(opt_group->opt_map().size() == 1);
std::string key = opt_group->opt_map().begin()->first;
std::string value = boost::any_cast<std::string>(opt_group->get_value(key));
std::string config_value = m_type == Preset::TYPE_FILAMENT ? m_config->opt_string(key, 0u) : m_config->opt_string(key);
valid &= validate_custom_gcode(opt_group->title, value);
Field* field = opt_group->get_field(key);
TextCtrl* text_ctrl = dynamic_cast<TextCtrl*>(field);
if (text_ctrl != nullptr && text_ctrl->m_on_change != nullptr && !text_ctrl->m_disable_change_event) {
Slic3r::GUI::t_change callback = opt_group->m_on_change;
// temporary disable the opt_group->m_on_change callback to avoid multiple validations
opt_group->m_on_change = nullptr;
text_ctrl->m_on_change(key, value);
// restore the opt_group->m_on_change callback
opt_group->m_on_change = callback;
update_dirty();
on_value_change(key, value);
}
valid &= validate_custom_gcode(opt_group->title, boost::any_cast<std::string>(opt_group->get_value(key)));
if (!valid)
break;
}