Preset: New flag "respect_active_preset" is added to preset(name).
Return values, when preset i sactive: - edited_preset, when respect_active_preset==true - selected_preset, when respect_active_preset==false + UnsavedChangedDialog: Implementation for FR #7393 - "Switching Presets: Unsaved Changes" table + DiffDialog: Implemented possibility to compare selected and edited presets
This commit is contained in:
parent
0146e8d863
commit
8cc1a58f61
@ -1055,12 +1055,12 @@ const std::string& PresetCollection::get_suffix_modified() {
|
||||
|
||||
// Return a preset by its name. If the preset is active, a temporary copy is returned.
|
||||
// If a preset is not found by its name, null is returned.
|
||||
Preset* PresetCollection::find_preset(const std::string &name, bool first_visible_if_not_found)
|
||||
Preset* PresetCollection::find_preset(const std::string &name, bool first_visible_if_not_found, bool respect_active_preset /*= true*/)
|
||||
{
|
||||
Preset key(m_type, name, false);
|
||||
auto it = this->find_preset_internal(name);
|
||||
// Ensure that a temporary copy is returned if the preset found is currently selected.
|
||||
return (it != m_presets.end() && it->name == key.name) ? &this->preset(it - m_presets.begin()) :
|
||||
return (it != m_presets.end() && it->name == key.name) ? &this->preset(it - m_presets.begin(), respect_active_preset) :
|
||||
first_visible_if_not_found ? &this->first_visible() : nullptr;
|
||||
}
|
||||
|
||||
|
@ -392,8 +392,8 @@ public:
|
||||
const Preset& default_preset(size_t idx = 0) const { assert(idx < m_num_default_presets); return m_presets[idx]; }
|
||||
virtual const Preset& default_preset_for(const DynamicPrintConfig & /* config */) const { return this->default_preset(); }
|
||||
// Return a preset by an index. If the preset is active, a temporary copy is returned.
|
||||
Preset& preset(size_t idx) { return (idx == m_idx_selected) ? m_edited_preset : m_presets[idx]; }
|
||||
const Preset& preset(size_t idx) const { return const_cast<PresetCollection*>(this)->preset(idx); }
|
||||
Preset& preset(size_t idx, bool respect_active_preset = true) { return (idx == m_idx_selected && respect_active_preset) ? m_edited_preset : m_presets[idx]; }
|
||||
const Preset& preset(size_t idx, bool respect_active_preset = true) const { return const_cast<PresetCollection*>(this)->preset(idx); }
|
||||
void discard_current_changes() {
|
||||
m_presets[m_idx_selected].reset_dirty();
|
||||
m_edited_preset = m_presets[m_idx_selected];
|
||||
@ -403,9 +403,9 @@ public:
|
||||
|
||||
// Return a preset by its name. If the preset is active, a temporary copy is returned.
|
||||
// If a preset is not found by its name, null is returned.
|
||||
Preset* find_preset(const std::string &name, bool first_visible_if_not_found = false);
|
||||
const Preset* find_preset(const std::string &name, bool first_visible_if_not_found = false) const
|
||||
{ return const_cast<PresetCollection*>(this)->find_preset(name, first_visible_if_not_found); }
|
||||
Preset* find_preset(const std::string &name, bool first_visible_if_not_found = false, bool respect_active_preset = true);
|
||||
const Preset* find_preset(const std::string &name, bool first_visible_if_not_found = false, bool respect_active_preset = true) const
|
||||
{ return const_cast<PresetCollection*>(this)->find_preset(name, first_visible_if_not_found, respect_active_preset); }
|
||||
|
||||
size_t first_visible_idx() const;
|
||||
// Return index of the first compatible preset. Certainly at least the '- default -' preset shall be compatible.
|
||||
|
@ -231,7 +231,12 @@ static std::string suffix(Preset* preset)
|
||||
|
||||
wxString PresetComboBox::get_preset_name(const Preset & preset)
|
||||
{
|
||||
return from_u8(preset.name/* + suffix(preset)*/);
|
||||
return from_u8(preset.name);
|
||||
}
|
||||
|
||||
static wxString get_preset_name_with_suffix(const Preset & preset)
|
||||
{
|
||||
return from_u8(preset.name + Preset::suffix_modified());
|
||||
}
|
||||
|
||||
void PresetComboBox::update(std::string select_preset_name)
|
||||
@ -271,18 +276,32 @@ void PresetComboBox::update(std::string select_preset_name)
|
||||
auto bmp = get_bmp(bitmap_key, main_icon_name, "lock_closed", is_enabled, preset.is_compatible, preset.is_system || preset.is_default);
|
||||
assert(bmp);
|
||||
|
||||
if (!is_enabled)
|
||||
if (!is_enabled) {
|
||||
incomp_presets.emplace(get_preset_name(preset), bmp);
|
||||
if (preset.is_dirty && m_show_modif_preset_separately)
|
||||
incomp_presets.emplace(get_preset_name_with_suffix(preset), bmp);
|
||||
}
|
||||
else if (preset.is_default || preset.is_system)
|
||||
{
|
||||
Append(get_preset_name(preset), *bmp);
|
||||
validate_selection(preset.name == select_preset_name);
|
||||
if (preset.is_dirty && m_show_modif_preset_separately) {
|
||||
wxString preset_name = get_preset_name_with_suffix(preset);
|
||||
Append(preset_name, *bmp);
|
||||
validate_selection(into_u8(preset_name) == select_preset_name);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nonsys_presets.emplace(get_preset_name(preset), std::pair<wxBitmapBundle*, bool>(bmp, is_enabled));
|
||||
if (preset.name == select_preset_name || (select_preset_name.empty() && is_enabled))
|
||||
selected = get_preset_name(preset);
|
||||
if (preset.is_dirty && m_show_modif_preset_separately) {
|
||||
wxString preset_name = get_preset_name_with_suffix(preset);
|
||||
nonsys_presets.emplace(preset_name, std::pair<wxBitmapBundle*, bool>(bmp, is_enabled));
|
||||
if (preset_name == select_preset_name || (select_preset_name.empty() && is_enabled))
|
||||
selected = preset_name;
|
||||
}
|
||||
}
|
||||
if (i + 1 == m_collection->num_default_presets())
|
||||
set_label_marker(Append(separator(L("System presets")), NullBitmapBndl()));
|
||||
|
@ -31,6 +31,7 @@ class BitmapCache;
|
||||
class PresetComboBox : public BitmapComboBox
|
||||
{
|
||||
bool m_show_all { false };
|
||||
bool m_show_modif_preset_separately{ false };
|
||||
public:
|
||||
PresetComboBox(wxWindow* parent, Preset::Type preset_type, const wxSize& size = wxDefaultSize, PresetBundle* preset_bundle = nullptr);
|
||||
~PresetComboBox();
|
||||
@ -65,6 +66,7 @@ public:
|
||||
void edit_physical_printer();
|
||||
void add_physical_printer();
|
||||
bool del_physical_printer(const wxString& note_string = wxEmptyString);
|
||||
void show_modif_preset_separately() { m_show_modif_preset_separately = true; }
|
||||
|
||||
virtual wxString get_preset_name(const Preset& preset);
|
||||
Preset::Type get_type() { return m_type; }
|
||||
|
@ -79,12 +79,13 @@ static void make_string_bold(wxString& str)
|
||||
}
|
||||
|
||||
// preset(root) node
|
||||
ModelNode::ModelNode(Preset::Type preset_type, wxWindow* parent_win, const wxString& text, const std::string& icon_name) :
|
||||
ModelNode::ModelNode(Preset::Type preset_type, wxWindow* parent_win, const wxString& text, const std::string& icon_name, const wxString& new_val_column_text) :
|
||||
m_parent_win(parent_win),
|
||||
m_parent(nullptr),
|
||||
m_preset_type(preset_type),
|
||||
m_icon_name(icon_name),
|
||||
m_text(text)
|
||||
m_text(text),
|
||||
m_new_value(new_val_column_text)
|
||||
{
|
||||
UpdateIcons();
|
||||
}
|
||||
@ -128,20 +129,22 @@ wxBitmap ModelNode::get_bitmap(const wxString& color)
|
||||
}
|
||||
|
||||
// option node
|
||||
ModelNode::ModelNode(ModelNode* parent, const wxString& text, const wxString& old_value, const wxString& new_value) :
|
||||
ModelNode::ModelNode(ModelNode* parent, const wxString& text, const wxString& old_value, const wxString& mod_value, const wxString& new_value) :
|
||||
m_parent_win(parent->m_parent_win),
|
||||
m_parent(parent),
|
||||
m_old_color(old_value.StartsWith("#") ? old_value : ""),
|
||||
m_mod_color(mod_value.StartsWith("#") ? mod_value : ""),
|
||||
m_new_color(new_value.StartsWith("#") ? new_value : ""),
|
||||
m_container(false),
|
||||
m_text(text),
|
||||
m_icon_name("empty"),
|
||||
m_old_value(old_value),
|
||||
m_mod_value(mod_value),
|
||||
m_new_value(new_value)
|
||||
{
|
||||
// check if old/new_value is color
|
||||
if (m_old_color.IsEmpty()) {
|
||||
if (!m_new_color.IsEmpty())
|
||||
if (!m_mod_color.IsEmpty())
|
||||
m_old_value = _L("Undef");
|
||||
}
|
||||
else {
|
||||
@ -149,8 +152,17 @@ ModelNode::ModelNode(ModelNode* parent, const wxString& text, const wxString& ol
|
||||
m_old_value.Clear();
|
||||
}
|
||||
|
||||
if (m_new_color.IsEmpty()) {
|
||||
if (m_mod_color.IsEmpty()) {
|
||||
if (!m_old_color.IsEmpty())
|
||||
m_mod_value = _L("Undef");
|
||||
}
|
||||
else {
|
||||
m_mod_color_bmp = get_bitmap(m_mod_color);
|
||||
m_mod_value.Clear();
|
||||
}
|
||||
|
||||
if (m_new_color.IsEmpty()) {
|
||||
if (!m_old_color.IsEmpty() || !m_mod_color.IsEmpty())
|
||||
m_new_value = _L("Undef");
|
||||
}
|
||||
else {
|
||||
@ -160,7 +172,8 @@ ModelNode::ModelNode(ModelNode* parent, const wxString& text, const wxString& ol
|
||||
|
||||
// "color" strings
|
||||
color_string(m_old_value, def_text_color());
|
||||
color_string(m_new_value, orange);
|
||||
color_string(m_mod_value, orange);
|
||||
color_string(m_new_value, def_text_color());
|
||||
|
||||
UpdateIcons();
|
||||
}
|
||||
@ -179,12 +192,14 @@ void ModelNode::UpdateEnabling()
|
||||
if (!m_toggle) {
|
||||
change_text_color(m_text, def_text_color(), grey);
|
||||
change_text_color(m_old_value, def_text_color(), grey);
|
||||
change_text_color(m_new_value, orange,grey);
|
||||
change_text_color(m_mod_value, orange,grey);
|
||||
change_text_color(m_new_value, def_text_color(), grey);
|
||||
}
|
||||
else {
|
||||
change_text_color(m_text, grey, def_text_color());
|
||||
change_text_color(m_old_value, grey, def_text_color());
|
||||
change_text_color(m_new_value, grey, orange);
|
||||
change_text_color(m_mod_value, grey, orange);
|
||||
change_text_color(m_new_value, grey, def_text_color());
|
||||
}
|
||||
// update icons for the colors
|
||||
UpdateIcons();
|
||||
@ -195,6 +210,8 @@ void ModelNode::UpdateIcons()
|
||||
// update icons for the colors, if any exists
|
||||
if (!m_old_color.IsEmpty())
|
||||
m_old_color_bmp = get_bitmap(m_old_color);
|
||||
if (!m_mod_color.IsEmpty())
|
||||
m_mod_color_bmp = get_bitmap(m_mod_color);
|
||||
if (!m_new_color.IsEmpty())
|
||||
m_new_color_bmp = get_bitmap(m_new_color);
|
||||
|
||||
@ -223,13 +240,14 @@ DiffModel::DiffModel(wxWindow* parent) :
|
||||
{
|
||||
}
|
||||
|
||||
wxDataViewItem DiffModel::AddPreset(Preset::Type type, wxString preset_name, PrinterTechnology pt)
|
||||
wxDataViewItem DiffModel::AddPreset(Preset::Type type, wxString preset_name, PrinterTechnology pt, wxString new_preset_name/* = wxString()*/)
|
||||
{
|
||||
// "color" strings
|
||||
color_string(preset_name, def_text_color());
|
||||
make_string_bold(preset_name);
|
||||
make_string_bold(new_preset_name);
|
||||
|
||||
auto preset = new ModelNode(type, m_parent_win, preset_name, get_icon_name(type, pt));
|
||||
auto preset = new ModelNode(type, m_parent_win, preset_name, get_icon_name(type, pt), new_preset_name);
|
||||
m_preset_nodes.emplace_back(preset);
|
||||
|
||||
wxDataViewItem child((void*)preset);
|
||||
@ -239,9 +257,9 @@ wxDataViewItem DiffModel::AddPreset(Preset::Type type, wxString preset_name, Pri
|
||||
return child;
|
||||
}
|
||||
|
||||
ModelNode* DiffModel::AddOption(ModelNode* group_node, wxString option_name, wxString old_value, wxString new_value)
|
||||
ModelNode* DiffModel::AddOption(ModelNode* group_node, wxString option_name, wxString old_value, wxString mod_value, wxString new_value)
|
||||
{
|
||||
group_node->Append(std::make_unique<ModelNode>(group_node, option_name, old_value, new_value));
|
||||
group_node->Append(std::make_unique<ModelNode>(group_node, option_name, old_value, mod_value, new_value));
|
||||
ModelNode* option = group_node->GetChildren().back().get();
|
||||
wxDataViewItem group_item = wxDataViewItem((void*)group_node);
|
||||
ItemAdded(group_item, wxDataViewItem((void*)option));
|
||||
@ -250,27 +268,27 @@ ModelNode* DiffModel::AddOption(ModelNode* group_node, wxString option_name, wxS
|
||||
return option;
|
||||
}
|
||||
|
||||
ModelNode* DiffModel::AddOptionWithGroup(ModelNode* category_node, wxString group_name, wxString option_name, wxString old_value, wxString new_value)
|
||||
ModelNode* DiffModel::AddOptionWithGroup(ModelNode* category_node, wxString group_name, wxString option_name, wxString old_value, wxString mod_value, wxString new_value)
|
||||
{
|
||||
category_node->Append(std::make_unique<ModelNode>(category_node, group_name));
|
||||
ModelNode* group_node = category_node->GetChildren().back().get();
|
||||
ItemAdded(wxDataViewItem((void*)category_node), wxDataViewItem((void*)group_node));
|
||||
|
||||
return AddOption(group_node, option_name, old_value, new_value);
|
||||
return AddOption(group_node, option_name, old_value, mod_value, new_value);
|
||||
}
|
||||
|
||||
ModelNode* DiffModel::AddOptionWithGroupAndCategory(ModelNode* preset_node, wxString category_name, wxString group_name,
|
||||
wxString option_name, wxString old_value, wxString new_value, const std::string category_icon_name)
|
||||
wxString option_name, wxString old_value, wxString mod_value, wxString new_value, const std::string category_icon_name)
|
||||
{
|
||||
preset_node->Append(std::make_unique<ModelNode>(preset_node, category_name, category_icon_name));
|
||||
ModelNode* category_node = preset_node->GetChildren().back().get();
|
||||
ItemAdded(wxDataViewItem((void*)preset_node), wxDataViewItem((void*)category_node));
|
||||
|
||||
return AddOptionWithGroup(category_node, group_name, option_name, old_value, new_value);
|
||||
return AddOptionWithGroup(category_node, group_name, option_name, old_value, mod_value, new_value);
|
||||
}
|
||||
|
||||
wxDataViewItem DiffModel::AddOption(Preset::Type type, wxString category_name, wxString group_name, wxString option_name,
|
||||
wxString old_value, wxString new_value, const std::string category_icon_name)
|
||||
wxString old_value, wxString mod_value, wxString new_value, const std::string category_icon_name)
|
||||
{
|
||||
// "color" strings
|
||||
color_string(category_name, def_text_color());
|
||||
@ -290,12 +308,12 @@ wxDataViewItem DiffModel::AddOption(Preset::Type type, wxString category_name, w
|
||||
{
|
||||
for (std::unique_ptr<ModelNode> &group : category->GetChildren())
|
||||
if (group->text() == group_name)
|
||||
return wxDataViewItem((void*)AddOption(group.get(), option_name, old_value, new_value));
|
||||
return wxDataViewItem((void*)AddOption(group.get(), option_name, old_value, mod_value, new_value));
|
||||
|
||||
return wxDataViewItem((void*)AddOptionWithGroup(category.get(), group_name, option_name, old_value, new_value));
|
||||
return wxDataViewItem((void*)AddOptionWithGroup(category.get(), group_name, option_name, old_value, mod_value, new_value));
|
||||
}
|
||||
|
||||
return wxDataViewItem((void*)AddOptionWithGroupAndCategory(preset.get(), category_name, group_name, option_name, old_value, new_value, category_icon_name));
|
||||
return wxDataViewItem((void*)AddOptionWithGroupAndCategory(preset.get(), category_name, group_name, option_name, old_value, mod_value, new_value, category_icon_name));
|
||||
}
|
||||
|
||||
return wxDataViewItem(nullptr);
|
||||
@ -364,6 +382,9 @@ void DiffModel::GetValue(wxVariant& variant, const wxDataViewItem& item, unsigne
|
||||
case colOldValue:
|
||||
variant << wxDataViewIconText(node->m_old_value, node->m_old_color_bmp);
|
||||
break;
|
||||
case colModValue:
|
||||
variant << wxDataViewIconText(node->m_mod_value, node->m_mod_color_bmp);
|
||||
break;
|
||||
case colNewValue:
|
||||
variant << wxDataViewIconText(node->m_new_value, node->m_new_color_bmp);
|
||||
break;
|
||||
@ -374,6 +395,9 @@ void DiffModel::GetValue(wxVariant& variant, const wxDataViewItem& item, unsigne
|
||||
case colOldValue:
|
||||
variant << DataViewBitmapText(node->m_old_value, node->m_old_color_bmp);
|
||||
break;
|
||||
case colModValue:
|
||||
variant << DataViewBitmapText(node->m_mod_value, node->m_mod_color_bmp);
|
||||
break;
|
||||
case colNewValue:
|
||||
variant << DataViewBitmapText(node->m_new_value, node->m_new_color_bmp);
|
||||
break;
|
||||
@ -635,16 +659,17 @@ void DiffViewCtrl::Rescale(int em /*= 0*/)
|
||||
|
||||
void DiffViewCtrl::Append( const std::string& opt_key, Preset::Type type,
|
||||
wxString category_name, wxString group_name, wxString option_name,
|
||||
wxString old_value, wxString new_value, const std::string category_icon_name)
|
||||
wxString old_value, wxString mod_value, wxString new_value, const std::string category_icon_name)
|
||||
{
|
||||
ItemData item_data = { opt_key, option_name, old_value, new_value, type };
|
||||
ItemData item_data = { opt_key, option_name, old_value, mod_value, new_value, type };
|
||||
|
||||
wxString old_val = get_short_string(item_data.old_val);
|
||||
wxString mod_val = get_short_string(item_data.mod_val);
|
||||
wxString new_val = get_short_string(item_data.new_val);
|
||||
if (old_val != item_data.old_val || new_val != item_data.new_val)
|
||||
if (old_val != item_data.old_val || mod_val != item_data.mod_val || new_val != item_data.new_val)
|
||||
item_data.is_long = true;
|
||||
|
||||
m_items_map.emplace(model->AddOption(type, category_name, group_name, option_name, old_val, new_val, category_icon_name), item_data);
|
||||
m_items_map.emplace(model->AddOption(type, category_name, group_name, option_name, old_val, mod_val, new_val, category_icon_name), item_data);
|
||||
|
||||
}
|
||||
|
||||
@ -694,11 +719,11 @@ void DiffViewCtrl::context_menu(wxDataViewEvent& event)
|
||||
if (it == m_items_map.end() || !it->second.is_long)
|
||||
return;
|
||||
|
||||
size_t column_cnt = this->GetColumnCount();
|
||||
const wxString old_value_header = this->GetColumn(column_cnt - 2)->GetTitle();
|
||||
const wxString new_value_header = this->GetColumn(column_cnt - 1)->GetTitle();
|
||||
FullCompareDialog(it->second.opt_name, it->second.old_val, it->second.new_val,
|
||||
old_value_header, new_value_header).ShowModal();
|
||||
const wxString old_value_header = this->GetColumn(DiffModel::colOldValue)->GetTitle();
|
||||
const wxString mod_value_header = this->GetColumn(DiffModel::colModValue)->GetTitle();
|
||||
const wxString new_value_header = has_new_value_column() ? this->GetColumn(DiffModel::colNewValue)->GetTitle() : "";
|
||||
FullCompareDialog(it->second.opt_name, it->second.old_val, it->second.mod_val, it->second.new_val,
|
||||
old_value_header, mod_value_header, new_value_header).ShowModal();
|
||||
|
||||
#ifdef __WXOSX__
|
||||
wxWindow* parent = this->GetParent();
|
||||
@ -819,14 +844,22 @@ void UnsavedChangesDialog::build(Preset::Type type, PresetCollection* dependent_
|
||||
int border = 10;
|
||||
int em = em_unit();
|
||||
|
||||
bool add_new_value_column = !new_selected_preset.empty() && dependent_presets && dependent_presets->get_edited_preset().type == type &&
|
||||
new_selected_preset != dependent_presets->get_edited_preset().name;
|
||||
if (add_new_value_column && dependent_presets->get_edited_preset().type == Preset::TYPE_PRINTER &&
|
||||
dependent_presets->get_edited_preset().printer_technology() != dependent_presets->find_preset(new_selected_preset)->printer_technology())
|
||||
add_new_value_column = false;
|
||||
|
||||
m_action_line = new wxStaticText(this, wxID_ANY, "");
|
||||
m_action_line->SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT).Bold());
|
||||
|
||||
m_tree = new DiffViewCtrl(this, wxSize(em * 60, em * 30));
|
||||
m_tree = new DiffViewCtrl(this, wxSize(em * (add_new_value_column ? 80 : 60), em * 30));
|
||||
m_tree->AppendToggleColumn_(L"\u2714" , DiffModel::colToggle, wxLinux ? 9 : 6);
|
||||
m_tree->AppendBmpTextColumn("" , DiffModel::colIconText, 28);
|
||||
m_tree->AppendBmpTextColumn(_L("Old Value"), DiffModel::colOldValue, 12);
|
||||
m_tree->AppendBmpTextColumn(_L("New Value"), DiffModel::colNewValue, 12);
|
||||
m_tree->AppendBmpTextColumn(_L("Original Value"), DiffModel::colOldValue, 12);
|
||||
m_tree->AppendBmpTextColumn(_L("Modified Value"), DiffModel::colModValue, 12);
|
||||
if (add_new_value_column)
|
||||
m_tree->AppendBmpTextColumn(_L("New Value"), DiffModel::colNewValue, 12);
|
||||
|
||||
// Add Buttons
|
||||
wxFont btn_font = this->GetFont().Scaled(1.4f);
|
||||
@ -1222,7 +1255,7 @@ void UnsavedChangesDialog::update(Preset::Type type, PresetCollection* dependent
|
||||
}
|
||||
else {
|
||||
wxString action_msg;
|
||||
if (type == dependent_presets->type()) {
|
||||
if (dependent_presets && type == dependent_presets->type()) {
|
||||
action_msg = format_wxstr(_L("Preset \"%1%\" has the following unsaved changes:"), presets->get_edited_preset().name);
|
||||
}
|
||||
else {
|
||||
@ -1234,10 +1267,10 @@ void UnsavedChangesDialog::update(Preset::Type type, PresetCollection* dependent
|
||||
m_action_line->SetLabel(action_msg);
|
||||
}
|
||||
|
||||
update_tree(type, presets);
|
||||
update_tree(type, presets, new_selected_preset);
|
||||
}
|
||||
|
||||
void UnsavedChangesDialog::update_tree(Preset::Type type, PresetCollection* presets_)
|
||||
void UnsavedChangesDialog::update_tree(Preset::Type type, PresetCollection* presets_, const std::string& new_selected_preset)
|
||||
{
|
||||
// update searcher befofre update of tree
|
||||
wxGetApp().sidebar().check_and_update_searcher();
|
||||
@ -1262,12 +1295,13 @@ void UnsavedChangesDialog::update_tree(Preset::Type type, PresetCollection* pres
|
||||
{
|
||||
const DynamicPrintConfig& old_config = presets->get_selected_preset().config;
|
||||
const PrinterTechnology& old_pt = presets->get_selected_preset().printer_technology();
|
||||
const DynamicPrintConfig& new_config = presets->get_edited_preset().config;
|
||||
const DynamicPrintConfig& mod_config = presets->get_edited_preset().config;
|
||||
const DynamicPrintConfig& new_config = m_tree->has_new_value_column() ? presets->find_preset(new_selected_preset, false, false)->config : mod_config;
|
||||
type = presets->type();
|
||||
|
||||
const std::map<wxString, std::string>& category_icon_map = wxGetApp().get_tab(type)->get_category_icon_map();
|
||||
|
||||
m_tree->model->AddPreset(type, from_u8(presets->get_edited_preset().name), old_pt);
|
||||
m_tree->model->AddPreset(type, from_u8(presets->get_edited_preset().name), old_pt, from_u8(new_selected_preset));
|
||||
|
||||
// Collect dirty options.
|
||||
const bool deep_compare = (type == Preset::TYPE_PRINTER || type == Preset::TYPE_SLA_MATERIAL);
|
||||
@ -1275,12 +1309,13 @@ void UnsavedChangesDialog::update_tree(Preset::Type type, PresetCollection* pres
|
||||
|
||||
// process changes of extruders count
|
||||
if (type == Preset::TYPE_PRINTER && old_pt == ptFFF &&
|
||||
old_config.opt<ConfigOptionStrings>("extruder_colour")->values.size() != new_config.opt<ConfigOptionStrings>("extruder_colour")->values.size()) {
|
||||
old_config.opt<ConfigOptionStrings>("extruder_colour")->values.size() != mod_config.opt<ConfigOptionStrings>("extruder_colour")->values.size()) {
|
||||
wxString local_label = _L("Extruders count");
|
||||
wxString old_val = from_u8((boost::format("%1%") % old_config.opt<ConfigOptionStrings>("extruder_colour")->values.size()).str());
|
||||
wxString new_val = from_u8((boost::format("%1%") % new_config.opt<ConfigOptionStrings>("extruder_colour")->values.size()).str());
|
||||
wxString mod_val = from_u8((boost::format("%1%") % mod_config.opt<ConfigOptionStrings>("extruder_colour")->values.size()).str());
|
||||
wxString new_val = !m_tree->has_new_value_column() ? "" : from_u8((boost::format("%1%") % new_config.opt<ConfigOptionStrings>("extruder_colour")->values.size()).str());
|
||||
|
||||
m_tree->Append("extruders_count", type, _L("General"), _L("Capabilities"), local_label, old_val, new_val, category_icon_map.at("General"));
|
||||
m_tree->Append("extruders_count", type, _L("General"), _L("Capabilities"), local_label, old_val, mod_val, new_val, category_icon_map.at("General"));
|
||||
}
|
||||
|
||||
for (const std::string& opt_key : dirty_options) {
|
||||
@ -1293,7 +1328,8 @@ void UnsavedChangesDialog::update_tree(Preset::Type type, PresetCollection* pres
|
||||
}
|
||||
|
||||
m_tree->Append(opt_key, type, option.category_local, option.group_local, option.label_local,
|
||||
get_string_value(opt_key, old_config), get_string_value(opt_key, new_config), category_icon_map.at(option.category));
|
||||
get_string_value(opt_key, old_config), get_string_value(opt_key, mod_config),
|
||||
m_tree->has_new_value_column() ? get_string_value(opt_key, new_config) : "", category_icon_map.at(option.category));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1331,20 +1367,21 @@ void UnsavedChangesDialog::on_sys_color_changed()
|
||||
// FullCompareDialog
|
||||
//------------------------------------------
|
||||
|
||||
FullCompareDialog::FullCompareDialog(const wxString& option_name, const wxString& old_value, const wxString& new_value,
|
||||
const wxString& old_value_header, const wxString& new_value_header)
|
||||
FullCompareDialog::FullCompareDialog(const wxString& option_name, const wxString& old_value, const wxString& mod_value, const wxString& new_value,
|
||||
const wxString& old_value_header, const wxString& mod_value_header, const wxString& new_value_header)
|
||||
: wxDialog(nullptr, wxID_ANY, option_name, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
|
||||
{
|
||||
wxGetApp().UpdateDarkUI(this);
|
||||
|
||||
int border = 10;
|
||||
bool has_new_value_column = !new_value_header.IsEmpty();
|
||||
|
||||
wxStaticBoxSizer* sizer = new wxStaticBoxSizer(wxVERTICAL, this);
|
||||
|
||||
wxFlexGridSizer* grid_sizer = new wxFlexGridSizer(2, 2, 1, 0);
|
||||
wxFlexGridSizer* grid_sizer = new wxFlexGridSizer(2, has_new_value_column ? 3 : 2, 1, 0);
|
||||
grid_sizer->SetFlexibleDirection(wxBOTH);
|
||||
grid_sizer->AddGrowableCol(0,1);
|
||||
grid_sizer->AddGrowableCol(1,1);
|
||||
for (size_t col = 0 ; col < grid_sizer->GetCols(); col++)
|
||||
grid_sizer->AddGrowableCol(col, 1);
|
||||
grid_sizer->AddGrowableRow(1,1);
|
||||
|
||||
auto add_header = [grid_sizer, border, this](wxString label) {
|
||||
@ -1354,7 +1391,9 @@ FullCompareDialog::FullCompareDialog(const wxString& option_name, const wxString
|
||||
};
|
||||
|
||||
add_header(old_value_header);
|
||||
add_header(new_value_header);
|
||||
add_header(mod_value_header);
|
||||
if (has_new_value_column)
|
||||
add_header(new_value_header);
|
||||
|
||||
auto get_set_from_val = [](wxString str) {
|
||||
if (str.Find("\n") == wxNOT_FOUND)
|
||||
@ -1370,11 +1409,14 @@ FullCompareDialog::FullCompareDialog(const wxString& option_name, const wxString
|
||||
};
|
||||
|
||||
std::set<wxString> old_set = get_set_from_val(old_value);
|
||||
std::set<wxString> mod_set = get_set_from_val(mod_value);
|
||||
std::set<wxString> new_set = get_set_from_val(new_value);
|
||||
std::set<wxString> old_new_diff_set;
|
||||
std::set<wxString> old_mod_diff_set;
|
||||
std::set<wxString> mod_old_diff_set;
|
||||
std::set<wxString> new_old_diff_set;
|
||||
|
||||
std::set_difference(old_set.begin(), old_set.end(), new_set.begin(), new_set.end(), std::inserter(old_new_diff_set, old_new_diff_set.begin()));
|
||||
std::set_difference(old_set.begin(), old_set.end(), mod_set.begin(), mod_set.end(), std::inserter(old_mod_diff_set, old_mod_diff_set.begin()));
|
||||
std::set_difference(mod_set.begin(), mod_set.end(), old_set.begin(), old_set.end(), std::inserter(mod_old_diff_set, mod_old_diff_set.begin()));
|
||||
std::set_difference(new_set.begin(), new_set.end(), old_set.begin(), old_set.end(), std::inserter(new_old_diff_set, new_old_diff_set.begin()));
|
||||
|
||||
auto add_value = [grid_sizer, border, this](wxString label, const std::set<wxString>& diff_set, bool is_colored = false) {
|
||||
@ -1391,8 +1433,10 @@ FullCompareDialog::FullCompareDialog(const wxString& option_name, const wxString
|
||||
|
||||
grid_sizer->Add(text, 1, wxALL | wxEXPAND, border);
|
||||
};
|
||||
add_value(old_value, old_new_diff_set);
|
||||
add_value(new_value, new_old_diff_set, true);
|
||||
add_value(old_value, old_mod_diff_set);
|
||||
add_value(mod_value, mod_old_diff_set, true);
|
||||
if (has_new_value_column)
|
||||
add_value(new_value, new_old_diff_set);
|
||||
|
||||
sizer->Add(grid_sizer, 1, wxEXPAND);
|
||||
|
||||
@ -1466,10 +1510,11 @@ DiffPresetDialog::DiffPresetDialog(MainFrame* mainframe)
|
||||
auto add_preset_combobox = [collection, sizer, new_type, em, this](PresetComboBox** cb_, PresetBundle* preset_bundle) {
|
||||
*cb_ = new PresetComboBox(this, new_type, wxSize(em * 35, -1), preset_bundle);
|
||||
PresetComboBox* cb = (*cb_);
|
||||
cb->show_modif_preset_separately();
|
||||
cb->set_selection_changed_function([this, new_type, preset_bundle, cb](int selection) {
|
||||
if (m_view_type == Preset::TYPE_INVALID) {
|
||||
std::string preset_name = cb->GetString(selection).ToUTF8().data();
|
||||
update_compatibility(Preset::remove_suffix_modified(preset_name), new_type, preset_bundle);
|
||||
update_compatibility(preset_name, new_type, preset_bundle);
|
||||
}
|
||||
update_tree();
|
||||
});
|
||||
@ -1491,7 +1536,7 @@ DiffPresetDialog::DiffPresetDialog(MainFrame* mainframe)
|
||||
std::string preset_name = get_selection(presets_left);
|
||||
presets_right->update(preset_name);
|
||||
if (m_view_type == Preset::TYPE_INVALID)
|
||||
update_compatibility(Preset::remove_suffix_modified(preset_name), presets_right->get_type(), m_preset_bundle_right.get());
|
||||
update_compatibility(preset_name, presets_right->get_type(), m_preset_bundle_right.get());
|
||||
update_tree();
|
||||
});
|
||||
}
|
||||
@ -1512,7 +1557,7 @@ DiffPresetDialog::DiffPresetDialog(MainFrame* mainframe)
|
||||
m_tree = new DiffViewCtrl(this, wxSize(em * 65, em * 40));
|
||||
m_tree->AppendBmpTextColumn("", DiffModel::colIconText, 35);
|
||||
m_tree->AppendBmpTextColumn(_L("Left Preset Value"), DiffModel::colOldValue, 15);
|
||||
m_tree->AppendBmpTextColumn(_L("Right Preset Value"),DiffModel::colNewValue, 15);
|
||||
m_tree->AppendBmpTextColumn(_L("Right Preset Value"),DiffModel::colModValue, 15);
|
||||
m_tree->Hide();
|
||||
|
||||
wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL);
|
||||
@ -1618,8 +1663,14 @@ void DiffPresetDialog::update_tree()
|
||||
Preset::Type type = preset_combos.presets_left->get_type();
|
||||
|
||||
const PresetCollection* presets = get_preset_collection(type);
|
||||
const Preset* left_preset = presets->find_preset(get_selection(preset_combos.presets_left));
|
||||
const Preset* right_preset = presets->find_preset(get_selection(preset_combos.presets_right));
|
||||
|
||||
std::string preset_name_full = get_selection(preset_combos.presets_left);
|
||||
std::string preset_name = Preset::remove_suffix_modified(preset_name_full);
|
||||
const Preset* left_preset = presets->find_preset(preset_name, false, preset_name_full.length() != preset_name.length());
|
||||
preset_name_full = get_selection(preset_combos.presets_right);
|
||||
preset_name = Preset::remove_suffix_modified(preset_name_full);
|
||||
const Preset* right_preset = presets->find_preset(preset_name, false, preset_name_full.length() != preset_name.length());
|
||||
|
||||
if (!left_preset || !right_preset) {
|
||||
bottom_info = _L("One of the presets doesn't found");
|
||||
preset_combos.equal_bmp->SetBitmap_(ScalableBitmap(this, "question"));
|
||||
@ -1668,7 +1719,7 @@ void DiffPresetDialog::update_tree()
|
||||
wxString left_val = from_u8((boost::format("%1%") % left_config.opt<ConfigOptionStrings>("extruder_colour")->values.size()).str());
|
||||
wxString right_val = from_u8((boost::format("%1%") % right_congig.opt<ConfigOptionStrings>("extruder_colour")->values.size()).str());
|
||||
|
||||
m_tree->Append("extruders_count", type, _L("General"), _L("Capabilities"), local_label, left_val, right_val, category_icon_map.at("General"));
|
||||
m_tree->Append("extruders_count", type, _L("General"), _L("Capabilities"), local_label, left_val, right_val, "", category_icon_map.at("General"));
|
||||
}
|
||||
|
||||
for (const std::string& opt_key : dirty_options) {
|
||||
@ -1678,14 +1729,14 @@ void DiffPresetDialog::update_tree()
|
||||
Search::Option option = searcher.get_option(opt_key, get_full_label(opt_key, left_config), type);
|
||||
if (option.opt_key() != opt_key) {
|
||||
// temporary solution, just for testing
|
||||
m_tree->Append(opt_key, type, _L("Undef category"), _L("Undef group"), opt_key, left_val, right_val, "question");
|
||||
m_tree->Append(opt_key, type, _L("Undef category"), _L("Undef group"), opt_key, left_val, right_val, "", "question");
|
||||
// When founded option isn't the correct one.
|
||||
// It can be for dirty_options: "default_print_profile", "printer_model", "printer_settings_id",
|
||||
// because of they don't exist in searcher
|
||||
continue;
|
||||
}
|
||||
m_tree->Append(opt_key, type, option.category_local, option.group_local, option.label_local,
|
||||
left_val, right_val, category_icon_map.at(option.category));
|
||||
left_val, right_val, "", category_icon_map.at(option.category));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,6 +42,7 @@ class ModelNode
|
||||
std::string m_icon_name;
|
||||
// saved values for colors if they exist
|
||||
wxString m_old_color;
|
||||
wxString m_mod_color;
|
||||
wxString m_new_color;
|
||||
|
||||
#ifdef __linux__
|
||||
@ -56,14 +57,17 @@ public:
|
||||
#ifdef __linux__
|
||||
wxIcon m_icon;
|
||||
wxIcon m_old_color_bmp;
|
||||
wxIcon m_mod_color_bmp;
|
||||
wxIcon m_new_color_bmp;
|
||||
#else
|
||||
wxBitmap m_icon;
|
||||
wxBitmap m_old_color_bmp;
|
||||
wxBitmap m_mod_color_bmp;
|
||||
wxBitmap m_new_color_bmp;
|
||||
#endif //__linux__
|
||||
wxString m_text;
|
||||
wxString m_old_value;
|
||||
wxString m_mod_value;
|
||||
wxString m_new_value;
|
||||
|
||||
// TODO/FIXME:
|
||||
@ -78,7 +82,7 @@ public:
|
||||
bool m_container {true};
|
||||
|
||||
// preset(root) node
|
||||
ModelNode(Preset::Type preset_type, wxWindow* parent_win, const wxString& text, const std::string& icon_name);
|
||||
ModelNode(Preset::Type preset_type, wxWindow* parent_win, const wxString& text, const std::string& icon_name, const wxString& new_val_column_text);
|
||||
|
||||
// category node
|
||||
ModelNode(ModelNode* parent, const wxString& text, const std::string& icon_name);
|
||||
@ -87,7 +91,7 @@ public:
|
||||
ModelNode(ModelNode* parent, const wxString& text);
|
||||
|
||||
// option node
|
||||
ModelNode(ModelNode* parent, const wxString& text, const wxString& old_value, const wxString& new_value);
|
||||
ModelNode(ModelNode* parent, const wxString& text, const wxString& old_value, const wxString& mod_value, const wxString& new_value);
|
||||
|
||||
bool IsContainer() const { return m_container; }
|
||||
bool IsToggled() const { return m_toggle; }
|
||||
@ -122,17 +126,20 @@ class DiffModel : public wxDataViewModel
|
||||
ModelNode *AddOption(ModelNode *group_node,
|
||||
wxString option_name,
|
||||
wxString old_value,
|
||||
wxString mod_value,
|
||||
wxString new_value);
|
||||
ModelNode *AddOptionWithGroup(ModelNode *category_node,
|
||||
wxString group_name,
|
||||
wxString option_name,
|
||||
wxString old_value,
|
||||
wxString mod_value,
|
||||
wxString new_value);
|
||||
ModelNode *AddOptionWithGroupAndCategory(ModelNode *preset_node,
|
||||
wxString category_name,
|
||||
wxString group_name,
|
||||
wxString option_name,
|
||||
wxString old_value,
|
||||
wxString mod_value,
|
||||
wxString new_value,
|
||||
const std::string category_icon_name);
|
||||
|
||||
@ -141,6 +148,7 @@ public:
|
||||
colToggle,
|
||||
colIconText,
|
||||
colOldValue,
|
||||
colModValue,
|
||||
colNewValue,
|
||||
colMax
|
||||
};
|
||||
@ -150,9 +158,9 @@ public:
|
||||
|
||||
void SetAssociatedControl(wxDataViewCtrl* ctrl) { m_ctrl = ctrl; }
|
||||
|
||||
wxDataViewItem AddPreset(Preset::Type type, wxString preset_name, PrinterTechnology pt);
|
||||
wxDataViewItem AddPreset(Preset::Type type, wxString preset_name, PrinterTechnology pt, wxString new_preset_name = wxString());
|
||||
wxDataViewItem AddOption(Preset::Type type, wxString category_name, wxString group_name, wxString option_name,
|
||||
wxString old_value, wxString new_value, const std::string category_icon_name);
|
||||
wxString old_value, wxString mod_value, wxString new_value, const std::string category_icon_name);
|
||||
|
||||
void UpdateItemEnabling(wxDataViewItem item);
|
||||
bool IsEnabledItem(const wxDataViewItem& item);
|
||||
@ -193,6 +201,7 @@ class DiffViewCtrl : public wxDataViewCtrl
|
||||
std::string opt_key;
|
||||
wxString opt_name;
|
||||
wxString old_val;
|
||||
wxString mod_val;
|
||||
wxString new_val;
|
||||
Preset::Type type;
|
||||
bool is_long{ false };
|
||||
@ -217,7 +226,7 @@ public:
|
||||
void AppendToggleColumn_(const wxString& label, unsigned model_column, int width);
|
||||
void Rescale(int em = 0);
|
||||
void Append(const std::string& opt_key, Preset::Type type, wxString category_name, wxString group_name, wxString option_name,
|
||||
wxString old_value, wxString new_value, const std::string category_icon_name);
|
||||
wxString old_value, wxString mod_value, wxString new_value, const std::string category_icon_name);
|
||||
void Clear();
|
||||
|
||||
wxString get_short_string(wxString full_string);
|
||||
@ -227,6 +236,7 @@ public:
|
||||
void set_em_unit(int em) { m_em_unit = em; }
|
||||
bool has_unselected_options();
|
||||
bool has_long_strings() { return m_has_long_strings; }
|
||||
bool has_new_value_column() { return this->GetColumnCount() == DiffModel::colMax; }
|
||||
|
||||
std::vector<std::string> options(Preset::Type type, bool selected);
|
||||
std::vector<std::string> selected_options();
|
||||
@ -280,14 +290,14 @@ public:
|
||||
};
|
||||
|
||||
// show unsaved changes when preset is switching
|
||||
UnsavedChangesDialog(Preset::Type type, PresetCollection* dependent_presets, const std::string& new_selected_preset);
|
||||
UnsavedChangesDialog(Preset::Type type, PresetCollection* dependent_presets, const std::string& new_selected_preset = std::string());
|
||||
// show unsaved changes for all another cases
|
||||
UnsavedChangesDialog(const wxString& caption, const wxString& header, const std::string& app_config_key, int act_buttons);
|
||||
~UnsavedChangesDialog() {}
|
||||
|
||||
void build(Preset::Type type, PresetCollection* dependent_presets, const std::string& new_selected_preset, const wxString& header = "");
|
||||
void update(Preset::Type type, PresetCollection* dependent_presets, const std::string& new_selected_preset, const wxString& header);
|
||||
void update_tree(Preset::Type type, PresetCollection *presets);
|
||||
void update_tree(Preset::Type type, PresetCollection *presets, const std::string& new_selected_preset);
|
||||
void show_info_line(Action action, std::string preset_name = "");
|
||||
void update_config(Action action);
|
||||
void close(Action action);
|
||||
@ -320,8 +330,8 @@ protected:
|
||||
class FullCompareDialog : public wxDialog
|
||||
{
|
||||
public:
|
||||
FullCompareDialog(const wxString& option_name, const wxString& old_value, const wxString& new_value,
|
||||
const wxString& old_value_header, const wxString& new_value_header);
|
||||
FullCompareDialog(const wxString& option_name, const wxString& old_value, const wxString& mod_value, const wxString& new_value,
|
||||
const wxString& old_value_header, const wxString& mod_value_header, const wxString& new_value_header);
|
||||
~FullCompareDialog() {}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user