FIX: replace ConfirmHintDialog with SecondaryCheckDialog

Change-Id: I3a712f838d7a4d8cbfe725c30f3d77813dd80b92
This commit is contained in:
tao.jin 2022-10-19 16:10:19 +08:00 committed by Lane.Wei
parent 7e96cbf7da
commit 92b0f591d3
5 changed files with 78 additions and 48 deletions

View File

@ -23,6 +23,8 @@
namespace Slic3r { namespace GUI { namespace Slic3r { namespace GUI {
wxDEFINE_EVENT(EVT_SECONDARY_CHECK_CONFIRM, wxCommandEvent);
ReleaseNoteDialog::ReleaseNoteDialog(Plater *plater /*= nullptr*/) ReleaseNoteDialog::ReleaseNoteDialog(Plater *plater /*= nullptr*/)
: DPIDialog(static_cast<wxWindow *>(wxGetApp().mainframe), wxID_ANY, _L("Release Note"), wxDefaultPosition, wxDefaultSize, wxCAPTION | wxCLOSE_BOX) : DPIDialog(static_cast<wxWindow *>(wxGetApp().mainframe), wxID_ANY, _L("Release Note"), wxDefaultPosition, wxDefaultSize, wxCAPTION | wxCLOSE_BOX)
{ {
@ -338,8 +340,8 @@ void UpdateVersionDialog::update_version_info(wxString release_note, wxString ve
} }
} }
SecondaryCheckDialog::SecondaryCheckDialog(wxWindow* parent) SecondaryCheckDialog::SecondaryCheckDialog(wxWindow* parent, wxWindowID id, const wxString& title, enum ButtonStyle btn_style, const wxPoint& pos, const wxSize& size, long style)
:DPIDialog(parent, wxID_ANY, _L("Confirm"), wxDefaultPosition, wxDefaultSize, wxCAPTION | wxCLOSE_BOX) :DPIDialog(parent, id, title, pos, size, style)
{ {
std::string icon_path = (boost::format("%1%/images/BambuStudioTitle.ico") % resources_dir()).str(); std::string icon_path = (boost::format("%1%/images/BambuStudioTitle.ico") % resources_dir()).str();
SetIcon(wxIcon(encode_path(icon_path.c_str()), wxBITMAP_TYPE_ICO)); SetIcon(wxIcon(encode_path(icon_path.c_str()), wxBITMAP_TYPE_ICO));
@ -380,7 +382,13 @@ SecondaryCheckDialog::SecondaryCheckDialog(wxWindow* parent)
m_button_ok->SetCornerRadius(FromDIP(12)); m_button_ok->SetCornerRadius(FromDIP(12));
m_button_ok->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent& e) { m_button_ok->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent& e) {
EndModal(wxID_YES); wxCommandEvent evt(EVT_SECONDARY_CHECK_CONFIRM, GetId());
e.SetEventObject(this);
GetEventHandler()->ProcessEvent(evt);
if (this->IsModal())
EndModal(wxID_YES);
else
this->Close();
}); });
m_button_cancel = new Button(this, _L("Cancel")); m_button_cancel = new Button(this, _L("Cancel"));
@ -392,9 +400,17 @@ SecondaryCheckDialog::SecondaryCheckDialog(wxWindow* parent)
m_button_cancel->SetCornerRadius(FromDIP(12)); m_button_cancel->SetCornerRadius(FromDIP(12));
m_button_cancel->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent& e) { m_button_cancel->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent& e) {
EndModal(wxID_NO); if (this->IsModal())
EndModal(wxID_NO);
else
this->Close();
}); });
if (btn_style != CONFIRM_AND_CANCEL)
m_button_cancel->Hide();
else
m_button_cancel->Show();
sizer_button->AddStretchSpacer(); sizer_button->AddStretchSpacer();
sizer_button->Add(m_button_ok, 0, wxALL, FromDIP(5)); sizer_button->Add(m_button_ok, 0, wxALL, FromDIP(5));
sizer_button->Add(m_button_cancel, 0, wxALL, FromDIP(5)); sizer_button->Add(m_button_cancel, 0, wxALL, FromDIP(5));
@ -438,6 +454,10 @@ wxString SecondaryCheckDialog::format_text(wxStaticText* st, wxString str, int w
int new_line_pos = 0; int new_line_pos = 0;
for (int i = 0; i < str.length(); i++) { for (int i = 0; i < str.length(); i++) {
if (str[i] == '\n') {
count_txt = "";
continue;
}
auto text_size = st->GetTextExtent(count_txt); auto text_size = st->GetTextExtent(count_txt);
if (text_size.x < warp) { if (text_size.x < warp) {
count_txt += str[i]; count_txt += str[i];

View File

@ -37,6 +37,8 @@
namespace Slic3r { namespace GUI { namespace Slic3r { namespace GUI {
wxDECLARE_EVENT(EVT_SECONDARY_CHECK_CONFIRM, wxCommandEvent);
class ReleaseNoteDialog : public DPIDialog class ReleaseNoteDialog : public DPIDialog
{ {
public: public:
@ -81,7 +83,20 @@ public:
class SecondaryCheckDialog : public DPIDialog class SecondaryCheckDialog : public DPIDialog
{ {
public: public:
SecondaryCheckDialog(wxWindow* parent); enum ButtonStyle {
ONLY_CONFIRM = 0,
CONFIRM_AND_CANCEL = 1,
MAX_STYLE_NUM = 2
};
SecondaryCheckDialog(
wxWindow* parent,
wxWindowID id = wxID_ANY,
const wxString& title = wxEmptyString,
enum ButtonStyle btn_style = CONFIRM_AND_CANCEL,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxCLOSE_BOX | wxCAPTION
);
void update_text(wxString text); void update_text(wxString text);
wxString format_text(wxStaticText* st, wxString str, int warp); wxString format_text(wxStaticText* st, wxString str, int warp);
~SecondaryCheckDialog(); ~SecondaryCheckDialog();

View File

@ -1805,7 +1805,7 @@ void SelectMachineDialog::on_ok_btn(wxCommandEvent &event)
|| has_slice_warnings || has_slice_warnings
) { ) {
wxString confirm_title = _L("Confirm"); wxString confirm_title = _L("Confirm");
SecondaryCheckDialog confirm_dlg(this); SecondaryCheckDialog confirm_dlg(this, wxID_ANY, confirm_title);
confirm_dlg.update_text(confirm_text); confirm_dlg.update_text(confirm_text);
if (confirm_dlg.ShowModal() == wxID_YES) { if (confirm_dlg.ShowModal() == wxID_YES) {
this->on_ok(); this->on_ok();

View File

@ -10,7 +10,7 @@
#include "slic3r/Utils/Http.hpp" #include "slic3r/Utils/Http.hpp"
#include "libslic3r/Thread.hpp" #include "libslic3r/Thread.hpp"
#include "RecenterDialog.hpp" #include "RecenterDialog.hpp"
#include "ConfirmHintDialog.hpp" #include "ReleaseNote.hpp"
namespace Slic3r { namespace GUI { namespace Slic3r { namespace GUI {
@ -1226,13 +1226,12 @@ void StatusPanel::on_subtask_pause_resume(wxCommandEvent &event)
void StatusPanel::on_subtask_abort(wxCommandEvent &event) void StatusPanel::on_subtask_abort(wxCommandEvent &event)
{ {
ConfirmHintDialog* abort_dlg = new ConfirmHintDialog(this, wxID_ANY, _L("Cancel print")); SecondaryCheckDialog abort_dlg(this->GetParent(), wxID_ANY, _L("Cancel print"));
abort_dlg->SetHint(_L("Are you sure you want to cancel this print?")); abort_dlg.update_text(_L("Are you sure you want to cancel this print?"));
abort_dlg->Bind(EVT_CONFIRM_HINT, [this](wxCommandEvent &e) { abort_dlg.Bind(EVT_SECONDARY_CHECK_CONFIRM, [this](wxCommandEvent &e) {
if (obj) obj->command_task_abort(); if (obj) obj->command_task_abort();
}); });
if(abort_dlg->ShowModal()) abort_dlg.ShowModal();
delete abort_dlg;
} }
void StatusPanel::error_info_reset() void StatusPanel::error_info_reset()
@ -1247,6 +1246,7 @@ void StatusPanel::error_info_reset()
void StatusPanel::on_subtask_clean(wxCommandEvent &event) void StatusPanel::on_subtask_clean(wxCommandEvent &event)
{ {
error_info_reset(); error_info_reset();
before_error_code = obj->print_error;
} }
void StatusPanel::on_webrequest_state(wxWebRequestEvent &evt) void StatusPanel::on_webrequest_state(wxWebRequestEvent &evt)
@ -1405,16 +1405,16 @@ void StatusPanel::update_error_message()
print_error_str.insert(4, " "); print_error_str.insert(4, " ");
} }
wxString error_msg = wxString::Format("%s[%s]", wxString error_msg = wxString::Format("%s[%s]",
wxGetApp().get_hms_query()->query_print_error_msg(obj->print_error), wxGetApp().get_hms_query()->query_print_error_msg(obj->print_error),
print_error_str); print_error_str);
show_error_message(error_msg); show_error_message(error_msg);
//hint dialog //hint dialog
BOOST_LOG_TRIVIAL(info) << "Print error! " << error_msg; BOOST_LOG_TRIVIAL(info) << "Print error! " << error_msg;
ConfirmHintDialog print_error_dlg(this->GetParent(), wxID_ANY, _L("Warning"), ConfirmHintDialog::ButtonStyle::ONLY_CONFIRM); SecondaryCheckDialog print_error_dlg(this->GetParent(), wxID_ANY, _L("Warning"), SecondaryCheckDialog::ButtonStyle::ONLY_CONFIRM);
print_error_dlg.SetHint(error_msg); print_error_dlg.update_text(error_msg);
print_error_dlg.ShowModal(); print_error_dlg.ShowModal();
} }
} }
} }
void StatusPanel::show_printing_status(bool ctrl_area, bool temp_area) void StatusPanel::show_printing_status(bool ctrl_area, bool temp_area)

View File

@ -5,7 +5,6 @@
#include "GUI_App.hpp" #include "GUI_App.hpp"
#include "libslic3r/Thread.hpp" #include "libslic3r/Thread.hpp"
#include "ReleaseNote.hpp" #include "ReleaseNote.hpp"
#include "ConfirmHintDialog.hpp"
namespace Slic3r { namespace Slic3r {
namespace GUI { namespace GUI {
@ -660,30 +659,30 @@ void MachineInfoPanel::upgrade_firmware_internal() {
void MachineInfoPanel::on_upgrade_firmware(wxCommandEvent &event) void MachineInfoPanel::on_upgrade_firmware(wxCommandEvent &event)
{ {
ConfirmHintDialog confirm_dlg(this->GetParent(), wxID_ANY, _L("Upgrade firmware")); SecondaryCheckDialog* confirm_dlg = new SecondaryCheckDialog(this->GetParent(), wxID_ANY, _L("Upgrade firmware"));
confirm_dlg.SetHint(_L( confirm_dlg->update_text(_L("Are you sure you want to update? This will take about 10 minutes. Do not turn off the power while the printer is updating."));
"Are you sure you want to update? This will take about 10 minutes. Do not turn off the power while the printer is updating." confirm_dlg->Bind(EVT_SECONDARY_CHECK_CONFIRM, [this](wxCommandEvent &e) {
)); if (m_obj) {
confirm_dlg.Bind(EVT_CONFIRM_HINT, [this](wxCommandEvent &e) {
if (m_obj){
m_obj->command_upgrade_confirm(); m_obj->command_upgrade_confirm();
} }
}); });
confirm_dlg.ShowModal(); if (confirm_dlg->ShowModal()) {
delete confirm_dlg;
}
} }
void MachineInfoPanel::on_consisitency_upgrade_firmware(wxCommandEvent &event) void MachineInfoPanel::on_consisitency_upgrade_firmware(wxCommandEvent &event)
{ {
ConfirmHintDialog confirm_dlg(this->GetParent(), wxID_ANY, _L("Upgrade firmware")); SecondaryCheckDialog* confirm_dlg = new SecondaryCheckDialog(this->GetParent(), wxID_ANY, _L("Upgrade firmware"));
confirm_dlg.SetHint(_L( confirm_dlg->update_text(_L("Are you sure you want to update? This will take about 10 minutes. Do not turn off the power while the printer is updating."));
"Are you sure you want to update? This will take about 10 minutes. Do not turn off the power while the printer is updating." confirm_dlg->Bind(EVT_SECONDARY_CHECK_CONFIRM, [this](wxCommandEvent &e) {
)); if (m_obj) {
confirm_dlg.Bind(EVT_CONFIRM_HINT, [this](wxCommandEvent &e) {
if (m_obj){
m_obj->command_consistency_upgrade_confirm(); m_obj->command_consistency_upgrade_confirm();
} }
}); });
confirm_dlg.ShowModal(); if (confirm_dlg->ShowModal()) {
delete confirm_dlg;
}
} }
void MachineInfoPanel::on_show_release_note(wxMouseEvent &event) void MachineInfoPanel::on_show_release_note(wxMouseEvent &event)
@ -798,16 +797,14 @@ void UpgradePanel::update(MachineObject *obj)
if (m_obj && m_show_forced_hint) { if (m_obj && m_show_forced_hint) {
if (m_obj->upgrade_force_upgrade) { if (m_obj->upgrade_force_upgrade) {
m_show_forced_hint = false; //lock hint m_show_forced_hint = false; //lock hint
ConfirmHintDialog force_dlg(m_scrolledWindow, wxID_ANY, _L("Upgrade firmware"), ConfirmHintDialog::CONFIRM_AND_CANCEL, wxDefaultPosition, wxDefaultSize, wxPD_APP_MODAL); SecondaryCheckDialog* force_dlg = new SecondaryCheckDialog(m_scrolledWindow, wxID_ANY, _L("Upgrade firmware"));
force_dlg.SetHint(_L( force_dlg->update_text(_L(
"An important update was detected and needs to be run before printing can continue. Do you want to update now? You can also update later from 'Upgrade firmware'." "An important update was detected and needs to be run before printing can continue. Do you want to update now? You can also update later from 'Upgrade firmware'."
)); ));
force_dlg.Bind(EVT_CONFIRM_HINT, [this](wxCommandEvent& e) { force_dlg->Bind(EVT_SECONDARY_CHECK_CONFIRM, &MachineInfoPanel::on_upgrade_firmware, m_push_upgrade_panel);
if (m_obj) { if (force_dlg->ShowModal()) {
m_obj->command_upgrade_confirm(); delete force_dlg;
} }
});
force_dlg.ShowModal();
} }
} }
@ -819,16 +816,14 @@ void UpgradePanel::update(MachineObject *obj)
if (m_obj && m_show_consistency_hint) { if (m_obj && m_show_consistency_hint) {
if (m_obj->upgrade_consistency_request) { if (m_obj->upgrade_consistency_request) {
m_show_consistency_hint = false; m_show_consistency_hint = false;
ConfirmHintDialog consistency_dlg(m_scrolledWindow, wxID_ANY, _L("Upgrade firmware"), ConfirmHintDialog::CONFIRM_AND_CANCEL, wxDefaultPosition, wxDefaultSize, wxPD_APP_MODAL); SecondaryCheckDialog* consistency_dlg = new SecondaryCheckDialog(m_scrolledWindow, wxID_ANY, _L("Upgrade firmware"));
consistency_dlg.SetHint(_L( consistency_dlg->update_text(_L(
"The firmware version is abnormal. Repairing and updating are required before printing. Do you want to update now? You can also update later on printer or update next time starting the studio." "The firmware version is abnormal. Repairing and updating are required before printing. Do you want to update now? You can also update later on printer or update next time starting the studio."
)); ));
consistency_dlg.Bind(EVT_CONFIRM_HINT, [this](wxCommandEvent& e) { consistency_dlg->Bind(EVT_SECONDARY_CHECK_CONFIRM, &MachineInfoPanel::on_consisitency_upgrade_firmware, m_push_upgrade_panel);
if (m_obj) { if (consistency_dlg->ShowModal()) {
m_obj->command_consistency_upgrade_confirm(); delete consistency_dlg;
} }
});
consistency_dlg.ShowModal();
} }
} }