DiffPresetDialog: Refactoring.

Move logic of a processing of selected options to owned dialog instead of MainFrame.
This commit is contained in:
YuSanka 2023-09-25 16:22:03 +02:00
parent e9fb61b8aa
commit bbbeedf1ce
4 changed files with 25 additions and 54 deletions

View File

@ -288,49 +288,8 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_S
preferences_dialog = new PreferencesDialog(this);
}
// bind events from DiffDlg
bind_diff_dialog();
}
void MainFrame::bind_diff_dialog()
{
auto get_tab = [](Preset::Type type) {
Tab* null_tab = nullptr;
for (Tab* tab : wxGetApp().tabs_list)
if (tab->type() == type)
return tab;
return null_tab;
};
auto transfer = [this, get_tab](Preset::Type type) {
get_tab(type)->transfer_options(diff_dialog.get_left_preset_name(type),
diff_dialog.get_right_preset_name(type),
diff_dialog.get_selected_options(type));
};
auto update_presets = [this, get_tab](Preset::Type type) {
get_tab(type)->update_preset_choice();
m_plater->sidebar().update_presets(type);
};
auto process_options = [this](std::function<void(Preset::Type)> process) {
const Preset::Type diff_dlg_type = diff_dialog.view_type();
if (diff_dlg_type == Preset::TYPE_INVALID) {
for (const Preset::Type& type : diff_dialog.types_list() )
process(type);
}
else
process(diff_dlg_type);
};
diff_dialog.Bind(EVT_DIFF_DIALOG_TRANSFER, [process_options, transfer](SimpleEvent&) { process_options(transfer); });
diff_dialog.Bind(EVT_DIFF_DIALOG_UPDATE_PRESETS,[process_options, update_presets](SimpleEvent&) { process_options(update_presets); });
}
#ifdef _MSW_DARK_MODE
static wxString pref() { return " [ "; }
static wxString suff() { return " ] "; }

View File

@ -117,7 +117,6 @@ class MainFrame : public DPIFrame
bool can_delete() const;
bool can_delete_all() const;
bool can_reslice() const;
void bind_diff_dialog();
// MenuBar items changeable in respect to printer technology
enum MenuItems

View File

@ -41,10 +41,6 @@ namespace Slic3r {
namespace GUI {
wxDEFINE_EVENT(EVT_DIFF_DIALOG_TRANSFER, SimpleEvent);
wxDEFINE_EVENT(EVT_DIFF_DIALOG_UPDATE_PRESETS, SimpleEvent);
// ----------------------------------------------------------------------------
// ModelNode: a node inside DiffModel
// ----------------------------------------------------------------------------
@ -2062,13 +2058,34 @@ void DiffPresetDialog::button_event(Action act)
}
else {
Hide();
if (act == Action::Transfer)
wxPostEvent(this, SimpleEvent(EVT_DIFF_DIALOG_TRANSFER));
process_options([this](Preset::Type type) {
if (Tab* tab = wxGetApp().get_tab(type))
tab->transfer_options(get_left_preset_name(type),
get_right_preset_name(type),
get_selected_options(type));
});
else if (!presets_to_save.empty())
wxPostEvent(this, SimpleEvent(EVT_DIFF_DIALOG_UPDATE_PRESETS));
process_options([this](Preset::Type type) {
if (Tab* tab = wxGetApp().get_tab(type)) {
tab->update_preset_choice();
wxGetApp().sidebar().update_presets(type);
}
});
}
}
void DiffPresetDialog::process_options(std::function<void(Preset::Type)> process)
{
if (m_view_type == Preset::TYPE_INVALID) {
for (const Preset::Type& type : types_list())
process(type);
}
else
process(m_view_type);
};
std::string DiffPresetDialog::get_left_preset_name(Preset::Type type)
{
PresetComboBox* cb = m_preset_combos[int(type - Preset::TYPE_PRINT)].presets_left;

View File

@ -17,10 +17,7 @@ class ScalableButton;
class wxStaticText;
namespace Slic3r {
namespace GUI{
wxDECLARE_EVENT(EVT_DIFF_DIALOG_TRANSFER, SimpleEvent);
wxDECLARE_EVENT(EVT_DIFF_DIALOG_UPDATE_PRESETS, SimpleEvent);
namespace GUI {
// ----------------------------------------------------------------------------
// ModelNode: a node inside DiffModel
@ -412,8 +409,7 @@ public:
void show(Preset::Type type = Preset::TYPE_INVALID);
void update_presets(Preset::Type type = Preset::TYPE_INVALID, bool update_preset_bundles_from_app = true);
Preset::Type view_type() const { return m_view_type; }
PrinterTechnology printer_technology() const { return m_pr_technology; }
void process_options(std::function<void(Preset::Type)> process);
std::string get_left_preset_name(Preset::Type type);
std::string get_right_preset_name(Preset::Type type);