added option to save a profile as detached(no inheritance)

This commit is contained in:
azio25134
2024-10-10 16:12:20 -07:00
parent fb032cd85f
commit c1326c6dec
3 changed files with 701 additions and 668 deletions

View File

@@ -146,6 +146,18 @@ SavePresetDialog::Item::Item(Preset::Type type, const std::string &suffix, wxBox
sizer->Add(radio_sizer, 0, wxEXPAND | wxTOP, BORDER_W);
// Only add the detach checkbox if m_mode is comDevelop
if (parent->m_mode == comDevelop) {
m_detach_checkbox = new wxCheckBox(parent, wxID_ANY, _L("Detach from parent"));
sizer->Add(m_detach_checkbox, 0, wxALIGN_LEFT | wxALL, BORDER_W);
// Set initial state (unchecked by default)
m_detach_checkbox->SetValue(m_detach);
// Bind the checkbox event to update the detach state for this item
m_detach_checkbox->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent&) { m_detach = m_detach_checkbox->GetValue(); });
}
auto radio_clicked = [this](wxMouseEvent &e) {
if (m_radio_user->GetId() == e.GetId()) {
m_radio_user->SetValue(true);
@@ -296,15 +308,15 @@ void SavePresetDialog::Item::DoSetSize(int x, int y, int width, int height, int
// SavePresetDialog
//-----------------------------------------------
SavePresetDialog::SavePresetDialog(wxWindow *parent, Preset::Type type, std::string suffix)
: DPIDialog(parent, wxID_ANY, _L("Save preset"), wxDefaultPosition, wxDefaultSize, wxCAPTION | wxCLOSE_BOX)
SavePresetDialog::SavePresetDialog(wxWindow* parent, Preset::Type type, int mode, std::string suffix)
: DPIDialog(parent, wxID_ANY, _L("Save preset"), wxDefaultPosition, wxDefaultSize, wxCAPTION | wxCLOSE_BOX), m_mode(mode)
{
build(std::vector<Preset::Type>{type}, suffix);
wxGetApp().UpdateDlgDarkUI(this);
}
SavePresetDialog::SavePresetDialog(wxWindow *parent, std::vector<Preset::Type> types, std::string suffix)
: DPIDialog(parent, wxID_ANY, _L("Save preset"), wxDefaultPosition, wxDefaultSize, wxCAPTION | wxCLOSE_BOX)
SavePresetDialog::SavePresetDialog(wxWindow* parent, std::vector<Preset::Type> types, int mode, std::string suffix)
: DPIDialog(parent, wxID_ANY, _L("Save preset"), wxDefaultPosition, wxDefaultSize, wxCAPTION | wxCLOSE_BOX), m_mode(mode)
{
build(types, suffix);
wxGetApp().UpdateDlgDarkUI(this);
@@ -414,6 +426,14 @@ bool SavePresetDialog::get_save_to_project_selection(Preset::Type type)
return false;
}
bool SavePresetDialog::get_detach_value(Preset::Type type)
{
for (const Item* item : m_items)
if (item->type() == type)
return item->is_detached();
return false;
}
bool SavePresetDialog::enable_ok_btn() const
{
for (const Item *item : m_items)

View File

@@ -56,6 +56,9 @@ class SavePresetDialog : public DPIDialog
//BBS: add project embedded preset relate logic
bool save_to_project() const { return m_save_to_project; }
// Method to get detach state
bool is_detached() const { return m_detach; }
Preset::Type m_type;
ValidationType m_valid_type;
std::string m_preset_name;
@@ -71,7 +74,10 @@ class SavePresetDialog : public DPIDialog
//BBS: add project embedded preset relate logic
RadioBox * m_radio_user{nullptr};
RadioBox * m_radio_project{nullptr};
wxCheckBox* m_detach_checkbox{nullptr};
bool m_save_to_project {false};
bool m_detach{false};
void update();
};
@@ -84,13 +90,14 @@ class SavePresetDialog : public DPIDialog
wxStaticText* m_label {nullptr};
wxBoxSizer* m_radio_sizer {nullptr};
ActionType m_action {UndefAction};
int m_mode;
std::string m_ph_printer_name;
std::string m_old_preset_name;
public:
SavePresetDialog(wxWindow *parent, Preset::Type type, std::string suffix = "");
SavePresetDialog(wxWindow* parent, std::vector<Preset::Type> types, std::string suffix = "");
SavePresetDialog(wxWindow* parent, Preset::Type type, int mode = 0, std::string suffix = "");
SavePresetDialog(wxWindow* parent, std::vector<Preset::Type> types, int mode = 0, std::string suffix = "");
~SavePresetDialog();
void AddItem(Preset::Type type, const std::string& suffix);
@@ -107,6 +114,10 @@ public:
//BBS: add project embedded preset relate logic
bool get_save_to_project_selection(Preset::Type type);
// Method to get the detach state
bool get_detach_value(Preset::Type type);
protected:
void on_dpi_changed(const wxRect& suggested_rect) override;
void on_sys_color_changed() override {}

View File

@@ -5506,17 +5506,18 @@ void Tab::save_preset(std::string name /*= ""*/, bool detach, bool save_to_proje
// focus currently.is there anything better than this ?
//! m_tabctrl->OnSetFocus();
if (from_input) {
SavePresetDialog dlg(m_parent, m_type, detach ? _u8L("Detached") : "");
SavePresetDialog dlg(m_parent, m_type, m_mode, detach ? _u8L("Detached") : "");
dlg.Show(false);
dlg.input_name_from_other(input_name);
wxCommandEvent evt(wxEVT_TEXT, GetId());
dlg.GetEventHandler()->ProcessEvent(evt);
dlg.confirm_from_other();
name = input_name;
detach = dlg.get_detach_value(m_type);
}
if (name.empty()) {
SavePresetDialog dlg(m_parent, m_type, detach ? _u8L("Detached") : "");
SavePresetDialog dlg(m_parent, m_type, m_mode, detach ? _u8L("Detached") : "");
if (!m_just_edit) {
if (dlg.ShowModal() != wxID_OK)
return;
@@ -5524,6 +5525,7 @@ void Tab::save_preset(std::string name /*= ""*/, bool detach, bool save_to_proje
name = dlg.get_name();
//BBS: add project embedded preset relate logic
save_to_project = dlg.get_save_to_project_selection(m_type);
detach = dlg.get_detach_value(m_type);
}
//BBS record current preset name