From 62561292e907d2dd5232c157da78e749a7ed1ce2 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Thu, 22 Nov 2018 08:12:41 -0800 Subject: [PATCH] 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. (cherry picked from commit 36a69a7d5d8978df38dcec4966d1e3098a229b21) --- pcbnew/kicad_clipboard.cpp | 47 ++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/pcbnew/kicad_clipboard.cpp b/pcbnew/kicad_clipboard.cpp index 113b607e46..ba557b61e6 100644 --- a/pcbnew/kicad_clipboard.cpp +++ b/pcbnew/kicad_clipboard.cpp @@ -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 + } }