FIX: move preset dirty suffix to prefix

Change-Id: I52d4d6e3dea28d071eb7bf2f3b5e77b5e1b8c8bb
This commit is contained in:
chunmao.guo 2022-09-22 10:28:46 +08:00 committed by Lane.Wei
parent 99fcecf193
commit c5024af7e2
4 changed files with 19 additions and 29 deletions

View File

@ -307,8 +307,8 @@ void Preset::update_suffix_modified(const std::string& new_suffix_modified)
// This converts a UI name to a unique preset identifier. // This converts a UI name to a unique preset identifier.
std::string Preset::remove_suffix_modified(const std::string &name) std::string Preset::remove_suffix_modified(const std::string &name)
{ {
return boost::algorithm::ends_with(name, g_suffix_modified) ? return boost::algorithm::starts_with(name, g_suffix_modified) ?
name.substr(0, name.size() - g_suffix_modified.size()) : name.substr(g_suffix_modified.size()) :
name; name;
} }
@ -530,9 +530,10 @@ void Preset::save(DynamicPrintConfig* parent_config)
} }
// Return a label of this preset, consisting of a name and a "(modified)" suffix, if this preset is dirty. // Return a label of this preset, consisting of a name and a "(modified)" suffix, if this preset is dirty.
std::string Preset::label() const std::string Preset::label(bool no_alias) const
{ {
return this->name + (this->is_dirty ? g_suffix_modified : ""); return (this->is_dirty ? g_suffix_modified : "")
+ ((no_alias || this->alias.empty()) ? this->name : this->alias);
} }
bool is_compatible_with_print(const PresetWithVendorProfile &preset, const PresetWithVendorProfile &active_print, const PresetWithVendorProfile &active_printer) bool is_compatible_with_print(const PresetWithVendorProfile &preset, const PresetWithVendorProfile &active_print, const PresetWithVendorProfile &active_printer)

View File

@ -245,7 +245,7 @@ public:
void save(DynamicPrintConfig* parent_config); void save(DynamicPrintConfig* parent_config);
// Return a label of this preset, consisting of a name and a "(modified)" suffix, if this preset is dirty. // Return a label of this preset, consisting of a name and a "(modified)" suffix, if this preset is dirty.
std::string label() const; std::string label(bool no_alias) const;
// Set the is_dirty flag if the provided config is different from the active one. // Set the is_dirty flag if the provided config is different from the active one.
void set_dirty(const DynamicPrintConfig &config) { this->is_dirty = ! this->config.diff(config).empty(); } void set_dirty(const DynamicPrintConfig &config) { this->is_dirty = ! this->config.diff(config).empty(); }

View File

@ -3999,7 +3999,7 @@ bool GUI_App::load_language(wxString language, bool initial)
//FIXME This is a temporary workaround, the correct solution is to switch to "C" locale during file import / export only. //FIXME This is a temporary workaround, the correct solution is to switch to "C" locale during file import / export only.
//wxSetlocale(LC_NUMERIC, "C"); //wxSetlocale(LC_NUMERIC, "C");
Preset::update_suffix_modified((" (" + _L("*") + ")").ToUTF8().data()); Preset::update_suffix_modified((_L("*") + " ").ToUTF8().data());
return true; return true;
} }

View File

