diff --git a/eeschema/dialogs/dialog_sim_model.cpp b/eeschema/dialogs/dialog_sim_model.cpp index 90a137081a..5cade2d821 100644 --- a/eeschema/dialogs/dialog_sim_model.cpp +++ b/eeschema/dialogs/dialog_sim_model.cpp @@ -377,12 +377,20 @@ void DIALOG_SIM_MODEL::updateInstanceWidgets() if( curModel().HasPrimaryValue() ) { - m_saveInValueCheckbox->SetLabel( wxString::Format( "Save %s in Value field as \"%s\"", - curModel().GetParam( 0 ).info.description, - curModel().Serde().GenerateValue() ) ); - } + const SIM_MODEL::PARAM& primary = curModel().GetParam( 0 ); - m_saveInValueCheckbox->Show( curModel().HasPrimaryValue() ); + m_saveInValueCheckbox->SetLabel( wxString::Format( _( "Save parameter '%s (%s)' in Value " + "field" ), + primary.info.description, + primary.info.name ) ); + m_saveInValueCheckbox->Enable( true ); + } + else + { + m_saveInValueCheckbox->SetLabel( _( "Save primary parameter in Value field" ) ); + m_saveInValueCheckbox->SetValue( false ); + m_saveInValueCheckbox->Enable( false ); + } } @@ -396,6 +404,7 @@ void DIALOG_SIM_MODEL::updateModelParamsTab() m_paramGridMgr->SetColumnCount( PARAM_COLUMN::END_ ); + m_paramGridMgr->SetColumnTitle( PARAM_COLUMN::DESCRIPTION, _( "Parameter" ) ); m_paramGridMgr->SetColumnTitle( PARAM_COLUMN::UNIT, _( "Unit" ) ); m_paramGridMgr->SetColumnTitle( PARAM_COLUMN::DEFAULT, _( "Default" ) ); m_paramGridMgr->SetColumnTitle( PARAM_COLUMN::TYPE, _( "Type" ) ); @@ -946,6 +955,32 @@ int DIALOG_SIM_MODEL::getModelPinIndex( const wxString& aModelPinString ) con } +template +void DIALOG_SIM_MODEL::onKeyDown( wxKeyEvent& aEvent ) +{ + // Because wxPropertyGrid has special handling for the tab key, wxPropertyGrid::DedicateKey() + // and wxPropertyGrid::AddActionTrigger() don't work for it. So instead we translate it to an + // (up or down) arrow key, which has proper handling (select next or previous property) defined + // by the aforementioned functions. + + if( aEvent.GetKeyCode() == WXK_TAB ) + { + wxWindow* focus = FindFocus(); + wxPropertyGrid* pg = focus ? dynamic_cast( focus->GetParent() ) : nullptr; + + if( pg ) + { + pg->CommitChangesFromEditor(); + + aEvent.m_keyCode = aEvent.ShiftDown() ? WXK_UP : WXK_DOWN; + aEvent.m_shiftDown = false; + } + } + + aEvent.Skip(); +} + + template void DIALOG_SIM_MODEL::onRadioButton( wxCommandEvent& aEvent ) { diff --git a/eeschema/dialogs/dialog_sim_model.h b/eeschema/dialogs/dialog_sim_model.h index e67dffb77c..58213b8d40 100644 --- a/eeschema/dialogs/dialog_sim_model.h +++ b/eeschema/dialogs/dialog_sim_model.h @@ -113,6 +113,7 @@ private: wxString getModelPinString( int aModelPinIndex ) const; int getModelPinIndex( const wxString& aModelPinString ) const; + void onKeyDown( wxKeyEvent& aEvent ) override; void onRadioButton( wxCommandEvent& aEvent ) override; void onLibraryPathTextEnter( wxCommandEvent& aEvent ) override; void onLibraryPathTextKillFocus( wxFocusEvent& aEvent ) override; diff --git a/eeschema/dialogs/dialog_sim_model_base.cpp b/eeschema/dialogs/dialog_sim_model_base.cpp index 5a020362d4..58a32e867e 100644 --- a/eeschema/dialogs/dialog_sim_model_base.cpp +++ b/eeschema/dialogs/dialog_sim_model_base.cpp @@ -193,8 +193,8 @@ DIALOG_SIM_MODEL_BASE::DIALOG_SIM_MODEL_BASE( wxWindow* parent, wxWindowID id, c bSizerMargins->Add( m_notebook4, 1, wxEXPAND|wxTOP, 10 ); - - bSizerMargins->Add( 0, 5, 0, wxEXPAND, 5 ); + m_saveInValueCheckbox = new wxCheckBox( m_modelPanel, wxID_ANY, _("Save {} in Value field as \"{}\""), wxDefaultPosition, wxDefaultSize, 0 ); + bSizerMargins->Add( m_saveInValueCheckbox, 0, wxALL, 6 ); bSizerPanel->Add( bSizerMargins, 1, wxEXPAND, 5 ); @@ -246,11 +246,6 @@ DIALOG_SIM_MODEL_BASE::DIALOG_SIM_MODEL_BASE( wxWindow* parent, wxWindowID id, c bSizer8->Add( m_notebook, 1, wxEXPAND|wxTOP|wxRIGHT|wxLEFT, 5 ); - m_saveInValueCheckbox = new wxCheckBox( this, wxID_ANY, _("Save {} in Value field as \"{}\""), wxDefaultPosition, wxDefaultSize, 0 ); - m_saveInValueCheckbox->Hide(); - - bSizer8->Add( m_saveInValueCheckbox, 0, wxALL, 5 ); - wxBoxSizer* bSizer81; bSizer81 = new wxBoxSizer( wxHORIZONTAL ); @@ -280,6 +275,7 @@ DIALOG_SIM_MODEL_BASE::DIALOG_SIM_MODEL_BASE( wxWindow* parent, wxWindowID id, c this->Centre( wxBOTH ); // Connect Events + this->Connect( wxEVT_KEY_DOWN, wxKeyEventHandler( DIALOG_SIM_MODEL_BASE::onKeyDown ) ); m_useLibraryModelRadioButton->Connect( wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler( DIALOG_SIM_MODEL_BASE::onRadioButton ), NULL, this ); m_pathLabel->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_SIM_MODEL_BASE::onLibraryPathLabelUpdate ), NULL, this ); m_libraryPathText->Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( DIALOG_SIM_MODEL_BASE::onLibraryPathTextKillFocus ), NULL, this ); @@ -312,15 +308,16 @@ DIALOG_SIM_MODEL_BASE::DIALOG_SIM_MODEL_BASE( wxWindow* parent, wxWindowID id, c m_typeChoice->Connect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( DIALOG_SIM_MODEL_BASE::onTypeChoice ), NULL, this ); m_paramGridMgr->Connect( wxEVT_PG_CHANGED, wxPropertyGridEventHandler( DIALOG_SIM_MODEL_BASE::onParamGridChanged ), NULL, this ); m_codePreview->Connect( wxEVT_SET_FOCUS, wxFocusEventHandler( DIALOG_SIM_MODEL_BASE::onCodePreviewSetFocus ), NULL, this ); + m_saveInValueCheckbox->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_SIM_MODEL_BASE::onSaveInValueCheckbox ), NULL, this ); m_pinAssignmentsGrid->Connect( wxEVT_GRID_CELL_CHANGED, wxGridEventHandler( DIALOG_SIM_MODEL_BASE::onPinAssignmentsGridCellChange ), NULL, this ); m_pinAssignmentsGrid->Connect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_SIM_MODEL_BASE::onPinAssignmentsGridSize ), NULL, this ); - m_saveInValueCheckbox->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_SIM_MODEL_BASE::onSaveInValueCheckbox ), NULL, this ); m_excludeCheckbox->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_SIM_MODEL_BASE::onExcludeCheckbox ), NULL, this ); } DIALOG_SIM_MODEL_BASE::~DIALOG_SIM_MODEL_BASE() { // Disconnect Events + this->Disconnect( wxEVT_KEY_DOWN, wxKeyEventHandler( DIALOG_SIM_MODEL_BASE::onKeyDown ) ); m_useLibraryModelRadioButton->Disconnect( wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler( DIALOG_SIM_MODEL_BASE::onRadioButton ), NULL, this ); m_pathLabel->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_SIM_MODEL_BASE::onLibraryPathLabelUpdate ), NULL, this ); m_libraryPathText->Disconnect( wxEVT_KILL_FOCUS, wxFocusEventHandler( DIALOG_SIM_MODEL_BASE::onLibraryPathTextKillFocus ), NULL, this ); @@ -353,9 +350,9 @@ DIALOG_SIM_MODEL_BASE::~DIALOG_SIM_MODEL_BASE() m_typeChoice->Disconnect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( DIALOG_SIM_MODEL_BASE::onTypeChoice ), NULL, this ); m_paramGridMgr->Disconnect( wxEVT_PG_CHANGED, wxPropertyGridEventHandler( DIALOG_SIM_MODEL_BASE::onParamGridChanged ), NULL, this ); m_codePreview->Disconnect( wxEVT_SET_FOCUS, wxFocusEventHandler( DIALOG_SIM_MODEL_BASE::onCodePreviewSetFocus ), NULL, this ); + m_saveInValueCheckbox->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_SIM_MODEL_BASE::onSaveInValueCheckbox ), NULL, this ); m_pinAssignmentsGrid->Disconnect( wxEVT_GRID_CELL_CHANGED, wxGridEventHandler( DIALOG_SIM_MODEL_BASE::onPinAssignmentsGridCellChange ), NULL, this ); m_pinAssignmentsGrid->Disconnect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_SIM_MODEL_BASE::onPinAssignmentsGridSize ), NULL, this ); - m_saveInValueCheckbox->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_SIM_MODEL_BASE::onSaveInValueCheckbox ), NULL, this ); m_excludeCheckbox->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_SIM_MODEL_BASE::onExcludeCheckbox ), NULL, this ); } diff --git a/eeschema/dialogs/dialog_sim_model_base.fbp b/eeschema/dialogs/dialog_sim_model_base.fbp index 326e93683c..88f74f39c0 100644 --- a/eeschema/dialogs/dialog_sim_model_base.fbp +++ b/eeschema/dialogs/dialog_sim_model_base.fbp @@ -56,6 +56,7 @@ + onKeyDown bSizer8 @@ -1652,13 +1653,68 @@ - 5 - wxEXPAND + 6 + wxALL 0 - - 5 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Save {} in Value field as "{}" + + 0 + + + 0 + + 1 + m_saveInValueCheckbox + 1 + + protected - 0 + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + onSaveInValueCheckbox @@ -1821,71 +1877,6 @@ - - 5 - wxALL - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 1 - wxID_ANY - Save {} in Value field as "{}" - - 0 - - - 0 - - 1 - m_saveInValueCheckbox - 1 - - - protected - 1 - - Resizable - 1 - - - ; ; forward_declare - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - - - onSaveInValueCheckbox - - 5 wxEXPAND|wxLEFT diff --git a/eeschema/dialogs/dialog_sim_model_base.h b/eeschema/dialogs/dialog_sim_model_base.h index 3906f19f21..73a782f47d 100644 --- a/eeschema/dialogs/dialog_sim_model_base.h +++ b/eeschema/dialogs/dialog_sim_model_base.h @@ -75,15 +75,16 @@ class DIALOG_SIM_MODEL_BASE : public DIALOG_SHIM wxPropertyGridPage* m_paramGrid; wxPanel* m_codePanel; wxStyledTextCtrl* m_codePreview; + wxCheckBox* m_saveInValueCheckbox; wxPanel* m_pinAssignmentsPanel; WX_GRID* m_pinAssignmentsGrid; - wxCheckBox* m_saveInValueCheckbox; wxCheckBox* m_excludeCheckbox; wxStdDialogButtonSizer* m_sdbSizer1; wxButton* m_sdbSizer1OK; wxButton* m_sdbSizer1Cancel; // Virtual event handlers, override them in your derived class + virtual void onKeyDown( wxKeyEvent& event ) { event.Skip(); } virtual void onRadioButton( wxCommandEvent& event ) { event.Skip(); } virtual void onLibraryPathLabelUpdate( wxUpdateUIEvent& event ) { event.Skip(); } virtual void onLibraryPathTextKillFocus( wxFocusEvent& event ) { event.Skip(); } @@ -111,9 +112,9 @@ class DIALOG_SIM_MODEL_BASE : public DIALOG_SHIM virtual void onTypeChoice( wxCommandEvent& event ) { event.Skip(); } virtual void onParamGridChanged( wxPropertyGridEvent& event ) { event.Skip(); } virtual void onCodePreviewSetFocus( wxFocusEvent& event ) { event.Skip(); } + virtual void onSaveInValueCheckbox( wxCommandEvent& event ) { event.Skip(); } virtual void onPinAssignmentsGridCellChange( wxGridEvent& event ) { event.Skip(); } virtual void onPinAssignmentsGridSize( wxSizeEvent& event ) { event.Skip(); } - virtual void onSaveInValueCheckbox( wxCommandEvent& event ) { event.Skip(); } virtual void onExcludeCheckbox( wxCommandEvent& event ) { event.Skip(); }