Properties: improve handling of unit binders
This commit is contained in:
parent
199e25f3f3
commit
5e352d2a66
|
@ -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<wxTextCtrl*>( 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<wxTextCtrl*>( 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;
|
||||
}
|
||||
|
|
|
@ -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<wxTextEntry*>( m_valueCtrl ) );
|
||||
|
@ -342,16 +343,22 @@ void UNIT_BINDER::SetValue( const wxString& aValue )
|
|||
wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( m_valueCtrl );
|
||||
wxStaticText* staticText = dynamic_cast<wxStaticText*>( 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<wxTextEntry*>( m_valueCtrl );
|
||||
wxStaticText* staticText = dynamic_cast<wxStaticText*>( 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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue