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
This commit is contained in:
parent
6e77176d76
commit
964d6ebc06
|
@ -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(
|
||||
wxString( m_formatter.GetString().c_str(), wxConvUTF8 ) ) );
|
||||
wxTheClipboard->Close();
|
||||
}
|
||||
|
||||
clipboard->SetData( new wxTextDataObject(
|
||||
wxString( m_formatter.GetString().c_str(), wxConvUTF8 ) ) );
|
||||
|
||||
clipboard->Flush();
|
||||
}
|
||||
|
||||
|
||||
|
@ -193,16 +196,18 @@ BOARD_ITEM* CLIPBOARD_IO::Parse()
|
|||
BOARD_ITEM* item;
|
||||
wxString result;
|
||||
|
||||
if( wxTheClipboard->Open() )
|
||||
{
|
||||
if( wxTheClipboard->IsSupported( wxDF_TEXT ) )
|
||||
{
|
||||
wxTextDataObject data;
|
||||
wxTheClipboard->GetData( data );
|
||||
result = data.GetText();
|
||||
}
|
||||
auto clipboard = wxTheClipboard;
|
||||
wxClipboardLocker clipboardLock( clipboard );
|
||||
|
||||
wxTheClipboard->Close();
|
||||
if( !clipboardLock )
|
||||
return nullptr;
|
||||
|
||||
|
||||
if( clipboard->IsSupported( wxDF_TEXT ) )
|
||||
{
|
||||
wxTextDataObject data;
|
||||
clipboard->GetData( data );
|
||||
result = data.GetText();
|
||||
}
|
||||
|
||||
try
|
||||
|
@ -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(
|
||||
wxString( m_formatter.GetString().c_str(), wxConvUTF8 ) ) );
|
||||
wxTheClipboard->Close();
|
||||
}
|
||||
|
||||
clipboard->SetData( new wxTextDataObject(
|
||||
wxString( m_formatter.GetString().c_str(), wxConvUTF8 ) ) );
|
||||
clipboard->Flush();
|
||||
}
|
||||
|
||||
|
||||
|
@ -256,17 +261,18 @@ BOARD* CLIPBOARD_IO::Load( const wxString& aFileName,
|
|||
{
|
||||
std::string result;
|
||||
|
||||
if( wxTheClipboard->Open() )
|
||||
auto clipboard = wxTheClipboard;
|
||||
wxClipboardLocker clipboardLock( clipboard );
|
||||
|
||||
if( !clipboardLock )
|
||||
return nullptr;
|
||||
|
||||
if( clipboard->IsSupported( wxDF_TEXT ) )
|
||||
{
|
||||
if( wxTheClipboard->IsSupported( wxDF_TEXT ) )
|
||||
{
|
||||
wxTextDataObject data;
|
||||
wxTheClipboard->GetData( data );
|
||||
wxTextDataObject data;
|
||||
clipboard->GetData( data );
|
||||
|
||||
result = data.GetText().mb_str();
|
||||
}
|
||||
|
||||
wxTheClipboard->Close();
|
||||
result = data.GetText().mb_str();
|
||||
}
|
||||
|
||||
STRING_LINE_READER reader(result, wxT( "clipboard" ) );
|
||||
|
|
Loading…
Reference in New Issue