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