@ -244,16 +244,6 @@ int PresetComboBox::update_ams_color()
return idx; return idx;
} }
static std::string suffix(const Preset& preset)
{
return (preset.is_dirty ? Preset::suffix_modified() : "");
}
static std::string suffix(Preset* preset)
{
return (preset->is_dirty ? Preset::suffix_modified() : "");
}
wxColor PresetComboBox::different_color(wxColor const &clr) wxColor PresetComboBox::different_color(wxColor const &clr)
{ {
if (clr.GetLuminance() < 0.51) return *wxWHITE; if (clr.GetLuminance() < 0.51) return *wxWHITE;
@ -771,7 +761,7 @@ void PlaterPresetComboBox::switch_to_tab()
if (m_type == Preset::TYPE_FILAMENT) if (m_type == Preset::TYPE_FILAMENT)
{ {
const std::string& selected_preset = GetString(GetSelection()).ToUTF8().data(); const std::string& selected_preset = GetString(GetSelection()).ToUTF8().data();
if (!boost::algorithm::ends_with(selected_preset, Preset::suffix_modified())) if (!boost::algorithm::starts_with(selected_preset, Preset::suffix_modified()))
{ {
const std::string& preset_name = wxGetApp().preset_bundle->filaments.get_preset_name_by_alias(selected_preset); const std::string& preset_name = wxGetApp().preset_bundle->filaments.get_preset_name_by_alias(selected_preset);
wxGetApp().get_tab(m_type)->select_preset(preset_name); wxGetApp().get_tab(m_type)->select_preset(preset_name);
@ -869,8 +859,7 @@ void PlaterPresetComboBox::show_edit_menu()
wxString PlaterPresetComboBox::get_preset_name(const Preset& preset) wxString PlaterPresetComboBox::get_preset_name(const Preset& preset)
{ {
std::string name = preset.alias.empty() ? preset.name : preset.alias; return from_u8(preset.label(false));
return from_u8(name + suffix(preset));
} }
// Only the compatible presets are shown. // Only the compatible presets are shown.
@ -979,10 +968,10 @@ void PlaterPresetComboBox::update()
const std::string name = preset.alias.empty() ? preset.name : preset.alias; const std::string name = preset.alias.empty() ? preset.name : preset.alias;
if (preset.is_default || preset.is_system) { if (preset.is_default || preset.is_system) {
//BBS: move system to the end //BBS: move system to the end
system_presets.emplace(wxString::FromUTF8((name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), bmp); system_presets.emplace(get_preset_name(preset), bmp);
if (is_selected) { if (is_selected) {
tooltip = get_tooltip(preset); tooltip = get_tooltip(preset);
selected_system_preset = wxString::FromUTF8((name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()); selected_system_preset = get_preset_name(preset);
} }
//Append(get_preset_name(preset), *bmp); //Append(get_preset_name(preset), *bmp);
//validate_selection(is_selected); //validate_selection(is_selected);
@ -993,9 +982,9 @@ void PlaterPresetComboBox::update()
//BBS: add project embedded preset logic //BBS: add project embedded preset logic
else if (preset.is_project_embedded) else if (preset.is_project_embedded)
{ {
project_embedded_presets.emplace(wxString::FromUTF8((name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), bmp); project_embedded_presets.emplace(get_preset_name(preset), bmp);
if (is_selected) { if (is_selected) {
selected_user_preset = wxString::FromUTF8((name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()); selected_user_preset = get_preset_name(preset);
tooltip = wxString::FromUTF8(preset.name.c_str()); tooltip = wxString::FromUTF8(preset.name.c_str());
} }
} }
@ -1166,7 +1155,7 @@ void TabPresetComboBox::OnSelect(wxCommandEvent &evt)
wxString TabPresetComboBox::get_preset_name(const Preset& preset) wxString TabPresetComboBox::get_preset_name(const Preset& preset)
{ {
return from_u8(preset.name + suffix(preset)); return from_u8(preset.label(true));
} }
// Update the choice UI from the list of presets. // Update the choice UI from the list of presets.
@ -1221,9 +1210,9 @@ void TabPresetComboBox::update()
if (preset.is_default || preset.is_system) { if (preset.is_default || preset.is_system) {
//BBS: move system to the end //BBS: move system to the end
system_presets.emplace(wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), std::pair<wxBitmap*, bool>(bmp, is_enabled)); system_presets.emplace(get_preset_name(preset), std::pair<wxBitmap *, bool>(bmp, is_enabled));
if (i == idx_selected) if (i == idx_selected)
selected = wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()); selected = get_preset_name(preset);
//int item_id = Append(get_preset_name(preset), *bmp); //int item_id = Append(get_preset_name(preset), *bmp);
//if (!is_enabled) //if (!is_enabled)
// set_label_marker(item_id, LABEL_ITEM_DISABLED); // set_label_marker(item_id, LABEL_ITEM_DISABLED);
@ -1233,9 +1222,9 @@ void TabPresetComboBox::update()
else if (preset.is_project_embedded) else if (preset.is_project_embedded)
{ {
//std::pair<wxBitmap*, bool> pair(bmp, is_enabled); //std::pair<wxBitmap*, bool> pair(bmp, is_enabled);
project_embedded_presets.emplace(wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), std::pair<wxBitmap*, bool>(bmp, is_enabled)); project_embedded_presets.emplace(get_preset_name(preset), std::pair<wxBitmap *, bool>(bmp, is_enabled));
if (i == idx_selected) if (i == idx_selected)
selected = wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()); selected = get_preset_name(preset);
} }
else else
{ {
@ -1364,7 +1353,7 @@ void TabPresetComboBox::update_dirty()
Preset* preset = m_collection->find_preset(preset_name, false); Preset* preset = m_collection->find_preset(preset_name, false);
if (preset) { if (preset) {
std::string new_label = preset->name + suffix(preset); std::string new_label = preset->label(true);
if (marker == LABEL_ITEM_PHYSICAL_PRINTER) if (marker == LABEL_ITEM_PHYSICAL_PRINTER)
new_label = ph_printer_name + PhysicalPrinter::separator() + new_label; new_label = ph_printer_name + PhysicalPrinter::separator() + new_label;