TEXT_CTRL_EVAL: Evaluate expressions when Enter key is pressed

Fixes: lp:1741320
* https://bugs.launchpad.net/kicad/+bug/1741320
This commit is contained in:
Maciej Suminski 2018-01-16 14:52:28 +01:00
parent 947a4839fd
commit d85cf732b6
2 changed files with 20 additions and 3 deletions

View File

@ -27,12 +27,14 @@
TEXT_CTRL_EVAL::TEXT_CTRL_EVAL( wxWindow* aParent, wxWindowID aId, const
wxString& aValue, const wxPoint& aPos, const wxSize& aSize, long aStyle,
const wxValidator& aValidator, const wxString& aName )
: wxTextCtrl( aParent, aId, aValue, aPos, aSize, aStyle, aValidator, aName )
: wxTextCtrl( aParent, aId, aValue, aPos, aSize, aStyle | wxTE_PROCESS_ENTER, aValidator, aName )
{
Connect( wxEVT_SET_FOCUS,
wxFocusEventHandler( TEXT_CTRL_EVAL::onTextFocusGet ), NULL, this );
Connect( wxEVT_KILL_FOCUS,
wxFocusEventHandler( TEXT_CTRL_EVAL::onTextFocusLost ), NULL, this );
Connect( wxEVT_TEXT_ENTER,
wxCommandEventHandler( TEXT_CTRL_EVAL::onTextEnter ), NULL, this );
}
@ -48,12 +50,24 @@ void TEXT_CTRL_EVAL::onTextFocusGet( wxFocusEvent& aEvent )
void TEXT_CTRL_EVAL::onTextFocusLost( wxFocusEvent& aEvent )
{
evaluate();
aEvent.Skip();
}
void TEXT_CTRL_EVAL::onTextEnter( wxCommandEvent& aEvent )
{
evaluate();
aEvent.Skip();
}
void TEXT_CTRL_EVAL::evaluate()
{
if( GetValue().IsEmpty() )
SetValue( "0" );
if( m_eval.process( GetValue().mb_str(), this ) )
SetValue( wxString::FromUTF8( m_eval.result() ) );
aEvent.Skip();
}

View File

@ -53,6 +53,9 @@ protected:
void onTextFocusGet( wxFocusEvent& aEvent );
void onTextFocusLost( wxFocusEvent& aEvent );
void onTextEnter( wxCommandEvent& aEvent );
void evaluate();
};