From b2951cb43e739f03e5baf7a03b0eb064b779ad07 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 24 Nov 2020 10:03:15 +0100 Subject: [PATCH] Added "Remember my choice" checkbox to the message dialog after first clicking on parameter label in Settings tabs --- src/slic3r/GUI/OG_CustomCtrl.cpp | 64 +++++++++++++++++++++++++++----- src/slic3r/GUI/OG_CustomCtrl.hpp | 14 +++++++ src/slic3r/GUI/Preferences.cpp | 6 ++- 3 files changed, 74 insertions(+), 10 deletions(-) diff --git a/src/slic3r/GUI/OG_CustomCtrl.cpp b/src/slic3r/GUI/OG_CustomCtrl.cpp index 7da66a5655..8469b1a4b6 100644 --- a/src/slic3r/GUI/OG_CustomCtrl.cpp +++ b/src/slic3r/GUI/OG_CustomCtrl.cpp @@ -674,21 +674,67 @@ wxCoord OG_CustomCtrl::CtrlLine::draw_act_bmps(wxDC& dc, wxPoint pos, const wxBi bool OG_CustomCtrl::CtrlLine::launch_browser() const { + if (!is_focused || og_line.label_path.IsEmpty()) + return false; + + bool launch = true; + if (get_app_config()->get("suppress_hyperlinks").empty()) { - wxString preferences_item = _L("Suppress to open hyperlink in browser"); - wxString msg = - _L("PrusaSlicer will remember your action.") + "\n" + - _L("You will not be asked about it again on label hovering.") + "\n\n" + - format_wxstr(_L("Visit \"Preferences\" and check \"%1%\"\nto changes your choise."), preferences_item) + "\n\n" + - _L("Should we suppress to use hyperlinks in PrusaSlicer?"); + RememberChoiceDialog dialog(nullptr, _L("Should we open this hyperlink in your default browser?"), _L("PrusaSlicer: Open hyperlink")); + int answer = dialog.ShowModal(); + launch = answer == wxID_YES; - wxMessageDialog dialog(nullptr, msg, _L("PrusaSlicer: Don't ask me again"), wxYES | wxNO | wxICON_INFORMATION); - get_app_config()->set("suppress_hyperlinks", dialog.ShowModal() == wxID_YES ? "1" : "0"); + get_app_config()->set("suppress_hyperlinks", dialog.remember_choice() ? (answer == wxID_NO ? "1" : "0") : ""); } + if (launch) + launch = get_app_config()->get("suppress_hyperlinks") != "1"; - return get_app_config()->get("suppress_hyperlinks") == "0" && is_focused && !og_line.label_path.IsEmpty() && wxLaunchDefaultBrowser(get_url(og_line.label_path)); + return launch && wxLaunchDefaultBrowser(get_url(og_line.label_path)); } +RememberChoiceDialog::RememberChoiceDialog(wxWindow* parent, const wxString& msg_text, const wxString& caption) + : wxDialog(parent, wxID_ANY, caption, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxICON_INFORMATION) +{ + this->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); + this->SetEscapeId(wxID_CLOSE); + + wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL); + + m_remember_choice = new wxCheckBox(this, wxID_ANY, _L("Remember my choice")); + m_remember_choice->SetValue(false); + m_remember_choice->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent& evt) + { + if (!evt.IsChecked()) + return; + wxString preferences_item = _L("Suppress to open hyperlink in browser"); + wxString msg = + _L("PrusaSlicer will remember your choice.") + "\n\n" + + _L("You will not be asked about it again on label hovering.") + "\n\n" + + format_wxstr(_L("Visit \"Preferences\" and check \"%1%\"\nto changes your choice."), preferences_item); + + wxMessageDialog dialog(nullptr, msg, _L("PrusaSlicer: Don't ask me again"), wxOK | wxCANCEL | wxICON_INFORMATION); + if (dialog.ShowModal() == wxID_CANCEL) + m_remember_choice->SetValue(false); + }); + + + // Add dialog's buttons + wxStdDialogButtonSizer* btns = this->CreateStdDialogButtonSizer(wxYES | wxNO); + wxButton* btnYES = static_cast(this->FindWindowById(wxID_YES, this)); + wxButton* btnNO = static_cast(this->FindWindowById(wxID_NO, this)); + btnYES->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { this->EndModal(wxID_YES); }); + btnNO->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { this->EndModal(wxID_NO); }); + + topSizer->Add(new wxStaticText(this, wxID_ANY, msg_text), 0, wxEXPAND | wxALL, 10); + topSizer->Add(m_remember_choice, 0, wxEXPAND | wxALL, 10); + topSizer->Add(btns, 0, wxEXPAND | wxALL, 10); + + this->SetSizer(topSizer); + topSizer->SetSizeHints(this); + + this->CenterOnScreen(); +} + } // GUI } // Slic3r diff --git a/src/slic3r/GUI/OG_CustomCtrl.hpp b/src/slic3r/GUI/OG_CustomCtrl.hpp index 722b393f5a..798443f390 100644 --- a/src/slic3r/GUI/OG_CustomCtrl.hpp +++ b/src/slic3r/GUI/OG_CustomCtrl.hpp @@ -95,6 +95,20 @@ public: }; +//----------------------------------------------- +// RememberChoiceDialog +//----------------------------------------------- + +class RememberChoiceDialog : public wxDialog +{ + wxCheckBox* m_remember_choice; +public: + RememberChoiceDialog(wxWindow* parent, const wxString& msg_text, const wxString& caption); + ~RememberChoiceDialog() {} + + bool remember_choice() const { return m_remember_choice->GetValue(); } +}; + }} #endif /* slic3r_OG_CustomCtrl_hpp_ */ diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp index 4abe4b84c4..95e86ff7e0 100644 --- a/src/slic3r/GUI/Preferences.cpp +++ b/src/slic3r/GUI/Preferences.cpp @@ -204,7 +204,11 @@ void PreferencesDialog::build() m_optgroup_gui = std::make_shared(this, _L("GUI")); m_optgroup_gui->label_width = 40; m_optgroup_gui->m_on_change = [this](t_config_option_key opt_key, boost::any value) { - m_values[opt_key] = boost::any_cast(value) ? "1" : "0"; + if (opt_key == "suppress_hyperlinks") + m_values[opt_key] = boost::any_cast(value) ? "1" : ""; + else + m_values[opt_key] = boost::any_cast(value) ? "1" : "0"; + if (opt_key == "use_custom_toolbar_size") { m_icon_size_sizer->ShowItems(boost::any_cast(value)); this->layout();