clipboard: re-add limited LOCALE_IO to SaveSelection

JP notes that there is an issue with comma-based decimal locales and the
SaveSelection that is addressed by having a LOCALE_IO call in a limited
block.

This changed the copy timing of the clipboard and the interaction with
KDE Klipper again.  To address this, we isolate the clipboard open call
to the end of the routine and force a round-trip of the clipboard data
before exiting.
This commit is contained in:
Seth Hillbrand 2018-11-22 08:12:41 -08:00
parent d03e82602e
commit 36a69a7d5d
1 changed files with 35 additions and 12 deletions

View File

@ -67,12 +67,6 @@ void CLIPBOARD_IO::SaveSelection( const SELECTION& aSelected )
if( aSelected.Empty() )
return;
auto clipboard = wxTheClipboard;
wxClipboardLocker clipboardLock( clipboard );
if( !clipboardLock || !clipboard->IsOpened() )
return;
if( aSelected.HasReferencePoint() )
refPoint = aSelected.GetReferencePoint();
@ -153,6 +147,8 @@ void CLIPBOARD_IO::SaveSelection( const SELECTION& aSelected )
{
// we will fake being a .kicad_pcb to get the full parser kicking
// This means we also need layers and nets
LOCALE_IO io;
m_formatter.Print( 0, "(kicad_pcb (version %d) (host pcbnew %s)\n",
SEXPR_BOARD_FILE_VERSION, m_formatter.Quotew( GetBuildVersion() ).c_str() );
@ -184,10 +180,27 @@ void CLIPBOARD_IO::SaveSelection( const SELECTION& aSelected )
m_formatter.Print( 0, "\n)" );
}
// These are placed at the end to minimize the open time of the clipboard
auto clipboard = wxTheClipboard;
wxClipboardLocker clipboardLock( clipboard );
if( !clipboardLock || !clipboard->IsOpened() )
return;
clipboard->SetData( new wxTextDataObject(
wxString( m_formatter.GetString().c_str(), wxConvUTF8 ) ) );
clipboard->Flush();
// 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
// such as KDE's Klipper
{
wxTextDataObject data;
clipboard->GetData( data );
( void )data.GetText(); // Keep unused variable
}
}
@ -226,12 +239,6 @@ BOARD_ITEM* CLIPBOARD_IO::Parse()
void CLIPBOARD_IO::Save( const wxString& aFileName, BOARD* aBoard,
const PROPERTIES* aProperties )
{
auto clipboard = wxTheClipboard;
wxClipboardLocker clipboardLock( clipboard );
if( !clipboardLock )
return;
init( aProperties );
m_board = aBoard; // after init()
@ -250,9 +257,25 @@ void CLIPBOARD_IO::Save( const wxString& aFileName, BOARD* aBoard,
m_out->Print( 0, ")\n" );
auto clipboard = wxTheClipboard;
wxClipboardLocker clipboardLock( clipboard );
if( !clipboardLock )
return;
clipboard->SetData( new wxTextDataObject(
wxString( m_formatter.GetString().c_str(), wxConvUTF8 ) ) );
clipboard->Flush();
// 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
// such as KDE's Klipper
{
wxTextDataObject data;
clipboard->GetData( data );
( void )data.GetText(); // Keep unused variable
}
}