From 3ad5f52b00c97cb229fd1e1cfda6fe3fb51fc6a6 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Mon, 27 Mar 2023 13:34:21 +0200 Subject: [PATCH] Simplified "Save/Rename Preset" dialog when only one preset is saved/renamed. --- src/slic3r/GUI/SavePresetDialog.cpp | 57 +++++++++++-------------- src/slic3r/GUI/SavePresetDialog.hpp | 8 ++-- src/slic3r/GUI/Tab.cpp | 4 +- src/slic3r/GUI/UnsavedChangesDialog.cpp | 2 +- 4 files changed, 31 insertions(+), 40 deletions(-) diff --git a/src/slic3r/GUI/SavePresetDialog.cpp b/src/slic3r/GUI/SavePresetDialog.cpp index 33f41b9c4e..09ae10207d 100644 --- a/src/slic3r/GUI/SavePresetDialog.cpp +++ b/src/slic3r/GUI/SavePresetDialog.cpp @@ -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 TOP_LABELS = { - const std::string label_str = m_use_text_ctrl ? - // TRN %1% = "Preset" - L("Rename %1% to") : - // TRN %1% = "Preset" - L("Save %1% as"); - Tab* tab = wxGetApp().get_tab(m_type); - return format_wxstr(_(label_str) + ":", tab->title()); -} + // type Save settings + { Preset::Type::TYPE_PRINT, L("Save print settings as") }, + { Preset::Type::TYPE_SLA_PRINT, L("Save print settings as") }, + { Preset::Type::TYPE_FILAMENT, L("Save filament settings as")}, + { Preset::Type::TYPE_SLA_MATERIAL, L("Save material settings as")}, + { Preset::Type::TYPE_PRINTER, L("Save printer settings as") }, +}; -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_use_text_ctrl(parent->is_for_rename()), 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()); - 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); 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)); - sizer->Add(label_top, 0, wxEXPAND | wxTOP| wxBOTTOM, BORDER_W); - sizer->Add(input_name_sizer,0, wxEXPAND | wxBOTTOM, BORDER_W); + if (label_top) + sizer->Add(label_top, 0, wxEXPAND | wxTOP| 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); 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) || (dlg && dlg->get_preset_bundle())) // means that we save modifications from the DiffDialog info_line = _L("Save preset modifications to existing user profile"); - else - info_line = _L("Nothing changed"); m_valid_type = ValidationType::Valid; } else { @@ -266,8 +264,8 @@ void SavePresetDialog::Item::update() void SavePresetDialog::Item::update_valid_bmp() { - std::string bmp_name = m_valid_type == ValidationType::Warning ? "exclamation" : - m_valid_type == ValidationType::NoValid ? "cross" : "tick_mark" ; + std::string bmp_name = m_valid_type == ValidationType::Warning ? "exclamation_manifold" : + m_valid_type == ValidationType::NoValid ? "exclamation" : "tick_mark" ; m_valid_bmp->SetBitmap(*get_bmp_bundle(bmp_name)); } @@ -289,22 +287,17 @@ void SavePresetDialog::Item::Enable(bool enable /*= true*/) // 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{type}, suffix, template_filament); -} - SavePresetDialog::SavePresetDialog(wxWindow* parent, std::vector 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) { build(types, suffix, template_filament); } -SavePresetDialog::SavePresetDialog(wxWindow* parent, Preset::Type type, bool rename, 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), - m_use_for_rename(rename), +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), + m_use_for_rename(true), m_info_line_extention(info_line_extention) { build(std::vector{type}); @@ -335,9 +328,9 @@ void SavePresetDialog::build(std::vector types, std::string suffix m_presets_sizer = new wxBoxSizer(wxVERTICAL); - // Add first item - for (Preset::Type type : types) - AddItem(type, suffix); + const bool is_for_multiple_save = types.size() > 1; + for (const Preset::Type& type : types) + AddItem(type, suffix, is_for_multiple_save); // Add dialog's buttons wxStdDialogButtonSizer* btns = this->CreateStdDialogButtonSizer(wxOK | wxCANCEL); @@ -367,9 +360,9 @@ void SavePresetDialog::build(std::vector types, std::string suffix #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() diff --git a/src/slic3r/GUI/SavePresetDialog.hpp b/src/slic3r/GUI/SavePresetDialog.hpp index 3088d457f6..1450ebbd24 100644 --- a/src/slic3r/GUI/SavePresetDialog.hpp +++ b/src/slic3r/GUI/SavePresetDialog.hpp @@ -36,7 +36,7 @@ public: 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); void update_valid_bmp(); @@ -65,7 +65,6 @@ public: std::string get_init_preset_name(const std::string &suffix); void init_input_name_ctrl(wxBoxSizer *input_name_sizer, std::string preset_name); const Preset* get_existing_preset() const ; - wxString get_top_label_text() const ; void update(); }; @@ -89,12 +88,11 @@ public: 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 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; - 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; } std::string get_name(); diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 1b2a1ba816..3fb7bf6058 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -3820,7 +3820,7 @@ void Tab::save_preset(std::string name /*= ""*/, bool detach) } 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) return; name = dlg.get_name(); @@ -3931,7 +3931,7 @@ void Tab::rename_preset() // get new name - SavePresetDialog dlg(m_parent, m_type, true, msg); + SavePresetDialog dlg(m_parent, m_type, msg); if (dlg.ShowModal() != wxID_OK) return; diff --git a/src/slic3r/GUI/UnsavedChangesDialog.cpp b/src/slic3r/GUI/UnsavedChangesDialog.cpp index d7d4798c20..ad702c1b31 100644 --- a/src/slic3r/GUI/UnsavedChangesDialog.cpp +++ b/src/slic3r/GUI/UnsavedChangesDialog.cpp @@ -1012,7 +1012,7 @@ bool UnsavedChangesDialog::save(PresetCollection* dependent_presets, bool show_s // for system/default/external presets we should take an edited name 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) { m_exit_action = Action::Discard; return false;