Replaced the static text control in error dialog with HTML control,
which supports copying of the text into clipboard. Removed the "copy to clipboard" button from the error dialog.
This commit is contained in:
parent
586ccad8f0
commit
de86e6ec9a
1 changed files with 24 additions and 24 deletions
|
@ -7,6 +7,9 @@
|
||||||
#include <wx/statbmp.h>
|
#include <wx/statbmp.h>
|
||||||
#include <wx/scrolwin.h>
|
#include <wx/scrolwin.h>
|
||||||
#include <wx/clipbrd.h>
|
#include <wx/clipbrd.h>
|
||||||
|
#include <wx/html/htmlwin.h>
|
||||||
|
|
||||||
|
#include <boost/algorithm/string/replace.hpp>
|
||||||
|
|
||||||
#include "libslic3r/libslic3r.h"
|
#include "libslic3r/libslic3r.h"
|
||||||
#include "libslic3r/Utils.hpp"
|
#include "libslic3r/Utils.hpp"
|
||||||
|
@ -50,7 +53,7 @@ MsgDialog::MsgDialog(wxWindow *parent, const wxString &title, const wxString &he
|
||||||
btn_sizer->Add(button);
|
btn_sizer->Add(button);
|
||||||
}
|
}
|
||||||
|
|
||||||
rightsizer->Add(btn_sizer, 0, wxALIGN_CENTRE_HORIZONTAL);
|
rightsizer->Add(btn_sizer, 0, wxALIGN_RIGHT);
|
||||||
|
|
||||||
auto *logo = new wxStaticBitmap(this, wxID_ANY, std::move(bitmap));
|
auto *logo = new wxStaticBitmap(this, wxID_ANY, std::move(bitmap));
|
||||||
|
|
||||||
|
@ -72,32 +75,29 @@ ErrorDialog::ErrorDialog(wxWindow *parent, const wxString &msg)
|
||||||
wxID_NONE)
|
wxID_NONE)
|
||||||
, msg(msg)
|
, msg(msg)
|
||||||
{
|
{
|
||||||
auto *panel = new wxScrolledWindow(this);
|
// Text shown as HTML, so that mouse selection and Ctrl-V to copy will work.
|
||||||
auto *p_sizer = new wxBoxSizer(wxVERTICAL);
|
wxHtmlWindow* html = new wxHtmlWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_AUTO);
|
||||||
panel->SetSizer(p_sizer);
|
{
|
||||||
|
html->SetMinSize(wxSize(40 * wxGetApp().em_unit(), -1));
|
||||||
auto *text = new wxStaticText(panel, wxID_ANY, msg);
|
wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
|
||||||
text->Wrap(CONTENT_WIDTH*wxGetApp().em_unit());
|
wxColour text_clr = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
|
||||||
p_sizer->Add(text, 1, wxEXPAND);
|
wxColour bgr_clr = wxSystemSettings::GetColour(wxSYS_COLOUR_FRAMEBK); // wxSYS_COLOUR_WINDOW
|
||||||
|
auto text_clr_str = wxString::Format(wxT("#%02X%02X%02X"), text_clr.Red(), text_clr.Green(), text_clr.Blue());
|
||||||
panel->SetMinSize(wxSize(CONTENT_WIDTH*wxGetApp().em_unit(), 0));
|
auto bgr_clr_str = wxString::Format(wxT("#%02X%02X%02X"), bgr_clr.Red(), bgr_clr.Green(), bgr_clr.Blue());
|
||||||
panel->SetScrollRate(0, 5);
|
const int font_size = font.GetPointSize()-1;
|
||||||
|
int size[] = {font_size, font_size, font_size, font_size, font_size, font_size, font_size};
|
||||||
content_sizer->Add(panel, 1, wxEXPAND);
|
html->SetFonts(font.GetFaceName(), font.GetFaceName(), size);
|
||||||
|
html->SetBorders(2);
|
||||||
auto *btn_copy = new wxButton(this, wxID_ANY, _(L("Copy to clipboard")));
|
std::string msg_escaped = xml_escape(msg.ToUTF8().data());
|
||||||
btn_copy->Bind(wxEVT_BUTTON, [this](wxCommandEvent& event) {
|
boost::replace_all(msg_escaped, "\r\n", "<br>");
|
||||||
if (wxTheClipboard->Open()) {
|
boost::replace_all(msg_escaped, "\n", "<br>");
|
||||||
wxTheClipboard->SetData(new wxTextDataObject(this->msg)); // Note: the clipboard takes ownership of the pointer
|
html->SetPage("<html><body bgcolor=\"" + bgr_clr_str + "\"><font color=\"" + text_clr_str + "\">" + wxString::FromUTF8(msg_escaped.data()) + "</font></body></html>");
|
||||||
wxTheClipboard->Close();
|
content_sizer->Add(html, 1, wxEXPAND);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
auto *btn_ok = new wxButton(this, wxID_OK);
|
auto *btn_ok = new wxButton(this, wxID_OK);
|
||||||
btn_ok->SetFocus();
|
btn_ok->SetFocus();
|
||||||
|
btn_sizer->Add(btn_ok, 0, wxRIGHT, HORIZ_SPACING);
|
||||||
btn_sizer->Add(btn_copy, 0, wxRIGHT, HORIZ_SPACING);
|
|
||||||
btn_sizer->Add(btn_ok);
|
|
||||||
|
|
||||||
SetMaxSize(wxSize(-1, CONTENT_MAX_HEIGHT*wxGetApp().em_unit()));
|
SetMaxSize(wxSize(-1, CONTENT_MAX_HEIGHT*wxGetApp().em_unit()));
|
||||||
Fit();
|
Fit();
|
||||||
|
|
Loading…
Add table
Reference in a new issue