SPE-1207 - Extensions in Open/Save/Export dialogs - alternative implementation for file_wildcards()

This commit is contained in:
enricoturri1966 2022-03-17 14:20:35 +01:00
parent dfd6ca899a
commit 99861f1b6e
4 changed files with 53 additions and 1 deletions

View File

@ -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_

View File

@ -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
@ -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(); }

View File

@ -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,

View File

@ -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) {