mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-31 12:41:20 -06:00 
			
		
		
		
	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/scrolwin.h> | ||||
| #include <wx/clipbrd.h> | ||||
| #include <wx/html/htmlwin.h> | ||||
| 
 | ||||
| #include <boost/algorithm/string/replace.hpp> | ||||
| 
 | ||||
| #include "libslic3r/libslic3r.h" | ||||
| #include "libslic3r/Utils.hpp" | ||||
|  | @ -50,7 +53,7 @@ MsgDialog::MsgDialog(wxWindow *parent, const wxString &title, const wxString &he | |||
| 		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)); | ||||
| 
 | ||||
|  | @ -72,32 +75,29 @@ ErrorDialog::ErrorDialog(wxWindow *parent, const wxString &msg) | |||
| 		wxID_NONE) | ||||
| 	, msg(msg) | ||||
| { | ||||
| 	auto *panel = new wxScrolledWindow(this); | ||||
| 	auto *p_sizer = new wxBoxSizer(wxVERTICAL); | ||||
| 	panel->SetSizer(p_sizer); | ||||
| 
 | ||||
| 	auto *text = new wxStaticText(panel, wxID_ANY, msg); | ||||
| 	text->Wrap(CONTENT_WIDTH*wxGetApp().em_unit()); | ||||
| 	p_sizer->Add(text, 1, wxEXPAND); | ||||
| 
 | ||||
|     panel->SetMinSize(wxSize(CONTENT_WIDTH*wxGetApp().em_unit(), 0)); | ||||
| 	panel->SetScrollRate(0, 5); | ||||
| 
 | ||||
| 	content_sizer->Add(panel, 1, wxEXPAND); | ||||
| 
 | ||||
| 	auto *btn_copy = new wxButton(this, wxID_ANY, _(L("Copy to clipboard"))); | ||||
| 	btn_copy->Bind(wxEVT_BUTTON, [this](wxCommandEvent& event) { | ||||
| 		if (wxTheClipboard->Open()) { | ||||
| 			wxTheClipboard->SetData(new wxTextDataObject(this->msg));   // Note: the clipboard takes ownership of the pointer
 | ||||
| 			wxTheClipboard->Close(); | ||||
| 		} | ||||
| 	}); | ||||
|     // Text shown as HTML, so that mouse selection and Ctrl-V to copy will work.
 | ||||
|     wxHtmlWindow* html = new wxHtmlWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_AUTO); | ||||
|     { | ||||
|         html->SetMinSize(wxSize(40 * wxGetApp().em_unit(), -1)); | ||||
|         wxFont 	  	font 			= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); | ||||
| 		wxColour  	text_clr  		= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT); | ||||
| 		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()); | ||||
| 		auto      	bgr_clr_str 	= wxString::Format(wxT("#%02X%02X%02X"), bgr_clr.Red(), bgr_clr.Green(), bgr_clr.Blue()); | ||||
| 		const int 	font_size       = font.GetPointSize()-1; | ||||
|         int 		size[] 			= {font_size, font_size, font_size, font_size, font_size, font_size, font_size}; | ||||
|         html->SetFonts(font.GetFaceName(), font.GetFaceName(), size); | ||||
|         html->SetBorders(2); | ||||
| 		std::string msg_escaped = xml_escape(msg.ToUTF8().data()); | ||||
| 		boost::replace_all(msg_escaped, "\r\n", "<br>"); | ||||
|         boost::replace_all(msg_escaped, "\n", "<br>"); | ||||
| 		html->SetPage("<html><body bgcolor=\"" + bgr_clr_str + "\"><font color=\"" + text_clr_str + "\">" + wxString::FromUTF8(msg_escaped.data()) + "</font></body></html>"); | ||||
| 		content_sizer->Add(html, 1, wxEXPAND); | ||||
|     } | ||||
| 
 | ||||
| 	auto *btn_ok = new wxButton(this, wxID_OK); | ||||
| 	btn_ok->SetFocus(); | ||||
| 
 | ||||
| 	btn_sizer->Add(btn_copy, 0, wxRIGHT, HORIZ_SPACING); | ||||
| 	btn_sizer->Add(btn_ok); | ||||
| 	btn_sizer->Add(btn_ok, 0, wxRIGHT, HORIZ_SPACING); | ||||
| 
 | ||||
|     SetMaxSize(wxSize(-1, CONTENT_MAX_HEIGHT*wxGetApp().em_unit())); | ||||
| 	Fit(); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 bubnikv
						bubnikv