Physical printers: Implemented import/export to/from the ConfigBundle.

+ fixed a bug : Case sensitivity of printer's name wasn't check during the adding of a new printer,
as a result in printers list was appeared both of printers (ex. "YuSanka" and "yusanka"), but related file was just one.
This commit is contained in:
YuSanka 2020-10-01 22:48:00 +02:00
parent 94a9820661
commit 2bba0e3131
7 changed files with 140 additions and 27 deletions

View file

@ -1071,6 +1071,9 @@ void MainFrame::init_menubar()
append_menu_item(export_menu, wxID_ANY, _L("Export Config &Bundle") + dots, _L("Export all presets to file"),
[this](wxCommandEvent&) { export_configbundle(); }, "export_config_bundle", nullptr,
[this]() {return true; }, this);
append_menu_item(export_menu, wxID_ANY, _L("Export Config Bundle With Physical Printers") + dots, _L("Export all presets including physical printers to file"),
[this](wxCommandEvent&) { export_configbundle(true); }, "export_config_bundle", nullptr,
[this]() {return true; }, this);
append_submenu(fileMenu, export_menu, wxID_ANY, _L("&Export"), "");
append_menu_item(fileMenu, wxID_ANY, _L("Ejec&t SD card / Flash drive") + dots + "\tCtrl+T", _L("Eject SD card / Flash drive after the G-code was exported to it."),
@ -1641,7 +1644,7 @@ bool MainFrame::load_config_file(const std::string &path)
return true;
}
void MainFrame::export_configbundle()
void MainFrame::export_configbundle(bool export_physical_printers /*= false*/)
{
if (!wxGetApp().check_unsaved_changes())
return;
@ -1663,7 +1666,7 @@ void MainFrame::export_configbundle()
// Export the config bundle.
wxGetApp().app_config->update_config_dir(get_dir_name(file));
try {
wxGetApp().preset_bundle->export_configbundle(file.ToUTF8().data());
wxGetApp().preset_bundle->export_configbundle(file.ToUTF8().data(), false, export_physical_printers);
} catch (const std::exception &ex) {
show_error(this, ex.what());
}

View file

@ -180,7 +180,7 @@ public:
void load_config_file();
// Open a config file. Return true if loaded.
bool load_config_file(const std::string &path);
void export_configbundle();
void export_configbundle(bool export_physical_printers = false);
void load_configbundle(wxString file = wxEmptyString);
void load_config(const DynamicPrintConfig& config);
// Select tab in m_tabpanel

View file

@ -468,15 +468,17 @@ void PhysicalPrinterDialog::OnOK(wxEvent& event)
}
PhysicalPrinterCollection& printers = wxGetApp().preset_bundle->physical_printers;
const PhysicalPrinter* existing = printers.find_printer(into_u8(printer_name));
const PhysicalPrinter* existing = printers.find_printer(into_u8(printer_name), false);
if (existing && into_u8(printer_name) != printers.get_selected_printer_name())
{
wxString msg_text = from_u8((boost::format(_u8L("Printer with name \"%1%\" already exists.")) % printer_name).str());
wxString msg_text = from_u8((boost::format(_u8L("Printer with name \"%1%\" already exists.")) % existing->name/*printer_name*/).str());
msg_text += "\n" + _L("Replace?");
wxMessageDialog dialog(nullptr, msg_text, _L("Warning"), wxICON_WARNING | wxYES | wxNO);
if (dialog.ShowModal() == wxID_NO)
return;
m_printer.name = existing->name;
}
std::set<std::string> repeat_presets;