Fixed a bug: Wrong save of a preset if the preset is already exist.

Step to repro:
1. Select system "Some_preset" preset
2. Make some changes
3. Save preset with "Some_preset - Copy" name.
=>  "Some_preset - Copy" is selected, there is/are marked option(s) only different from system preset.
repeate 1-3 steps
=>  "Some_preset - Copy" is selected, there is/are marked option(s) different from DEFAULT preset.
This commit is contained in:
YuSanka 2019-10-02 22:50:55 +02:00
parent 546ad99306
commit b3603a09fc
3 changed files with 30 additions and 0 deletions

View File

@ -819,6 +819,21 @@ bool PresetCollection::delete_current_preset()
return true; return true;
} }
bool PresetCollection::delete_preset(const std::string& name)
{
auto it = this->find_preset_internal(name);
const Preset& preset = *it;
if (preset.is_default)
return false;
if (!preset.is_external && !preset.is_system) {
// Erase the preset file.
boost::nowide::remove(preset.file.c_str());
}
m_presets.erase(it);
return true;
}
void PresetCollection::load_bitmap_default(wxWindow *window, const std::string &file_name) void PresetCollection::load_bitmap_default(wxWindow *window, const std::string &file_name)
{ {
// XXX: See note in PresetBundle::load_compatible_bitmaps() // XXX: See note in PresetBundle::load_compatible_bitmaps()

View File

@ -276,6 +276,9 @@ public:
// Delete the current preset, activate the first visible preset. // Delete the current preset, activate the first visible preset.
// returns true if the preset was deleted successfully. // returns true if the preset was deleted successfully.
bool delete_current_preset(); bool delete_current_preset();
// Delete the current preset, activate the first visible preset.
// returns true if the preset was deleted successfully.
bool delete_preset(const std::string& name);
// Load default bitmap to be placed at the wxBitmapComboBox of a MainFrame. // Load default bitmap to be placed at the wxBitmapComboBox of a MainFrame.
void load_bitmap_default(wxWindow *window, const std::string &file_name); void load_bitmap_default(wxWindow *window, const std::string &file_name);

View File

@ -3019,6 +3019,18 @@ void Tab::save_preset(std::string name /*= ""*/)
show_error(this, _(L("Cannot overwrite an external profile."))); show_error(this, _(L("Cannot overwrite an external profile.")));
return; return;
} }
if (existing && name != preset.name)
{
wxString msg_text = GUI::from_u8((boost::format(_utf8(L("Preset with name \"%1%\" already exist."))) % name).str());
msg_text += "\n" + _(L("Replace?"));
wxMessageDialog dialog(nullptr, msg_text, _(L("Warning")), wxICON_WARNING | wxYES | wxNO);
if (dialog.ShowModal() == wxID_NO)
return;
// Remove the preset from the list.
m_presets->delete_preset(name);
}
} }
// Save the preset into Slic3r::data_dir / presets / section_name / preset_name.ini // Save the preset into Slic3r::data_dir / presets / section_name / preset_name.ini