Don't log error messages when using the clipboard

wxClipboard::GetData()and wxClipboard::SetData() both log a "wxLogSysError" error-level message (see for example:  https://github.com/wxWidgets/wxWidgets/blob/v3.1.4/src/msw/clipbrd.cpp#L703 ). This logged message gets displayed as a messagebox to the user.

The logging can be disabled temporarily by creating a wxLogNull object. See https://docs.wxwidgets.org/3.0/classwx_log_null.html

Fixes https://gitlab.com/kicad/code/kicad/-/issues/6956
This commit is contained in:
Roberto Fernandez Bautista 2021-01-29 19:13:12 +00:00 committed by Jon Evans
parent 1c6c0bf8cf
commit 9aedeae5c3
13 changed files with 75 additions and 25 deletions

View File

@ -866,6 +866,8 @@ void EDA_3D_VIEWER::takeScreenshot( wxCommandEvent& event )
{
wxBitmap bitmap( screenshotImage );
wxLogNull doNotLog; // disable logging of failed clipboard actions
if( wxTheClipboard->Open() )
{
wxBitmapDataObject* dobjBmp = new wxBitmapDataObject( bitmap );

View File

@ -683,6 +683,8 @@ void BM2CMP_FRAME::OnExportToClipboard( wxCommandEvent& event )
std::string buffer;
ExportToBuffer( buffer, format );
wxLogNull doNotLog; // disable logging of failed clipboard actions
// Write buffer to the clipboard
if (wxTheClipboard->Open())
{

View File

@ -471,6 +471,8 @@ void DIALOG_ABOUT::onHtmlLinkClicked( wxHtmlLinkEvent& event )
void DIALOG_ABOUT::onCopyVersionInfo( wxCommandEvent& event )
{
wxLogNull doNotLog; // disable logging of failed clipboard actions
if( !wxTheClipboard->Open() )
{
wxMessageBox( _( "Could not open clipboard to write version information." ),

View File

@ -230,6 +230,8 @@ void WX_HTML_REPORT_PANEL::onMenuEvent( wxMenuEvent& event )
{
if( event.GetId() == wxID_COPY )
{
wxLogNull doNotLog; // disable logging of failed clipboard actions
if( wxTheClipboard->Open() )
{
bool primarySelection = wxTheClipboard->IsUsingPrimarySelection();

View File

@ -25,6 +25,7 @@
#include <grid_tricks.h>
#include <wx/tokenzr.h>
#include <wx/clipbrd.h>
#include <wx/log.h>
#include <widgets/grid_readonly_text_helpers.h>
@ -253,6 +254,8 @@ void GRID_TRICKS::showPopupMenu( wxMenu& menu )
menu.Enable( GRIDTRICKS_ID_PASTE, false );
wxLogNull doNotLog; // disable logging of failed clipboard actions
if( wxTheClipboard->Open() )
{
if( wxTheClipboard->IsSupported( wxDF_TEXT ) )
@ -470,6 +473,8 @@ void GRID_TRICKS::onKeyDown( wxKeyEvent& ev )
void GRID_TRICKS::paste_clipboard()
{
wxLogNull doNotLog; // disable logging of failed clipboard actions
if( wxTheClipboard->Open() )
{
if( wxTheClipboard->IsSupported( wxDF_TEXT ) )
@ -585,6 +590,8 @@ void GRID_TRICKS::paste_text( const wxString& cb_text )
void GRID_TRICKS::cutcopy( bool doCut )
{
wxLogNull doNotLog; // disable logging of failed clipboard actions
if( wxTheClipboard->Open() )
{
wxGridTableBase* tbl = m_grid->GetTable();

View File

@ -162,6 +162,8 @@ void SCINTILLA_TRICKS::onCharHook( wxKeyEvent& aEvent )
if( m_te->GetSelectionEnd() > m_te->GetSelectionStart() )
m_te->DeleteBack();
wxLogNull doNotLog; // disable logging of failed clipboard actions
if( wxTheClipboard->Open() )
{
if( wxTheClipboard->IsSupported( wxDF_TEXT ) )

View File

@ -975,6 +975,8 @@ void TOOL_MANAGER::ScheduleContextMenu( TOOL_BASE* aTool, ACTION_MENU* aMenu,
bool TOOL_MANAGER::SaveClipboard( const std::string& aTextUTF8 )
{
wxLogNull doNotLog; // disable logging of failed clipboard actions
if( wxTheClipboard->Open() )
{
// Store the UTF8 string as unicode string in clipboard:
@ -993,6 +995,8 @@ std::string TOOL_MANAGER::GetClipboardUTF8() const
{
std::string result;
wxLogNull doNotLog; // disable logging of failed clipboard actions
if( wxTheClipboard->Open() )
{
if( wxTheClipboard->IsSupported( wxDF_TEXT )

View File

@ -84,6 +84,8 @@ int CVPCB_ASSOCIATION_TOOL::CopyAssoc( const TOOL_EVENT& aEvent )
if( !fpid.IsValid() )
return 0;
wxLogNull doNotLog; // disable logging of failed clipboard actions
if( wxTheClipboard->Open() )
{
wxTheClipboard->SetData( new wxTextDataObject( fpid.GetUniStringLibId() ) );
@ -118,20 +120,24 @@ int CVPCB_ASSOCIATION_TOOL::CutAssoc( const TOOL_EVENT& aEvent )
return 0;
// Save it to the clipboard
if( wxTheClipboard->Open() )
{
if( !wxTheClipboard->SetData( new wxTextDataObject( fpid.GetUniStringLibId() ) ) )
wxLogNull doNotLog; // disable logging of failed clipboard actions
if( wxTheClipboard->Open() )
{
if( !wxTheClipboard->SetData( new wxTextDataObject( fpid.GetUniStringLibId() ) ) )
{
wxTheClipboard->Close();
return 0;
}
wxTheClipboard->Flush();
wxTheClipboard->Close();
}
else
{
return 0;
}
wxTheClipboard->Flush();
wxTheClipboard->Close();
}
else
{
return 0;
}
// Remove the association
@ -153,14 +159,18 @@ int CVPCB_ASSOCIATION_TOOL::PasteAssoc( const TOOL_EVENT& aEvent )
LIB_ID fpid;
wxTextDataObject data;
if( wxTheClipboard->Open() )
{
wxTheClipboard->GetData( data );
wxTheClipboard->Close();
}
else
{
return 0;
wxLogNull doNotLog; // disable logging of failed clipboard actions
if( wxTheClipboard->Open() )
{
wxTheClipboard->GetData( data );
wxTheClipboard->Close();
}
else
{
return 0;
}
}
if( fpid.Parse( data.GetText() ) >= 0 )

View File

@ -325,6 +325,7 @@ void DIALOG_CHOOSE_SYMBOL::OnCharHook( wxKeyEvent& e )
!e.AltDown() && !e.ShiftDown() && !e.MetaDown() )
{
wxString txt = m_details->SelectionToText();
wxLogNull doNotLog; // disable logging of failed clipboard actions
if( wxTheClipboard->Open() )
{

View File

@ -528,12 +528,16 @@ void SCH_EDIT_FRAME::DrawCurrentSheetToClipboard()
PrintPage( GetRenderSettings() );
if( wxTheClipboard->Open() )
{
// This data objects are held by the clipboard, so do not delete them in the app.
wxBitmapDataObject* clipbrd_data = new wxBitmapDataObject( image );
wxTheClipboard->SetData( clipbrd_data );
wxTheClipboard->Close();
wxLogNull doNotLog; // disable logging of failed clipboard actions
if( wxTheClipboard->Open() )
{
// This data objects are held by the clipboard, so do not delete them in the app.
wxBitmapDataObject* clipbrd_data = new wxBitmapDataObject( image );
wxTheClipboard->SetData( clipbrd_data );
wxTheClipboard->Close();
}
}
// Deselect Bitmap from DC in order to delete the MemoryDC

View File

@ -761,6 +761,8 @@ void SYMBOL_EDIT_FRAME::CopyPartToClipboard()
STRING_FORMATTER formatter;
SCH_SEXPR_PLUGIN::FormatPart( tmp.get(), formatter );
wxLogNull doNotLog; // disable logging of failed clipboard actions
auto clipboard = wxTheClipboard;
wxClipboardLocker clipboardLock( clipboard );
@ -788,6 +790,8 @@ void SYMBOL_EDIT_FRAME::DuplicatePart( bool aFromClipboard )
if( aFromClipboard )
{
wxLogNull doNotLog; // disable logging of failed clipboard actions
auto clipboard = wxTheClipboard;
wxClipboardLocker clipboardLock( clipboard );

View File

@ -281,6 +281,8 @@ void PANEL_SETUP_BOARD_STACKUP::onExportToClipboard( wxCommandEvent& event )
// Build a ascii representation of stackup and copy it in the clipboard
wxString report = BuildStackupReport( m_stackup, m_units );
wxLogNull doNotLog; // disable logging of failed clipboard actions
if( wxTheClipboard->Open() )
{
// This data objects are held by the clipboard,

View File

@ -240,6 +240,7 @@ void CLIPBOARD_IO::SaveSelection( const PCB_SELECTION& aSelected, bool isFootpri
}
// These are placed at the end to minimize the open time of the clipboard
wxLogNull doNotLog; // disable logging of failed clipboard actions
auto clipboard = wxTheClipboard;
wxClipboardLocker clipboardLock( clipboard );
@ -251,7 +252,7 @@ void CLIPBOARD_IO::SaveSelection( const PCB_SELECTION& aSelected, bool isFootpri
clipboard->Flush();
#ifndef __WXOSX__
#ifndef __WXOSX__ )
// This section exists to return the clipboard data, ensuring it has fully
// been processed by the system clipboard. This appears to be needed for
// extremely large clipboard copies on asynchronous linux clipboard managers
@ -259,12 +260,13 @@ void CLIPBOARD_IO::SaveSelection( const PCB_SELECTION& aSelected, bool isFootpri
// clipboard is closed seems to cause an ASAN error (heap-buffer-overflow)
// since it uses the cached version of the clipboard data and not the system
// clipboard data.
if( clipboard->IsSupported( wxDF_TEXT ) )
{
wxTextDataObject data;
clipboard->GetData( data );
( void )data.GetText(); // Keep unused variable
(void) data.GetText(); // Keep unused variable
}
#endif
#endif
}
@ -273,13 +275,14 @@ BOARD_ITEM* CLIPBOARD_IO::Parse()
BOARD_ITEM* item;
wxString result;
wxLogNull doNotLog; // disable logging of failed clipboard actions
auto clipboard = wxTheClipboard;
wxClipboardLocker clipboardLock( clipboard );
if( !clipboardLock )
return nullptr;
if( clipboard->IsSupported( wxDF_TEXT ) )
{
wxTextDataObject data;
@ -320,6 +323,8 @@ void CLIPBOARD_IO::Save( const wxString& aFileName, BOARD* aBoard,
m_out->Print( 0, ")\n" );
wxLogNull doNotLog; // disable logging of failed clipboard actions
auto clipboard = wxTheClipboard;
wxClipboardLocker clipboardLock( clipboard );
@ -334,6 +339,7 @@ void CLIPBOARD_IO::Save( const wxString& aFileName, BOARD* aBoard,
// been processed by the system clipboard. This appears to be needed for
// extremely large clipboard copies on asynchronous linux clipboard managers
// such as KDE's Klipper
if( clipboard->IsSupported( wxDF_TEXT ) )
{
wxTextDataObject data;
clipboard->GetData( data );
@ -347,6 +353,8 @@ BOARD* CLIPBOARD_IO::Load( const wxString& aFileName, BOARD* aAppendToMe,
{
std::string result;
wxLogNull doNotLog; // disable logging of failed clipboard actions
auto clipboard = wxTheClipboard;
wxClipboardLocker clipboardLock( clipboard );