InfoDialog: Improvements

* Fixed localization
* Substitutions are aligned in table
This commit is contained in:
YuSanka 2021-06-30 14:19:20 +02:00
parent 3e173d1c1e
commit 88d5f40b7c
2 changed files with 48 additions and 24 deletions

View File

@ -258,25 +258,32 @@ void warning_catcher(wxWindow* parent, const wxString& message)
msg.ShowModal();
}
static wxString bold(const wxString& str)
{
return wxString::Format("<b>\"%s\"</b>", str);
};
static void add_config_substitutions(const ConfigSubstitutions& conf_substitutions, wxString& changes)
{
changes += "<table>";
for (const ConfigSubstitution& conf_substitution : conf_substitutions) {
wxString new_val;
if (!conf_substitution.opt_def)
const ConfigOptionDef* def = conf_substitution.opt_def;
if (!def)
continue;
if (conf_substitution.opt_def->type == coEnum) {
const std::vector<std::string>& labels = conf_substitution.opt_def->enum_labels;
const std::vector<std::string>& values = conf_substitution.opt_def->enum_values;
if (def->type == coEnum) {
const std::vector<std::string>& labels = def->enum_labels;
const std::vector<std::string>& values = def->enum_values;
int val = conf_substitution.new_value->getInt();
bool is_infill = conf_substitution.opt_def->opt_key == "top_fill_pattern" ||
conf_substitution.opt_def->opt_key == "bottom_fill_pattern" ||
conf_substitution.opt_def->opt_key == "fill_pattern";
bool is_infill = def->opt_key == "top_fill_pattern" ||
def->opt_key == "bottom_fill_pattern" ||
def->opt_key == "fill_pattern";
// Each infill doesn't use all list of infill declared in PrintConfig.hpp.
// So we should "convert" val to the correct one
if (is_infill) {
for (const auto& key_val : *conf_substitution.opt_def->enum_keys_map)
for (const auto& key_val : *def->enum_keys_map)
if ((int)key_val.second == val) {
auto it = std::find(values.begin(), values.end(), key_val.first);
if (it == values.end())
@ -284,16 +291,20 @@ static void add_config_substitutions(const ConfigSubstitutions& conf_substitutio
new_val = from_u8(_utf8(labels[it - values.begin()]));
break;
}
new_val = _L("Undef");
if (new_val.IsEmpty())
new_val = _L("Undef");
}
else
new_val = from_u8(_utf8(labels[val]));
}
else if (conf_substitution.opt_def->type == coBool)
else if (def->type == coBool)
new_val = conf_substitution.new_value->getBool() ? "true" : "false";
changes += "\n" + GUI::format(_L("New unknown value <b>\"%1%\"</b> was changed to defaul value <b>\"%2%\"</b>"), conf_substitution.old_value, new_val);
changes += "<tr><td>" + bold(_(def->label)) + "</td><td>: " +
format_wxstr(_L("new unknown value %1% was changed to default value %2%"), bold(conf_substitution.old_value), bold(new_val)) +
"</td></tr>";
}
changes += "</table>";
}
void show_substitutions_info(const PresetsConfigSubstitutions& presets_config_substitutions)
@ -301,27 +312,26 @@ void show_substitutions_info(const PresetsConfigSubstitutions& presets_config_su
wxString changes;
auto preset_type_name = [](Preset::Type type) {
return type == Slic3r::Preset::TYPE_PRINT ? _L("Print") :
type == Slic3r::Preset::TYPE_SLA_PRINT ? _L("SLA Print") :
type == Slic3r::Preset::TYPE_FILAMENT ? _L("Filament") :
type == Slic3r::Preset::TYPE_SLA_MATERIAL ? _L("SLA Material") :
type == Slic3r::Preset::TYPE_PRINTER ? _L("Printer") : "";
return type == Slic3r::Preset::TYPE_PRINT ? _L("Print settings") :
type == Slic3r::Preset::TYPE_SLA_PRINT ? _L("SLA print settings") :
type == Slic3r::Preset::TYPE_FILAMENT ? _L("Filament") :
type == Slic3r::Preset::TYPE_SLA_MATERIAL ? _L("SLA material") :
type == Slic3r::Preset::TYPE_PRINTER ? _L("Printer") : "" ;
};
for (const PresetConfigSubstitutions& substitution : presets_config_substitutions) {
changes += "\n<p>" + GUI::format(_L(" %1% Preset : <b>%2%</b>"), preset_type_name(substitution.preset_type), substitution.preset_name);
changes += "\n\n" + format_wxstr("%1% : %2%", preset_type_name(substitution.preset_type), bold(substitution.preset_name));
if (!substitution.preset_file.empty())
changes += GUI::format(" (%1%)", substitution.preset_file);
changes += "</p>";
changes += format_wxstr(" (%1%)", substitution.preset_file);
add_config_substitutions(substitution.substitutions, changes);
}
if (!changes.IsEmpty())
changes += "\n\n";
wxString message = format(_L("Loading profiles found following incompatibilities:%1%"
" To recover these files, incompatible values were changed to default values.\n"
" But data in files won't be changed until you save them in PrusaSlicer."), changes);
wxString message = format_wxstr( _L("Loading profiles found following incompatibilities:%1%"
" To recover these files, incompatible values were changed to default values.\n"
" But data in files won't be changed until you save them in PrusaSlicer."), changes);
InfoDialog msg(nullptr, message);
msg.ShowModal();

View File

@ -119,7 +119,6 @@ InfoDialog::InfoDialog(wxWindow* parent, const wxString& msg)
// Text shown as HTML, so that mouse selection and Ctrl-V to copy will work.
wxHtmlWindow* html = new wxHtmlWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_AUTO);
{
html->SetMinSize(wxSize(40 * wxGetApp().em_unit(), -1));
wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
wxFont monospace = wxGetApp().code_font();
wxColour text_clr = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
@ -130,6 +129,22 @@ InfoDialog::InfoDialog(wxWindow* parent, const wxString& msg)
int size[] = { font_size, font_size, font_size, font_size, font_size, font_size, font_size };
html->SetFonts(font.GetFaceName(), monospace.GetFaceName(), size);
html->SetBorders(2);
// calculate html page size from text
int lines = msg.Freq('\n');
if (msg.Contains("<tr>")) {
int pos = 0;
while (pos < (int)msg.Len() && pos != wxNOT_FOUND) {
pos = msg.find("<tr>", pos + 1);
lines+=2;
}
}
int page_height = std::min((font.GetPixelSize().y + 1) * lines, 68 * wxGetApp().em_unit());
wxSize page_size(68 * wxGetApp().em_unit(), page_height);
html->SetMinSize(page_size);
std::string msg_escaped = xml_escape(msg.ToUTF8().data(), true);
boost::replace_all(msg_escaped, "\r\n", "<br>");
boost::replace_all(msg_escaped, "\n", "<br>");
@ -140,7 +155,6 @@ InfoDialog::InfoDialog(wxWindow* parent, const wxString& msg)
// Set info bitmap
logo->SetBitmap(create_scaled_bitmap("info", this, 84));
SetMinSize(wxSize(60 * wxGetApp().em_unit(), 30 * wxGetApp().em_unit()));
Fit();
}