Skip to content

Commit

Permalink
SPE-1207 - Extensions in Open/Save/Export dialogs - alternative imple…
Browse files Browse the repository at this point in the history
…mentation for file_wildcards()
  • Loading branch information
enricoturri1966 committed Mar 17, 2022
1 parent dfd6ca8 commit 99861f1
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/libslic3r/Technologies.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@
#define ENABLE_NEW_CAMERA_MOVEMENTS (1 && ENABLE_2_5_0_ALPHA1)
// Enable modified rectangle selection
#define ENABLE_NEW_RECTANGLE_SELECTION (1 && ENABLE_2_5_0_ALPHA1)
// Enable alternative version of file_wildcards()
#define ENABLE_ALTERNATIVE_FILE_WILDCARDS_GENERATOR (1 && ENABLE_2_5_0_ALPHA1)


#endif // _prusaslicer_technologies_h_
40 changes: 40 additions & 0 deletions src/slic3r/GUI/GUI_App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,44 @@ static const FileWildcards file_wildcards_by_type[FT_SIZE] = {
/* FT_SL1 */ { "Masked SLA files"sv, { ".sl1"sv, ".sl1s"sv, ".pwmx"sv } },
};

#if ENABLE_ALTERNATIVE_FILE_WILDCARDS_GENERATOR
wxString file_wildcards(FileType file_type)
{
const FileWildcards& data = file_wildcards_by_type[file_type];
std::string title;
std::string mask;

// Generate cumulative first item
for (const std::string_view& ext : data.file_extensions) {
if (title.empty()) {
title = "*";
title += ext;
mask = title;
}
else {
title += ", *";
title += ext;
mask += ";*";
mask += ext;
}
mask += ";*";
mask += boost::to_upper_copy(std::string(ext));
}

wxString ret = GUI::format_wxstr("%s (%s)|%s", data.title, title, mask);

// Adds an item for each of the extensions
if (data.file_extensions.size() > 1) {
for (const std::string_view& ext : data.file_extensions) {
title = "*";
title += ext;
ret += GUI::format_wxstr("|%s (%s)|%s", data.title, title, title);
}
}

return ret;
}
#else
// This function produces a Win32 file dialog file template mask to be consumed by wxWidgets on all platforms.
// The function accepts a custom extension parameter. If the parameter is provided, the custom extension
// will be added as a fist to the list. This is important for a "file save" dialog on OSX, which strips
Expand Down Expand Up @@ -551,8 +589,10 @@ wxString file_wildcards(FileType file_type, const std::string &custom_extension)
mask += ";*";
mask += boost::to_upper_copy(std::string(ext));
}

return GUI::format_wxstr("%s (%s)|%s", data.title, title, mask);
}
#endif // ENABLE_ALTERNATIVE_FILE_WILDCARDS_GENERATOR

static std::string libslic3r_translate_callback(const char *s) { return wxGetTranslation(wxString(s, wxConvUTF8)).utf8_str().data(); }

Expand Down
4 changes: 4 additions & 0 deletions src/slic3r/GUI/GUI_App.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ enum FileType
FT_SIZE,
};

#if ENABLE_ALTERNATIVE_FILE_WILDCARDS_GENERATOR
extern wxString file_wildcards(FileType file_type);
#else
extern wxString file_wildcards(FileType file_type, const std::string &custom_extension = std::string{});
#endif // ENABLE_ALTERNATIVE_FILE_WILDCARDS_GENERATOR

enum ConfigMenuIDs {
ConfigMenuWizard,
Expand Down
8 changes: 7 additions & 1 deletion src/slic3r/GUI/Plater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5919,11 +5919,17 @@ void Plater::export_gcode(bool prefer_removable)

fs::path output_path;
{
std::string ext = default_output_file.extension().string();
#if !ENABLE_ALTERNATIVE_FILE_WILDCARDS_GENERATOR
std::string ext = default_output_file.extension().string();
#endif // !ENABLE_ALTERNATIVE_FILE_WILDCARDS_GENERATOR
wxFileDialog dlg(this, (printer_technology() == ptFFF) ? _L("Save G-code file as:") : _L("Save SL1 / SL1S file as:"),
start_dir,
from_path(default_output_file.filename()),
#if ENABLE_ALTERNATIVE_FILE_WILDCARDS_GENERATOR
GUI::file_wildcards((printer_technology() == ptFFF) ? FT_GCODE : FT_SL1),
#else
GUI::file_wildcards((printer_technology() == ptFFF) ? FT_GCODE : FT_SL1, ext),
#endif // ENABLE_ALTERNATIVE_FILE_WILDCARDS_GENERATOR
wxFD_SAVE | wxFD_OVERWRITE_PROMPT
);
if (dlg.ShowModal() == wxID_OK) {
Expand Down

0 comments on commit 99861f1

Please sign in to comment.