Automatically change extension in output_filename_format when switching to/from binary gcode format in Print Settings

This commit is contained in:
enricoturri1966 2023-09-05 14:06:49 +02:00
parent 0f939409b8
commit a0dfb33b49

View File

@ -1719,6 +1719,33 @@ void TabPrint::build()
optgroup->append_single_option_line(option);
optgroup->append_single_option_line("gcode_binary");
optgroup->m_on_change = [this](const t_config_option_key& opt_key, boost::any value)
{
if (opt_key == "gcode_binary") {
const bool is_binary = m_config->opt_bool("gcode_binary");
std::string output_filename_format = m_config->opt_string("output_filename_format");
bool modified = false;
if (is_binary && boost::iends_with(output_filename_format, ".gcode")) {
output_filename_format = output_filename_format.substr(0, output_filename_format.length() - 5) + "bgcode";
modified = true;
}
else if (!is_binary && boost::iends_with(output_filename_format, ".bgcode")) {
output_filename_format = output_filename_format.substr(0, output_filename_format.length() - 6) + "gcode";
modified = true;
}
if (modified) {
DynamicPrintConfig new_conf = *m_config;
auto off_option = static_cast<ConfigOptionString*>(m_config->option("output_filename_format")->clone());
off_option->value = output_filename_format;
new_conf.set_key_value("output_filename_format", off_option);
load_config(new_conf);
}
}
update_dirty();
update();
};
optgroup = page->new_optgroup(L("Other"));
create_line_with_widget(optgroup.get(), "gcode_substitutions", "g-code-substitutions_301694", [this](wxWindow* parent) {