* Fixed builds for non-MSW platforms (We can't change the signature of the RichMessageDialog. It have to be completely the same as for wxRichMessageDialog)
* Texts of the message dialog are changed. Use InfoDialog instead of a RichMessageDialog.
* MsgDialog: Added SetButtonLabel() function
* InfoDialog: For constructor added is_marked_message and style parameter to allow to use marked text in the Dialog and set different style
This commit is contained in:
YuSanka 2021-12-10 15:34:28 +01:00
parent c21950c07b
commit 102ef9a024
4 changed files with 49 additions and 36 deletions

View file

@ -352,7 +352,7 @@ void show_substitutions_info(const PresetsConfigSubstitutions& presets_config_su
add_config_substitutions(substitution.substitutions, changes); add_config_substitutions(substitution.substitutions, changes);
} }
InfoDialog msg(nullptr, _L("Configuration bundle was loaded, however some configuration values were not recognized."), substitution_message(changes)); InfoDialog msg(nullptr, _L("Configuration bundle was loaded, however some configuration values were not recognized."), substitution_message(changes), true);
msg.ShowModal(); msg.ShowModal();
} }
@ -363,7 +363,7 @@ void show_substitutions_info(const ConfigSubstitutions& config_substitutions, co
InfoDialog msg(nullptr, InfoDialog msg(nullptr,
format_wxstr(_L("Configuration file \"%1%\" was loaded, however some configuration values were not recognized."), from_u8(filename)), format_wxstr(_L("Configuration file \"%1%\" was loaded, however some configuration values were not recognized."), from_u8(filename)),
substitution_message(changes)); substitution_message(changes), true);
msg.ShowModal(); msg.ShowModal();
} }

View file

