From 18a76d3a87d9d9d8aee24457753b21ad76052272 Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Sun, 8 Sep 2019 01:00:15 +0200 Subject: [PATCH] Manually put the UNIT_BINDER text on the primary selection clipboard The OnKillFocus handler of the UNIT_BINDER replaces the text in the control with the evaluated string, which removes the selection. To get the original text on the primary selection clipboard, we must add it ourselves. Fixes: lp:1794623 * https://bugs.launchpad.net/kicad/+bug/1794623 --- common/widgets/unit_binder.cpp | 23 +++++++++++++++++++++++ include/widgets/unit_binder.h | 4 ++++ 2 files changed, 27 insertions(+) diff --git a/common/widgets/unit_binder.cpp b/common/widgets/unit_binder.cpp index 4e7b7abd29..8504997b46 100644 --- a/common/widgets/unit_binder.cpp +++ b/common/widgets/unit_binder.cpp @@ -22,6 +22,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ +#include #include #include #include @@ -46,6 +47,8 @@ UNIT_BINDER::UNIT_BINDER( EDA_DRAW_FRAME* aParent, m_useMils = aUseMils; m_allowEval = allowEval && dynamic_cast( m_value ); m_needsEval = false; + m_selStart = 0; + m_selEnd = 0; auto textEntry = dynamic_cast( m_value ); if( textEntry ) @@ -79,7 +82,10 @@ void UNIT_BINDER::onSetFocus( wxFocusEvent& aEvent ) wxString oldStr = m_eval.OriginalText(); if( oldStr.length() ) + { textEntry->SetValue( oldStr ); + textEntry->SetSelection( m_selStart, m_selEnd ); + } m_needsEval = true; } @@ -95,8 +101,25 @@ void UNIT_BINDER::onKillFocus( wxFocusEvent& aEvent ) if( m_allowEval && textEntry ) { if( m_eval.Process( textEntry->GetValue() ) ) + { + textEntry->GetSelection( &m_selStart, &m_selEnd ); + wxString sel = textEntry->GetStringSelection(); + textEntry->ChangeValue( m_eval.Result() ); +#ifdef __WXGTK__ + // Manually copy the selected text to the primary selection clipboard + if( wxTheClipboard->Open() ) + { + bool clipTarget = wxTheClipboard->IsUsingPrimarySelection(); + wxTheClipboard->UsePrimarySelection( true ); + wxTheClipboard->SetData( new wxTextDataObject( sel ) ); + wxTheClipboard->UsePrimarySelection( clipTarget ); + wxTheClipboard->Close(); + } +#endif + } + m_needsEval = false; } diff --git a/include/widgets/unit_binder.h b/include/widgets/unit_binder.h index 4cf935b9da..ba4b80b3ce 100644 --- a/include/widgets/unit_binder.h +++ b/include/widgets/unit_binder.h @@ -140,6 +140,10 @@ protected: NUMERIC_EVALUATOR m_eval; bool m_allowEval; bool m_needsEval; + + ///> Selection start and end of the original text + long m_selStart; + long m_selEnd; }; #endif /* __UNIT_BINDER_H_ */