pcbnew: Set clipboard locale to avoid Klipper crash

Klipper seems to poll at odd times.  When we copy to wxTheClipboard
in one locale and Klipper extracts data in a different locale, it throws
an XError.  We don't need the extra LOCALE_IO calls as Format() uses its
own LOCALE_IO setting.

Fixes: lp:1800648
* https://bugs.launchpad.net/kicad/+bug/1800648

(cherry picked from commit 964d6ebc06)
This commit is contained in:
Seth Hillbrand 2018-11-01 21:12:34 -07:00
parent c0d9b9ab81
commit 82c9e54735
1 changed files with 40 additions and 34 deletions

View File

@ -61,13 +61,18 @@ void CLIPBOARD_IO::SetBoard( BOARD* aBoard )
void CLIPBOARD_IO::SaveSelection( const SELECTION& aSelected )
{
LOCALE_IO toggle; // toggles on, then off, the C locale.
VECTOR2I refPoint( 0, 0 );
// dont even start if the selection is empty
if( aSelected.Empty() )
return;
auto clipboard = wxTheClipboard;
wxClipboardLocker clipboardLock( clipboard );
if( !clipboardLock || !clipboard->IsOpened() )
return;
if( aSelected.HasReferencePoint() )
refPoint = aSelected.GetReferencePoint();
@ -175,16 +180,14 @@ void CLIPBOARD_IO::SaveSelection( const SELECTION& aSelected )
Format( clone.get(), 1 );
}
}
m_formatter.Print( 0, "\n)" );
}
if( wxTheClipboard->Open() )
{
wxTheClipboard->SetData( new wxTextDataObject(
clipboard->SetData( new wxTextDataObject(
wxString( m_formatter.GetString().c_str(), wxConvUTF8 ) ) );
wxTheClipboard->Close();
}
clipboard->Flush();
}
@ -193,18 +196,20 @@ BOARD_ITEM* CLIPBOARD_IO::Parse()
BOARD_ITEM* item;
wxString result;
if( wxTheClipboard->Open() )
{
if( wxTheClipboard->IsSupported( wxDF_TEXT ) )
auto clipboard = wxTheClipboard;
wxClipboardLocker clipboardLock( clipboard );
if( !clipboardLock )
return nullptr;
if( clipboard->IsSupported( wxDF_TEXT ) )
{
wxTextDataObject data;
wxTheClipboard->GetData( data );
clipboard->GetData( data );
result = data.GetText();
}
wxTheClipboard->Close();
}
try
{
item = PCB_IO::Parse( result );
@ -221,7 +226,11 @@ BOARD_ITEM* CLIPBOARD_IO::Parse()
void CLIPBOARD_IO::Save( const wxString& aFileName, BOARD* aBoard,
const PROPERTIES* aProperties )
{
LOCALE_IO toggle; // toggles on, then off, the C locale.
auto clipboard = wxTheClipboard;
wxClipboardLocker clipboardLock( clipboard );
if( !clipboardLock )
return;
init( aProperties );
@ -241,13 +250,9 @@ void CLIPBOARD_IO::Save( const wxString& aFileName, BOARD* aBoard,
m_out->Print( 0, ")\n" );
if( wxTheClipboard->Open() )
{
wxTheClipboard->SetData( new wxTextDataObject(
clipboard->SetData( new wxTextDataObject(
wxString( m_formatter.GetString().c_str(), wxConvUTF8 ) ) );
wxTheClipboard->Close();
}
clipboard->Flush();
}
@ -256,19 +261,20 @@ BOARD* CLIPBOARD_IO::Load( const wxString& aFileName,
{
std::string result;
if( wxTheClipboard->Open() )
{
if( wxTheClipboard->IsSupported( wxDF_TEXT ) )
auto clipboard = wxTheClipboard;
wxClipboardLocker clipboardLock( clipboard );
if( !clipboardLock )
return nullptr;
if( clipboard->IsSupported( wxDF_TEXT ) )
{
wxTextDataObject data;
wxTheClipboard->GetData( data );
clipboard->GetData( data );
result = data.GetText().mb_str();
}
wxTheClipboard->Close();
}
STRING_LINE_READER reader(result, wxT( "clipboard" ) );
init( aProperties );