@ -948,24 +948,31 @@ bool GUI_App::check_older_app_config(Semver current_version, bool backup)
return false; return false;
BOOST_LOG_TRIVIAL(info) << "last app config file used: " << m_older_data_dir_path; BOOST_LOG_TRIVIAL(info) << "last app config file used: " << m_older_data_dir_path;
// ask about using older data folder // ask about using older data folder
RichMessageDialog msg(nullptr, backup ?
wxString::Format(_L( InfoDialog msg(nullptr
"Current configuration folder: %s" , format_wxstr(_L("You are opening %1% version %2%."), SLIC3R_APP_NAME, SLIC3R_VERSION)
"\n\n%s found another configuration for version %s." , backup ?
"\nIt is found at %s." format_wxstr(_L(
"\n\nDo you wish to copy and use the configuration file for version %s (overwriting any file with the same name)? A backup of your current configuration will be created." "The active configuration was created by <b>%1% %2%</b>,"
"\nIf you select no, you will continue with the configuration file for version %s (may not be fully compatible).") "\nwhile a newer configuration was found in <b>%3%</b>"
, current_version.to_string(), SLIC3R_APP_NAME, last_semver.to_string(), m_older_data_dir_path, last_semver.to_string(), current_version.to_string()) "\ncreated by <b>%1% %4%</b>."
: wxString::Format(_L( "\n\nShall the newer configuration be imported?"
"%s found another configuration for version %s." "\nIf so, your active configuration will backed up before importing the new configuration."
"\nIt is found at %s." )
"\nThere is no configuration file in current configuration folder." , SLIC3R_APP_NAME, current_version.to_string(), m_older_data_dir_path, last_semver.to_string())
"\n\nDo you wish to copy and use the configuration file for version %s?" : format_wxstr(_L(
"\nIf you select no, you will start with clean installation with configuration wizard.") "An existing configuration was found in <b>%3%</b>"
, SLIC3R_APP_NAME, last_semver.to_string(), m_older_data_dir_path, last_semver.to_string()) "\ncreated by <b>%1% %2%</b>."
, _L("PrusaSlicer") "\n\nShall this configuration be imported?"
, wxYES_NO )
, wxString::Format(_L("Load configuration from version %s?"), last_semver.to_string())); , SLIC3R_APP_NAME, last_semver.to_string(), m_older_data_dir_path)
, true, wxYES_NO);
if (backup) {
msg.SetButtonLabel(wxID_YES, _L("Import"));
msg.SetButtonLabel(wxID_NO, _L("Don't import"));
}
if (msg.ShowModal() == wxID_YES) { if (msg.ShowModal() == wxID_YES) {
std::string snapshot_id; std::string snapshot_id;
if (backup) { if (backup) {

View file

@ -63,6 +63,15 @@ MsgDialog::MsgDialog(wxWindow *parent, const wxString &title, const wxString &he
SetSizerAndFit(main_sizer); SetSizerAndFit(main_sizer);
} }
void MsgDialog::SetButtonLabel(wxWindowID btn_id, const wxString& label, bool set_focus/* = false*/)
{
if (wxButton* btn = get_button(btn_id)) {
btn->SetLabel(label);
if (set_focus)
btn->SetFocus();
}
}
wxButton* MsgDialog::add_button(wxWindowID btn_id, bool set_focus /*= false*/, const wxString& label/* = wxString()*/) wxButton* MsgDialog::add_button(wxWindowID btn_id, bool set_focus /*= false*/, const wxString& label/* = wxString()*/)
{ {
wxButton* btn = new wxButton(this, btn_id, label); wxButton* btn = new wxButton(this, btn_id, label);
@ -98,7 +107,7 @@ void MsgDialog::finalize()
// Text shown as HTML, so that mouse selection and Ctrl-V to copy will work. // Text shown as HTML, so that mouse selection and Ctrl-V to copy will work.
static void add_msg_content(wxWindow* parent, wxBoxSizer* content_sizer, wxString msg, bool monospaced_font = false) static void add_msg_content(wxWindow* parent, wxBoxSizer* content_sizer, wxString msg, bool monospaced_font = false, bool is_marked_msg = false)
{ {
wxHtmlWindow* html = new wxHtmlWindow(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_AUTO); wxHtmlWindow* html = new wxHtmlWindow(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_AUTO);
@ -136,8 +145,7 @@ static void add_msg_content(wxWindow* parent, wxBoxSizer* content_sizer, wxStrin
int em = wxGetApp().em_unit(); int em = wxGetApp().em_unit();
// if message containes the table // if message containes the table
bool is_marked = msg.Contains("<tr>"); if (msg.Contains("<tr>")) {
if (is_marked) {
int lines = msg.Freq('\n') + 1; int lines = msg.Freq('\n') + 1;
int pos = 0; int pos = 0;
while (pos < (int)msg.Len() && pos != wxNOT_FOUND) { while (pos < (int)msg.Len() && pos != wxNOT_FOUND) {
@ -155,7 +163,7 @@ static void add_msg_content(wxWindow* parent, wxBoxSizer* content_sizer, wxStrin
} }
html->SetMinSize(page_size); html->SetMinSize(page_size);
std::string msg_escaped = xml_escape(msg.ToUTF8().data(), is_marked); std::string msg_escaped = xml_escape(msg.ToUTF8().data(), is_marked_msg);
boost::replace_all(msg_escaped, "\r\n", "<br>"); boost::replace_all(msg_escaped, "\r\n", "<br>");
boost::replace_all(msg_escaped, "\n", "<br>"); boost::replace_all(msg_escaped, "\n", "<br>");
if (monospaced_font) if (monospaced_font)
@ -215,10 +223,8 @@ MessageDialog::MessageDialog(wxWindow* parent,
RichMessageDialog::RichMessageDialog(wxWindow* parent, RichMessageDialog::RichMessageDialog(wxWindow* parent,
const wxString& message, const wxString& message,
const wxString& caption/* = wxEmptyString*/, const wxString& caption/* = wxEmptyString*/,
long style/* = wxOK*/, long style/* = wxOK*/)
const wxString& headline/* = wxEmptyString*/ : MsgDialog(parent, caption.IsEmpty() ? wxString::Format(_L("%s info"), SLIC3R_APP_NAME) : caption, wxEmptyString, style)
)
: MsgDialog(parent, caption.IsEmpty() ? wxString::Format(_L("%s info"), SLIC3R_APP_NAME) : caption, headline, style)
{ {
add_msg_content(this, content_sizer, message); add_msg_content(this, content_sizer, message);
@ -245,11 +251,11 @@ int RichMessageDialog::ShowModal()
// InfoDialog // InfoDialog
InfoDialog::InfoDialog(wxWindow* parent, const wxString &title, const wxString& msg) InfoDialog::InfoDialog(wxWindow* parent, const wxString &title, const wxString& msg, bool is_marked_msg/* = false*/, long style/* = wxOK | wxICON_INFORMATION*/)
: MsgDialog(parent, wxString::Format(_L("%s information"), SLIC3R_APP_NAME), title, wxOK | wxICON_INFORMATION) : MsgDialog(parent, wxString::Format(_L("%s information"), SLIC3R_APP_NAME), title, style)
, msg(msg) , msg(msg)
{ {
add_msg_content(this, content_sizer, msg); add_msg_content(this, content_sizer, msg, false, is_marked_msg);
finalize(); finalize();
} }

View file

@ -30,7 +30,7 @@ struct MsgDialog : wxDialog
MsgDialog &operator=(const MsgDialog &) = delete; MsgDialog &operator=(const MsgDialog &) = delete;
virtual ~MsgDialog() = default; virtual ~MsgDialog() = default;
// TODO: refactor with CreateStdDialogButtonSizer usage void SetButtonLabel(wxWindowID btn_id, const wxString& label, bool set_focus = false);
protected: protected:
enum { enum {
@ -111,6 +111,7 @@ public:
class MessageDialog : public MsgDialog class MessageDialog : public MsgDialog
{ {
public: public:
// NOTE! Don't change a signature of contsrucor. It have to be tha same as for wxMessageDialog
MessageDialog( wxWindow *parent, MessageDialog( wxWindow *parent,
const wxString& message, const wxString& message,
const wxString& caption = wxEmptyString, const wxString& caption = wxEmptyString,
@ -130,12 +131,11 @@ class RichMessageDialog : public MsgDialog
bool m_checkBoxValue{ false }; bool m_checkBoxValue{ false };
public: public:
// NOTE! Don't change a signature of contsrucor. It have to be tha same as for wxRichMessageDialog
RichMessageDialog( wxWindow *parent, RichMessageDialog( wxWindow *parent,
const wxString& message, const wxString& message,
const wxString& caption = wxEmptyString, const wxString& caption = wxEmptyString,
long style = wxOK, long style = wxOK);
const wxString& headline = wxEmptyString
);
RichMessageDialog(RichMessageDialog&&) = delete; RichMessageDialog(RichMessageDialog&&) = delete;
RichMessageDialog(const RichMessageDialog&) = delete; RichMessageDialog(const RichMessageDialog&) = delete;
RichMessageDialog &operator=(RichMessageDialog&&) = delete; RichMessageDialog &operator=(RichMessageDialog&&) = delete;
@ -306,7 +306,7 @@ public:
class InfoDialog : public MsgDialog class InfoDialog : public MsgDialog
{ {
public: public:
InfoDialog(wxWindow *parent, const wxString &title, const wxString &msg); InfoDialog(wxWindow *parent, const wxString &title, const wxString &msg, bool is_marked = false, long style = wxOK| wxICON_INFORMATION);
InfoDialog(InfoDialog&&) = delete; InfoDialog(InfoDialog&&) = delete;
InfoDialog(const InfoDialog&) = delete; InfoDialog(const InfoDialog&) = delete;
InfoDialog&operator=(InfoDialog&&) = delete; InfoDialog&operator=(InfoDialog&&) = delete;