Simplified "Save/Rename Preset" dialog when only one preset is saved/renamed.

This commit is contained in:
YuSanka 2023-03-27 13:34:21 +02:00
parent 0eb2a2cf04
commit 3ad5f52b00
4 changed files with 31 additions and 40 deletions

View File

@ -85,18 +85,17 @@ void SavePresetDialog::Item::init_input_name_ctrl(wxBoxSizer *input_name_sizer,
} }
} }
wxString SavePresetDialog::Item::get_top_label_text() const static std::map<Preset::Type, std::string> TOP_LABELS =
{ {
const std::string label_str = m_use_text_ctrl ? // type Save settings
// TRN %1% = "Preset" { Preset::Type::TYPE_PRINT, L("Save print settings as") },
L("Rename %1% to") : { Preset::Type::TYPE_SLA_PRINT, L("Save print settings as") },
// TRN %1% = "Preset" { Preset::Type::TYPE_FILAMENT, L("Save filament settings as")},
L("Save %1% as"); { Preset::Type::TYPE_SLA_MATERIAL, L("Save material settings as")},
Tab* tab = wxGetApp().get_tab(m_type); { Preset::Type::TYPE_PRINTER, L("Save printer settings as") },
return format_wxstr(_(label_str) + ":", tab->title()); };
}
SavePresetDialog::Item::Item(Preset::Type type, const std::string& suffix, wxBoxSizer* sizer, SavePresetDialog* parent): SavePresetDialog::Item::Item(Preset::Type type, const std::string& suffix, wxBoxSizer* sizer, SavePresetDialog* parent, bool is_for_multiple_save):
m_type(type), m_type(type),
m_use_text_ctrl(parent->is_for_rename()), m_use_text_ctrl(parent->is_for_rename()),
m_parent(parent), m_parent(parent),
@ -105,14 +104,15 @@ SavePresetDialog::Item::Item(Preset::Type type, const std::string& suffix, wxBox
{ {
m_valid_label->SetFont(wxGetApp().bold_font()); m_valid_label->SetFont(wxGetApp().bold_font());
wxStaticText* label_top = new wxStaticText(m_parent, wxID_ANY, get_top_label_text()); wxStaticText* label_top = is_for_multiple_save ? new wxStaticText(m_parent, wxID_ANY, _(TOP_LABELS.at(m_type)) + ":") : nullptr;
wxBoxSizer* input_name_sizer = new wxBoxSizer(wxHORIZONTAL); wxBoxSizer* input_name_sizer = new wxBoxSizer(wxHORIZONTAL);
input_name_sizer->Add(m_valid_bmp, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, BORDER_W); input_name_sizer->Add(m_valid_bmp, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, BORDER_W);
init_input_name_ctrl(input_name_sizer, get_init_preset_name(suffix)); init_input_name_ctrl(input_name_sizer, get_init_preset_name(suffix));
if (label_top)
sizer->Add(label_top, 0, wxEXPAND | wxTOP| wxBOTTOM, BORDER_W); sizer->Add(label_top, 0, wxEXPAND | wxTOP| wxBOTTOM, BORDER_W);
sizer->Add(input_name_sizer,0, wxEXPAND | wxBOTTOM, BORDER_W); sizer->Add(input_name_sizer,0, wxEXPAND | (label_top ? 0 : wxTOP) | wxBOTTOM, BORDER_W);
sizer->Add(m_valid_label, 0, wxEXPAND | wxLEFT, 3*BORDER_W); sizer->Add(m_valid_label, 0, wxEXPAND | wxLEFT, 3*BORDER_W);
if (m_type == Preset::TYPE_PRINTER) if (m_type == Preset::TYPE_PRINTER)
@ -205,8 +205,6 @@ void SavePresetDialog::Item::update()
if ((!m_use_text_ctrl && m_presets->get_edited_preset().is_dirty) || if ((!m_use_text_ctrl && m_presets->get_edited_preset().is_dirty) ||
(dlg && dlg->get_preset_bundle())) // means that we save modifications from the DiffDialog (dlg && dlg->get_preset_bundle())) // means that we save modifications from the DiffDialog
info_line = _L("Save preset modifications to existing user profile"); info_line = _L("Save preset modifications to existing user profile");
else
info_line = _L("Nothing changed");
m_valid_type = ValidationType::Valid; m_valid_type = ValidationType::Valid;
} }
else { else {
@ -266,8 +264,8 @@ void SavePresetDialog::Item::update()
void SavePresetDialog::Item::update_valid_bmp() void SavePresetDialog::Item::update_valid_bmp()
{ {
std::string bmp_name = m_valid_type == ValidationType::Warning ? "exclamation" : std::string bmp_name = m_valid_type == ValidationType::Warning ? "exclamation_manifold" :
m_valid_type == ValidationType::NoValid ? "cross" : "tick_mark" ; m_valid_type == ValidationType::NoValid ? "exclamation" : "tick_mark" ;
m_valid_bmp->SetBitmap(*get_bmp_bundle(bmp_name)); m_valid_bmp->SetBitmap(*get_bmp_bundle(bmp_name));
} }
@ -289,22 +287,17 @@ void SavePresetDialog::Item::Enable(bool enable /*= true*/)
// SavePresetDialog // SavePresetDialog
//----------------------------------------------- //-----------------------------------------------
SavePresetDialog::SavePresetDialog(wxWindow* parent, Preset::Type type, std::string suffix, bool template_filament)
: DPIDialog(parent, wxID_ANY, _L("Save preset"), wxDefaultPosition, wxSize(45 * wxGetApp().em_unit(), 5 * wxGetApp().em_unit()), wxDEFAULT_DIALOG_STYLE | wxICON_WARNING | wxRESIZE_BORDER)
{
build(std::vector<Preset::Type>{type}, suffix, template_filament);
}
SavePresetDialog::SavePresetDialog(wxWindow* parent, std::vector<Preset::Type> types, std::string suffix, bool template_filament/* =false*/, PresetBundle* preset_bundle/* = nullptr*/) SavePresetDialog::SavePresetDialog(wxWindow* parent, std::vector<Preset::Type> types, std::string suffix, bool template_filament/* =false*/, PresetBundle* preset_bundle/* = nullptr*/)
: DPIDialog(parent, wxID_ANY, _L("Save presets"), wxDefaultPosition, wxSize(45 * wxGetApp().em_unit(), 5 * wxGetApp().em_unit()), wxDEFAULT_DIALOG_STYLE | wxICON_WARNING | wxRESIZE_BORDER), : DPIDialog(parent, wxID_ANY, types.size() == 1 ? _L("Save preset") : _L("Save presets"),
wxDefaultPosition, wxSize(45 * wxGetApp().em_unit(), 5 * wxGetApp().em_unit()), wxDEFAULT_DIALOG_STYLE | wxICON_WARNING),
m_preset_bundle(preset_bundle) m_preset_bundle(preset_bundle)
{ {
build(types, suffix, template_filament); build(types, suffix, template_filament);
} }
SavePresetDialog::SavePresetDialog(wxWindow* parent, Preset::Type type, bool rename, const wxString& info_line_extention) SavePresetDialog::SavePresetDialog(wxWindow* parent, Preset::Type type, const wxString& info_line_extention)
: DPIDialog(parent, wxID_ANY, _L("Rename preset"), wxDefaultPosition, wxSize(45 * wxGetApp().em_unit(), 5 * wxGetApp().em_unit()), wxDEFAULT_DIALOG_STYLE | wxICON_WARNING | wxRESIZE_BORDER), : DPIDialog(parent, wxID_ANY, _L("Rename preset"), wxDefaultPosition, wxSize(45 * wxGetApp().em_unit(), 5 * wxGetApp().em_unit()), wxDEFAULT_DIALOG_STYLE | wxICON_WARNING),
m_use_for_rename(rename), m_use_for_rename(true),
m_info_line_extention(info_line_extention) m_info_line_extention(info_line_extention)
{ {
build(std::vector<Preset::Type>{type}); build(std::vector<Preset::Type>{type});
@ -335,9 +328,9 @@ void SavePresetDialog::build(std::vector<Preset::Type> types, std::string suffix
m_presets_sizer = new wxBoxSizer(wxVERTICAL); m_presets_sizer = new wxBoxSizer(wxVERTICAL);
// Add first item const bool is_for_multiple_save = types.size() > 1;
for (Preset::Type type : types) for (const Preset::Type& type : types)
AddItem(type, suffix); AddItem(type, suffix, is_for_multiple_save);
// Add dialog's buttons // Add dialog's buttons
wxStdDialogButtonSizer* btns = this->CreateStdDialogButtonSizer(wxOK | wxCANCEL); wxStdDialogButtonSizer* btns = this->CreateStdDialogButtonSizer(wxOK | wxCANCEL);
@ -367,9 +360,9 @@ void SavePresetDialog::build(std::vector<Preset::Type> types, std::string suffix
#endif #endif
} }
void SavePresetDialog::AddItem(Preset::Type type, const std::string& suffix) void SavePresetDialog::AddItem(Preset::Type type, const std::string& suffix, bool is_for_multiple_save)
{ {
m_items.emplace_back(new Item{type, suffix, m_presets_sizer, this}); m_items.emplace_back(new Item{type, suffix, m_presets_sizer, this, is_for_multiple_save});
} }
std::string SavePresetDialog::get_name() std::string SavePresetDialog::get_name()

View File

@ -36,7 +36,7 @@ public:
Warning Warning
}; };
Item(Preset::Type type, const std::string& suffix, wxBoxSizer* sizer, SavePresetDialog* parent); Item(Preset::Type type, const std::string& suffix, wxBoxSizer* sizer, SavePresetDialog* parent, bool is_for_multiple_save);
Item(wxWindow* parent, wxBoxSizer* sizer, const std::string& def_name, PrinterTechnology pt = ptFFF); Item(wxWindow* parent, wxBoxSizer* sizer, const std::string& def_name, PrinterTechnology pt = ptFFF);
void update_valid_bmp(); void update_valid_bmp();
@ -65,7 +65,6 @@ public:
std::string get_init_preset_name(const std::string &suffix); std::string get_init_preset_name(const std::string &suffix);
void init_input_name_ctrl(wxBoxSizer *input_name_sizer, std::string preset_name); void init_input_name_ctrl(wxBoxSizer *input_name_sizer, std::string preset_name);
const Preset* get_existing_preset() const ; const Preset* get_existing_preset() const ;
wxString get_top_label_text() const ;
void update(); void update();
}; };
@ -89,12 +88,11 @@ public:
const wxString& get_info_line_extention() { return m_info_line_extention; } const wxString& get_info_line_extention() { return m_info_line_extention; }
SavePresetDialog(wxWindow* parent, Preset::Type type, std::string suffix = "", bool template_filament = false);
SavePresetDialog(wxWindow* parent, std::vector<Preset::Type> types, std::string suffix = "", bool template_filament = false, PresetBundle* preset_bundle = nullptr); SavePresetDialog(wxWindow* parent, std::vector<Preset::Type> types, std::string suffix = "", bool template_filament = false, PresetBundle* preset_bundle = nullptr);
SavePresetDialog(wxWindow* parent, Preset::Type type, bool rename, const wxString& info_line_extention); SavePresetDialog(wxWindow* parent, Preset::Type type, const wxString& info_line_extention);
~SavePresetDialog() override; ~SavePresetDialog() override;
void AddItem(Preset::Type type, const std::string& suffix); void AddItem(Preset::Type type, const std::string& suffix, bool is_for_multiple_save);
PresetBundle* get_preset_bundle() const { return m_preset_bundle; } PresetBundle* get_preset_bundle() const { return m_preset_bundle; }
std::string get_name(); std::string get_name();

View File

@ -3820,7 +3820,7 @@ void Tab::save_preset(std::string name /*= ""*/, bool detach)
} }
if (name.empty()) { if (name.empty()) {
SavePresetDialog dlg(m_parent, m_type, detach ? _u8L("Detached") : "", from_template); SavePresetDialog dlg(m_parent, { m_type }, detach ? _u8L("Detached") : "", from_template);
if (dlg.ShowModal() != wxID_OK) if (dlg.ShowModal() != wxID_OK)
return; return;
name = dlg.get_name(); name = dlg.get_name();
@ -3931,7 +3931,7 @@ void Tab::rename_preset()
// get new name // get new name
SavePresetDialog dlg(m_parent, m_type, true, msg); SavePresetDialog dlg(m_parent, m_type, msg);
if (dlg.ShowModal() != wxID_OK) if (dlg.ShowModal() != wxID_OK)
return; return;

View File

@ -1012,7 +1012,7 @@ bool UnsavedChangesDialog::save(PresetCollection* dependent_presets, bool show_s
// for system/default/external presets we should take an edited name // for system/default/external presets we should take an edited name
if (preset.is_system || preset.is_default || preset.is_external) { if (preset.is_system || preset.is_default || preset.is_external) {
SavePresetDialog save_dlg(this, preset.type); SavePresetDialog save_dlg(this, { preset.type });
if (save_dlg.ShowModal() != wxID_OK) { if (save_dlg.ShowModal() != wxID_OK) {
m_exit_action = Action::Discard; m_exit_action = Action::Discard;
return false; return false;