diff --git a/src/slic3r/GUI/ExtraRenderers.cpp b/src/slic3r/GUI/ExtraRenderers.cpp index 533b59398d..874df1b4ab 100644 --- a/src/slic3r/GUI/ExtraRenderers.cpp +++ b/src/slic3r/GUI/ExtraRenderers.cpp @@ -3,6 +3,7 @@ #include "GUI.hpp" #include "I18N.hpp" #include "BitmapComboBox.hpp" +#include "Plater.hpp" #include #ifdef wxHAS_GENERIC_DATAVIEWCTRL @@ -222,14 +223,8 @@ bool BitmapTextRenderer::GetValueFromEditorCtrl(wxWindow* ctrl, wxVariant& value if (!text_editor || text_editor->GetValue().IsEmpty()) return false; - std::string chosen_name = into_u8(text_editor->GetValue()); - const char* unusable_symbols = "<>:/\\|?*\""; - for (size_t i = 0; i < std::strlen(unusable_symbols); i++) { - if (chosen_name.find_first_of(unusable_symbols[i]) != std::string::npos) { - m_was_unusable_symbol = true; - return false; - } - } + if (m_was_unusable_symbol = Slic3r::GUI::Plater::has_illegal_filename_characters(text_editor->GetValue())) + return false; // The icon can't be edited so get its old value and reuse it. wxVariant valueOld; diff --git a/src/slic3r/GUI/GUI_ObjectList.cpp b/src/slic3r/GUI/GUI_ObjectList.cpp index cd8e8e6a02..7d689ff6a2 100644 --- a/src/slic3r/GUI/GUI_ObjectList.cpp +++ b/src/slic3r/GUI/GUI_ObjectList.cpp @@ -4016,18 +4016,8 @@ void ObjectList::rename_item() if (new_name.IsEmpty()) return; - bool is_unusable_symbol = false; - std::string chosen_name = Slic3r::normalize_utf8_nfc(new_name.ToUTF8()); - const char* unusable_symbols = "<>:/\\|?*\""; - for (size_t i = 0; i < std::strlen(unusable_symbols); i++) { - if (chosen_name.find_first_of(unusable_symbols[i]) != std::string::npos) { - is_unusable_symbol = true; - } - } - - if (is_unusable_symbol) { - show_error(this, _(L("The supplied name is not valid;")) + "\n" + - _(L("the following characters are not allowed:")) + " <>:/\\|?*\""); + if (Plater::has_illegal_filename_characters(new_name)) { + Plater::show_illegal_characters_warning(this); return; } @@ -4247,10 +4237,7 @@ void ObjectList::OnEditingDone(wxDataViewEvent &event) const auto renderer = dynamic_cast(GetColumn(colName)->GetRenderer()); if (renderer->WasCanceled()) - wxTheApp->CallAfter([this]{ - show_error(this, _(L("The supplied name is not valid;")) + "\n" + - _(L("the following characters are not allowed:")) + " <>:/\\|?*\""); - }); + wxTheApp->CallAfter([this]{ Plater::show_illegal_characters_warning(this); }); #ifdef __WXMSW__ // Workaround for entering the column editing mode on Windows. Simulate keyboard enter when another column of the active line is selected. diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 322c0cdf6d..8e34c05c90 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -119,6 +119,30 @@ wxDEFINE_EVENT(EVT_SLICING_COMPLETED, wxCommandEvent); wxDEFINE_EVENT(EVT_PROCESS_COMPLETED, SlicingProcessCompletedEvent); wxDEFINE_EVENT(EVT_EXPORT_BEGAN, wxCommandEvent); + +bool Plater::has_illegal_filename_characters(const wxString& wxs_name) +{ + std::string name = into_u8(wxs_name); + return has_illegal_filename_characters(name); +} + +bool Plater::has_illegal_filename_characters(const std::string& name) +{ + const char* illegal_characters = "<>:/\\|?*\""; + for (size_t i = 0; i < std::strlen(illegal_characters); i++) + if (name.find_first_of(illegal_characters[i]) != std::string::npos) + return true; + + return false; +} + +void Plater::show_illegal_characters_warning(wxWindow* parent) +{ + show_error(parent, _L("The supplied name is not valid;") + "\n" + + _L("the following characters are not allowed:") + " <>:/\\|?*\""); +} + + // Sidebar widgets // struct InfoBox : public wxStaticBox @@ -5685,8 +5709,15 @@ void Plater::export_gcode(bool prefer_removable) GUI::file_wildcards((printer_technology() == ptFFF) ? FT_GCODE : boost::iequals(ext, ".sl1s") ? FT_SL1S : FT_SL1, ext), wxFD_SAVE | wxFD_OVERWRITE_PROMPT ); - if (dlg.ShowModal() == wxID_OK) + if (dlg.ShowModal() == wxID_OK) { output_path = into_path(dlg.GetPath()); + while (has_illegal_filename_characters(output_path.filename().string())) { + show_illegal_characters_warning(this); + dlg.SetFilename(from_path(output_path.filename())); + if (dlg.ShowModal() == wxID_OK) + output_path = into_path(dlg.GetPath()); + } + } } if (! output_path.empty()) { diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index ef30170724..19bd67edad 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -426,6 +426,10 @@ public: wxMenu* layer_menu(); wxMenu* multi_selection_menu(); + static bool has_illegal_filename_characters(const wxString& name); + static bool has_illegal_filename_characters(const std::string& name); + static void show_illegal_characters_warning(wxWindow* parent); + private: struct priv; std::unique_ptr p;