diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index 858744229c..a5a920f825 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -525,7 +525,13 @@ void MainFrame::init_tabpanel() m_tabpanel->Hide(); m_settings_dialog.set_tabpanel(m_tabpanel); - m_tabpanel->Bind(wxEVT_NOTEBOOK_PAGE_CHANGED, [this](wxEvent&) { + m_tabpanel->Bind(wxEVT_NOTEBOOK_PAGE_CHANGED, [this](wxBookCtrlEvent& e) { +#if ENABLE_VALIDATE_CUSTOM_GCODE + Tab* old_tab = dynamic_cast(m_tabpanel->GetPage(e.GetOldSelection())); + if (old_tab) + old_tab->validate_custom_gcodes(); +#endif // ENABLE_VALIDATE_CUSTOM_GCODE + wxWindow* panel = m_tabpanel->GetCurrentPage(); Tab* tab = dynamic_cast(panel); @@ -544,19 +550,6 @@ void MainFrame::init_tabpanel() select_tab(size_t(0)); // select Plater }); -#if ENABLE_VALIDATE_CUSTOM_GCODE - m_tabpanel->Bind(wxEVT_NOTEBOOK_PAGE_CHANGING, [this](wxBookCtrlEvent& evt) { - wxWindow* panel = m_tabpanel->GetCurrentPage(); - if (panel != nullptr) { - Tab* tab = dynamic_cast(panel); - if (tab != nullptr) - tab->validate_custom_gcodes(); -// if (tab != nullptr && !tab->validate_custom_gcodes()) -// evt.Veto(); - } - }); -#endif // ENABLE_VALIDATE_CUSTOM_GCODE - m_plater = new Plater(this, this); m_plater->Hide(); diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 74b54478e7..11c4875ebd 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -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(value)); + tab->validate_custom_gcodes_was_shown = !Tab::validate_custom_gcode(opt_group->title, boost::any_cast(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(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(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(opt_group->get_value(key))); if (!valid) break; } diff --git a/src/slic3r/GUI/Tab.hpp b/src/slic3r/GUI/Tab.hpp index fcbe27eb7f..8cbc6585a7 100644 --- a/src/slic3r/GUI/Tab.hpp +++ b/src/slic3r/GUI/Tab.hpp @@ -351,6 +351,7 @@ public: #if ENABLE_VALIDATE_CUSTOM_GCODE static bool validate_custom_gcode(const wxString& title, const std::string& gcode); bool validate_custom_gcodes(); + bool validate_custom_gcodes_was_shown { false }; #endif // ENABLE_VALIDATE_CUSTOM_GCODE protected: