G-code substitutions: Added path to helper

Fixed a bugs:
* Notes wasn't correctly save to 3mf
* Button "Delete All" wasn't hidden when last substitution was deleted
This commit is contained in:
YuSanka 2022-01-28 17:11:27 +01:00
parent cfdf7d2a00
commit 07a27c9e2d
2 changed files with 17 additions and 4 deletions

View File

@ -1703,7 +1703,7 @@ void TabPrint::build()
optgroup = page->new_optgroup(L("Other"));
create_line_with_widget(optgroup.get(), "gcode_substitutions", "", [this](wxWindow* parent) {
create_line_with_widget(optgroup.get(), "gcode_substitutions", "g-code-substitutions_301694", [this](wxWindow* parent) {
return create_manage_substitution_widget(parent);
});
line = { "", "" };
@ -4017,7 +4017,7 @@ void SubstitutionManager::add_substitution( int substitution_id,
add_text_editor(from_u8(plain_pattern), 0, 3);
add_text_editor(from_u8(format), 1, 3);
add_text_editor(from_u8(notes), 1, 2);
add_text_editor(from_u8(notes), 3, 2);
auto params_sizer = new wxBoxSizer(wxHORIZONTAL);
bool regexp = strchr(params.c_str(), 'r') != nullptr || strchr(params.c_str(), 'R') != nullptr;
@ -4079,7 +4079,9 @@ void SubstitutionManager::update_from_config()
m_grid_sizer->Clear(true);
std::vector<std::string>& subst = m_config->option<ConfigOptionStrings>("gcode_substitutions")->values;
if (!subst.empty())
if (subst.empty())
hide_delete_all_btn();
else
create_legend();
validate_lenth();
@ -4162,6 +4164,9 @@ wxSizer* TabPrint::create_substitutions_widget(wxWindow* parent)
update_dirty();
wxGetApp().mainframe->on_config_changed(m_config); // invalidate print
});
m_subst_manager.set_cb_hide_delete_all_btn([this]() {
m_del_all_substitutions_btn->Hide();
});
parent->GetParent()->Layout();
return grid_sizer;

View File

@ -54,6 +54,7 @@ class SubstitutionManager
int m_em{10};
std::function<void()> m_cb_edited_substitution{ nullptr };
std::function<void()> m_cb_hide_delete_all_btn{ nullptr };
void validate_lenth();
bool is_compatibile_with_ui();
@ -83,6 +84,13 @@ public:
if (m_cb_edited_substitution)
m_cb_edited_substitution();
}
void set_cb_hide_delete_all_btn(std::function<void()> cb_hide_delete_all_btn) {
m_cb_hide_delete_all_btn = cb_hide_delete_all_btn;
}
void hide_delete_all_btn() {
if (m_cb_hide_delete_all_btn)
m_cb_hide_delete_all_btn();
}
bool is_empty_substitutions();
};