diff --git a/common/properties/pg_editors.cpp b/common/properties/pg_editors.cpp index 9cacfa4ae9..26fd77f0b7 100644 --- a/common/properties/pg_editors.cpp +++ b/common/properties/pg_editors.cpp @@ -74,10 +74,33 @@ wxPGWindowList PG_UNIT_EDITOR::CreateControls( wxPropertyGrid* aPropGrid, wxPGPr } +void PG_UNIT_EDITOR::UpdateControl( wxPGProperty* aProperty, wxWindow* aCtrl ) const +{ + m_unitBinder->ChangeValue( aProperty->GetValueAsString() ); +} + + +bool PG_UNIT_EDITOR::OnEvent( wxPropertyGrid* aPropGrid, wxPGProperty* aProperty, + wxWindow* aCtrl, wxEvent& aEvent ) const +{ + if( aEvent.GetEventType() == wxEVT_LEFT_UP ) + { + if( wxTextCtrl* textCtrl = dynamic_cast( aCtrl ) ) + { + textCtrl->SelectAll(); + return false; + } + } + + return wxPGTextCtrlEditor::OnEvent( aPropGrid, aProperty, aCtrl, aEvent ); +} + + bool PG_UNIT_EDITOR::GetValueFromControl( wxVariant& aVariant, wxPGProperty* aProperty, wxWindow* aCtrl ) const { - wxASSERT( m_unitBinder ); + if( !m_unitBinder ) + return false; wxTextCtrl* textCtrl = dynamic_cast( aCtrl ); wxCHECK_MSG( textCtrl, false, "PG_UNIT_EDITOR requires a text control!" ); @@ -86,7 +109,6 @@ bool PG_UNIT_EDITOR::GetValueFromControl( wxVariant& aVariant, wxPGProperty* aPr if( aProperty->UsesAutoUnspecified() && textVal.empty() ) { aVariant.MakeNull(); - m_unitBinder->SetControl( nullptr ); return true; } @@ -105,7 +127,5 @@ bool PG_UNIT_EDITOR::GetValueFromControl( wxVariant& aVariant, wxPGProperty* aPr if( !changed && aVariant.IsNull() ) changed = true; - m_unitBinder->SetControl( nullptr ); - return changed; } diff --git a/common/widgets/unit_binder.cpp b/common/widgets/unit_binder.cpp index 3cc583977d..ce99ecbdd5 100644 --- a/common/widgets/unit_binder.cpp +++ b/common/widgets/unit_binder.cpp @@ -59,7 +59,8 @@ UNIT_BINDER::UNIT_BINDER( EDA_BASE_FRAME* aParent, const EDA_IU_SCALE& aIUScale, m_precision( 0 ), m_eval( aParent->GetUserUnits() ), m_originTransforms( aParent->GetOriginTransforms() ), - m_coordType( ORIGIN_TRANSFORMS::NOT_A_COORD ) + m_coordType( ORIGIN_TRANSFORMS::NOT_A_COORD ), + m_unitsInValue( false ) { init(); m_allowEval = allowEval && ( !m_valueCtrl || dynamic_cast( m_valueCtrl ) ); @@ -342,16 +343,22 @@ void UNIT_BINDER::SetValue( const wxString& aValue ) wxTextEntry* textEntry = dynamic_cast( m_valueCtrl ); wxStaticText* staticText = dynamic_cast( m_valueCtrl ); + wxString value = aValue; + + if( m_unitsInValue ) + value += wxT( " " ) + EDA_UNIT_UTILS::GetLabel( m_units, m_dataType ); + if( textEntry ) - textEntry->SetValue( aValue ); + textEntry->SetValue( value ); else if( staticText ) - staticText->SetLabel( aValue ); + staticText->SetLabel( value ); if( m_allowEval ) m_eval.Clear(); if( m_unitLabel ) m_unitLabel->SetLabel( EDA_UNIT_UTILS::GetLabel( m_units, m_dataType ) ); + } @@ -394,10 +401,15 @@ void UNIT_BINDER::ChangeValue( const wxString& aValue ) wxTextEntry* textEntry = dynamic_cast( m_valueCtrl ); wxStaticText* staticText = dynamic_cast( m_valueCtrl ); + wxString value = aValue; + + if( m_unitsInValue ) + value += wxT( " " ) + EDA_UNIT_UTILS::GetLabel( m_units, m_dataType ); + if( textEntry ) - textEntry->ChangeValue( aValue ); + textEntry->ChangeValue( value ); else if( staticText ) - staticText->SetLabel( aValue ); + staticText->SetLabel( value ); if( m_allowEval ) m_eval.Clear(); @@ -568,6 +580,7 @@ void UNIT_BINDER::Show( bool aShow, bool aResize ) PROPERTY_EDITOR_UNIT_BINDER::PROPERTY_EDITOR_UNIT_BINDER( EDA_DRAW_FRAME* aParent ) : UNIT_BINDER( aParent, nullptr, nullptr, nullptr, true, false ) { + m_unitsInValue = true; } diff --git a/include/properties/pg_editors.h b/include/properties/pg_editors.h index 34aa62ff61..1208018c17 100644 --- a/include/properties/pg_editors.h +++ b/include/properties/pg_editors.h @@ -45,6 +45,11 @@ public: bool GetValueFromControl( wxVariant& aVariant, wxPGProperty* aProperty, wxWindow* aCtrl ) const override; + void UpdateControl( wxPGProperty* aProperty, wxWindow* aCtrl ) const override; + + bool OnEvent( wxPropertyGrid* aPropGrid, wxPGProperty* aProperty, wxWindow* aCtrl, + wxEvent& aEvent ) const override; + /** * When restarting an editor, the instance of PG_UNIT_EDITOR may be the same * but the referenced frame is different. This re-binds the frame to the editor diff --git a/include/widgets/unit_binder.h b/include/widgets/unit_binder.h index 9b952cffd3..8a656641cf 100644 --- a/include/widgets/unit_binder.h +++ b/include/widgets/unit_binder.h @@ -244,6 +244,8 @@ protected: long m_selStart; ///< Selection start and end of the original text long m_selEnd; + bool m_unitsInValue; ///< Units label should be included in value text + /// A reference to an ORIGIN_TRANSFORMS object ORIGIN_TRANSFORMS& m_originTransforms;