mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-08-14 04:55:55 +08:00
Fix crash when creating a physical printer & having a dirty printer
supermerill/SuperSlicer#1631
This commit is contained in:
parent
03cf86b06c
commit
6d641fa24b
@ -180,7 +180,14 @@ PhysicalPrinterDialog::PhysicalPrinterDialog(wxWindow* parent, wxString printer_
|
||||
|
||||
m_printer_name = new wxTextCtrl(this, wxID_ANY, printer_name, wxDefaultPosition, wxDefaultSize);
|
||||
m_printer_name->Bind(wxEVT_TEXT, [this](wxEvent&) { this->update_full_printer_names(); });
|
||||
|
||||
m_printer_name->Bind(wxEVT_SET_FOCUS, [this](wxFocusEvent& e) {
|
||||
if (m_printer_name->GetValue() == m_default_name) m_printer_name->SetValue("");
|
||||
e.Skip();
|
||||
});
|
||||
m_printer_name->Bind(wxEVT_KILL_FOCUS, [this](wxFocusEvent& e) {
|
||||
if (m_printer_name->GetValue().empty()) m_printer_name->SetValue(m_default_name);
|
||||
e.Skip();
|
||||
});
|
||||
PhysicalPrinterCollection& printers = wxGetApp().preset_bundle->physical_printers;
|
||||
PhysicalPrinter* printer = printers.find_printer(into_u8(printer_name));
|
||||
if (!printer) {
|
||||
|
@ -366,6 +366,33 @@ void Tab::create_preset_tab()
|
||||
|
||||
if (m_btn_edit_ph_printer)
|
||||
m_btn_edit_ph_printer->Bind(wxEVT_BUTTON, [this](wxCommandEvent e) {
|
||||
// ask for saving modif before
|
||||
if (m_presets->current_is_dirty()) {
|
||||
//ok = may_discard_current_dirty_preset(nullptr, "");
|
||||
UnsavedChangesDialog dlg(Preset::Type::TYPE_PRINTER, m_presets, "");
|
||||
if (dlg.ShowModal() == wxID_CANCEL)
|
||||
return;
|
||||
|
||||
if (dlg.save_preset()) // save selected changes
|
||||
{
|
||||
const std::vector<std::string>& unselected_options = dlg.get_unselected_options(Preset::Type::TYPE_PRINTER);
|
||||
const std::string& name = dlg.get_preset_name();
|
||||
|
||||
// revert unselected options to the old values
|
||||
m_presets->get_edited_preset().config.apply_only(m_presets->get_selected_preset().config, unselected_options);
|
||||
save_preset(name);
|
||||
|
||||
for (const std::pair<std::string, Preset::Type>& nt : dlg.get_names_and_types())
|
||||
m_preset_bundle->save_changes_for_preset(nt.first, nt.second, dlg.get_unselected_options(nt.second));
|
||||
|
||||
// if we saved changes to the new presets, we should to
|
||||
// synchronize config.ini with the current selections.
|
||||
m_preset_bundle->export_selections(*wxGetApp().app_config);
|
||||
} else {
|
||||
// discard all changes
|
||||
m_presets->discard_current_changes();
|
||||
}
|
||||
}
|
||||
if (m_preset_bundle->physical_printers.has_selection())
|
||||
m_presets_choice->edit_physical_printer();
|
||||
else
|
||||
@ -3471,7 +3498,7 @@ bool Tab::may_discard_current_dirty_preset(PresetCollection* presets /*= nullptr
|
||||
// revert unselected options to the old values
|
||||
presets->get_edited_preset().config.apply_only(presets->get_selected_preset().config, unselected_options);
|
||||
save_preset(name);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_preset_bundle->save_changes_for_preset(name, presets->type(), unselected_options);
|
||||
@ -3481,7 +3508,7 @@ bool Tab::may_discard_current_dirty_preset(PresetCollection* presets /*= nullptr
|
||||
// but in full_config a filament_colors option aren't.
|
||||
if (presets->type() == Preset::TYPE_FFF_FILAMENT && wxGetApp().extruders_edited_cnt() > 1)
|
||||
wxGetApp().plater()->force_filament_colors_update();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (dlg.transfer_changes()) // move selected changes
|
||||
{
|
||||
@ -3500,8 +3527,7 @@ bool Tab::may_discard_current_dirty_preset(PresetCollection* presets /*= nullptr
|
||||
|
||||
// copy selected options to the cache from edited preset
|
||||
cache_config_diff(selected_options);
|
||||
}
|
||||
else
|
||||
} else
|
||||
wxGetApp().get_tab(presets->type())->cache_config_diff(selected_options);
|
||||
}
|
||||
|
||||
|
@ -646,9 +646,13 @@ void UnsavedChangesDialog::build(Preset::Type type, PresetCollection* dependent_
|
||||
};
|
||||
|
||||
const PresetCollection& printers = wxGetApp().preset_bundle->printers;
|
||||
if (dependent_presets && (type == dependent_presets->type() ?
|
||||
dependent_presets->get_edited_preset().printer_technology() == dependent_presets->find_preset(new_selected_preset)->printer_technology() :
|
||||
printers.get_edited_preset().printer_technology() == printers.find_preset(new_selected_preset)->printer_technology()))
|
||||
// get the preset we switch to (if it exists)
|
||||
const Preset* new_preset = nullptr;
|
||||
if (dependent_presets)
|
||||
new_preset = (type == dependent_presets->type() ? dependent_presets->find_preset(new_selected_preset) : printers.find_preset(new_selected_preset));
|
||||
if (new_preset && dependent_presets && (type == dependent_presets->type() ?
|
||||
dependent_presets->get_edited_preset().printer_technology() == new_preset->printer_technology() :
|
||||
printers.get_edited_preset().printer_technology() == new_preset->printer_technology()))
|
||||
add_btn(&m_transfer_btn, m_move_btn_id, "paste_menu", Action::Transfer, _L("Transfer"));
|
||||
add_btn(&m_discard_btn, m_continue_btn_id, dependent_presets ? "switch_presets" : "exit", Action::Discard, _L("Discard"), false);
|
||||
add_btn(&m_save_btn, m_save_btn_id, "save", Action::Save, _L("Save"));
|
||||
@ -1042,7 +1046,7 @@ void UnsavedChangesDialog::update(Preset::Type type, PresetCollection* dependent
|
||||
m_discard_btn ->Bind(wxEVT_ENTER_WINDOW, [this] (wxMouseEvent& e) { show_info_line(Action::Discard); e.Skip(); });
|
||||
|
||||
|
||||
if (type == Preset::TYPE_INVALID) {
|
||||
if (type == Preset::TYPE_INVALID || !dependent_presets) {
|
||||
m_action_line->SetLabel(header + "\n" + _L("The following presets were modified:"));
|
||||
}
|
||||
else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user