Implemented FR #7850 - G-Code Substitutions: move [X Delete all] button or ask for confirmation

+ MsgDialog:
* Added processing if the wxNO_DEFAULT and wxCANCEL_DEFAULT flags
* Next improvements of get_wraped_wxString() function
This commit is contained in:
YuSanka 2022-02-02 11:35:07 +01:00
parent 1fb41a8e22
commit fc59a2c1b0
2 changed files with 20 additions and 23 deletions

View File

@ -94,9 +94,9 @@ wxButton* MsgDialog::get_button(wxWindowID btn_id){
void MsgDialog::apply_style(long style)
{
if (style & wxOK) add_button(wxID_OK, true);
if (style & wxYES) add_button(wxID_YES, true);
if (style & wxNO) add_button(wxID_NO);
if (style & wxCANCEL) add_button(wxID_CANCEL);
if (style & wxYES) add_button(wxID_YES, !(style & wxNO_DEFAULT));
if (style & wxNO) add_button(wxID_NO, (style & wxNO_DEFAULT));
if (style & wxCANCEL) add_button(wxID_CANCEL, (style & wxCANCEL_DEFAULT));
logo->SetBitmap( create_scaled_bitmap(style & wxICON_WARNING ? "exclamation" :
style & wxICON_INFORMATION ? "info" :
@ -298,25 +298,12 @@ wxString get_wraped_wxString(const wxString& in, size_t line_len /*=80*/)
for (size_t i = 0; i < in.size();) {
// Overwrite the character (space or newline) starting at ibreak?
bool overwrite = false;
#if wxUSE_UNICODE_WCHAR
// On Windows, most likely the internal representation of wxString is wide char.
size_t end = std::min(in.size(), i + line_len);
size_t ibreak = end;
for (size_t j = i; j < end; ++ j) {
if (bool newline = in[j] == '\n'; in[j] == ' ' || in[j] == '\t' || newline) {
ibreak = j;
overwrite = true;
if (newline)
break;
} else if (in[j] == '/' || in[j] == '\\')
ibreak = j + 1;
}
#else
// UTF8 representation of wxString.
// Where to break the line, index of character at the start of a UTF-8 sequence.
size_t ibreak = size_t(-1);
// Overwrite the character at ibreak (it is a whitespace) or not?
for (size_t cnt = 0, j = i; j < in.size();) {
size_t j = i;
for (size_t cnt = 0; j < in.size();) {
if (bool newline = in[j] == '\n'; in[j] == ' ' || in[j] == '\t' || newline) {
// Overwrite the whitespace.
ibreak = j ++;
@ -325,16 +312,23 @@ wxString get_wraped_wxString(const wxString& in, size_t line_len /*=80*/)
break;
} else if (in[j] == '/') {
// Insert after the slash.
ibreak = ++ j;
ibreak = ++ j;
overwrite = false;
} else
j += get_utf8_sequence_length(in.c_str() + j, in.size() - j);
if (++ cnt == line_len) {
if (ibreak == size_t(-1))
ibreak = j;
if (ibreak == size_t(-1)) {
ibreak = j;
overwrite = false;
}
break;
}
}
#endif
if (j == in.size()) {
out.append(in.begin() + i, in.end());
break;
}
assert(ibreak != size_t(-1));
out.append(in.begin() + i, in.begin() + ibreak);
out.append('\n');
i = ibreak;

View File

@ -4139,7 +4139,10 @@ wxSizer* TabPrint::create_manage_substitution_widget(wxWindow* parent)
});
create_btn(&m_del_all_substitutions_btn, _L("Delete all"), "cross");
m_del_all_substitutions_btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent e) {
m_del_all_substitutions_btn->Bind(wxEVT_BUTTON, [this, parent](wxCommandEvent e) {
if (MessageDialog(parent, _L("Are you sure you want to delete all substitutions?"), SLIC3R_APP_NAME, wxYES_NO | wxICON_QUESTION).
ShowModal() != wxID_YES)
return;
m_subst_manager.delete_all();
m_del_all_substitutions_btn->Hide();
});