From 9885b7a4eff72287de34f0ef78eac1fc3fb193af Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 9 Dec 2023 17:54:40 +0000 Subject: [PATCH] Don't require more clicks than necessary to communicate intent. Fixes https://gitlab.com/kicad/code/kicad/-/issues/16261 --- eeschema/dialogs/dialog_sim_model.cpp | 70 ++++++++++++++++------ eeschema/dialogs/dialog_sim_model.h | 1 + eeschema/dialogs/dialog_sim_model_base.cpp | 2 + eeschema/dialogs/dialog_sim_model_base.fbp | 1 + eeschema/dialogs/dialog_sim_model_base.h | 1 + 5 files changed, 56 insertions(+), 19 deletions(-) diff --git a/eeschema/dialogs/dialog_sim_model.cpp b/eeschema/dialogs/dialog_sim_model.cpp index 549c78fc8c..3b8885f9fd 100644 --- a/eeschema/dialogs/dialog_sim_model.cpp +++ b/eeschema/dialogs/dialog_sim_model.cpp @@ -481,7 +481,7 @@ void DIALOG_SIM_MODEL::updateBuiltinModelWidgets( SIM_MODEL* m_deviceChoice->Clear(); m_deviceTypeChoice->Clear(); - if( m_rbBuiltinModel->GetValue() ) + if( !m_rbLibraryModel->GetValue() ) { for( SIM_MODEL::DEVICE_T deviceType : SIM_MODEL::DEVICE_T_ITERATOR() ) { @@ -1071,30 +1071,43 @@ int DIALOG_SIM_MODEL::getModelPinIndex( const wxString& aMode template void DIALOG_SIM_MODEL::onRadioButton( wxCommandEvent& aEvent ) { - bool fromLibrary = m_rbLibraryModel->GetValue(); - - m_pathLabel->Enable( fromLibrary ); - m_libraryPathText->Enable( fromLibrary ); - m_browseButton->Enable( fromLibrary ); - m_modelNameLabel->Enable( fromLibrary ); - m_modelNameChoice->Enable( fromLibrary ); - m_pinLabel->Enable( fromLibrary ); - m_pinCombobox->Enable( fromLibrary ); - m_differentialCheckbox->Enable( fromLibrary ); - m_pinModelLabel->Enable( fromLibrary ); - m_pinModelCombobox->Enable( fromLibrary ); - m_waveformLabel->Enable( fromLibrary ); - m_waveformChoice->Enable( fromLibrary ); - - m_deviceLabel->Enable( !fromLibrary ); - m_deviceChoice->Enable( !fromLibrary ); - m_deviceTypeLabel->Enable( !fromLibrary ); + if( m_rbLibraryModel->GetValue() ) + { + m_deviceLabel->Enable( false ); + m_deviceChoice->Enable( false ); + m_deviceTypeLabel->Enable( false ); + } + else if( m_rbBuiltinModel->GetValue() ) + { + m_pathLabel->Enable( false ); + m_libraryPathText->Enable( false ); + m_browseButton->Enable( false ); + m_modelNameLabel->Enable( false ); + m_modelNameChoice->Enable( false ); + m_pinLabel->Enable( false ); + m_pinCombobox->Enable( false ); + m_differentialCheckbox->Enable( false ); + m_pinModelLabel->Enable( false ); + m_pinModelCombobox->Enable( false ); + m_waveformLabel->Enable( false ); + m_waveformChoice->Enable( false ); + } m_prevModel = nullptr; // Ensure the Model panel will be rebuild after updating other params. updateWidgets(); } +template +void DIALOG_SIM_MODEL::onLibrarayPathText( wxCommandEvent& aEvent ) +{ + m_rbLibraryModel->SetValue( true ); + m_deviceLabel->Enable( false ); + m_deviceChoice->Enable( false ); + m_deviceTypeLabel->Enable( false ); +} + + template void DIALOG_SIM_MODEL::onLibraryPathTextEnter( wxCommandEvent& aEvent ) { @@ -1144,6 +1157,11 @@ void DIALOG_SIM_MODEL::onBrowseButtonClick( wxCommandEvent& a if( dlg.ShowModal() == wxID_CANCEL ) return; + m_rbLibraryModel->SetValue( true ); + m_deviceLabel->Enable( false ); + m_deviceChoice->Enable( false ); + m_deviceTypeLabel->Enable( false ); + path = dlg.GetPath(); wxFileName fn( path ); @@ -1249,6 +1267,20 @@ void DIALOG_SIM_MODEL::onDifferentialCheckbox( wxCommandEvent template void DIALOG_SIM_MODEL::onDeviceTypeChoice( wxCommandEvent& aEvent ) { + m_rbBuiltinModel->SetValue( true ); + m_pathLabel->Enable( false ); + m_libraryPathText->Enable( false ); + m_browseButton->Enable( false ); + m_modelNameLabel->Enable( false ); + m_modelNameChoice->Enable( false ); + m_pinLabel->Enable( false ); + m_pinCombobox->Enable( false ); + m_differentialCheckbox->Enable( false ); + m_pinModelLabel->Enable( false ); + m_pinModelCombobox->Enable( false ); + m_waveformLabel->Enable( false ); + m_waveformChoice->Enable( false ); + for( SIM_MODEL::DEVICE_T deviceType : SIM_MODEL::DEVICE_T_ITERATOR() ) { if( SIM_MODEL::DeviceInfo( deviceType ).description == m_deviceChoice->GetStringSelection() ) diff --git a/eeschema/dialogs/dialog_sim_model.h b/eeschema/dialogs/dialog_sim_model.h index f5ff94d03f..ed9ba19269 100644 --- a/eeschema/dialogs/dialog_sim_model.h +++ b/eeschema/dialogs/dialog_sim_model.h @@ -93,6 +93,7 @@ private: int getModelPinIndex( const wxString& aModelPinString ) const; void onRadioButton( wxCommandEvent& aEvent ) override; + void onLibrarayPathText( wxCommandEvent& aEvent ) override; void onLibraryPathTextEnter( wxCommandEvent& aEvent ) override; void onLibraryPathTextKillFocus( wxFocusEvent& aEvent ) override; void onBrowseButtonClick( wxCommandEvent& aEvent ) override; diff --git a/eeschema/dialogs/dialog_sim_model_base.cpp b/eeschema/dialogs/dialog_sim_model_base.cpp index 1e886c19bf..0b5d7b4534 100644 --- a/eeschema/dialogs/dialog_sim_model_base.cpp +++ b/eeschema/dialogs/dialog_sim_model_base.cpp @@ -330,6 +330,7 @@ DIALOG_SIM_MODEL_BASE::DIALOG_SIM_MODEL_BASE( wxWindow* parent, wxWindowID id, c m_rbLibraryModel->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 ); + m_libraryPathText->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_SIM_MODEL_BASE::onLibrarayPathText ), NULL, this ); m_libraryPathText->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_SIM_MODEL_BASE::onLibraryPathTextEnter ), NULL, this ); m_browseButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SIM_MODEL_BASE::onBrowseButtonClick ), NULL, this ); m_browseButton->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_SIM_MODEL_BASE::onBrowseButtonUpdate ), NULL, this ); @@ -366,6 +367,7 @@ DIALOG_SIM_MODEL_BASE::~DIALOG_SIM_MODEL_BASE() m_rbLibraryModel->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 ); + m_libraryPathText->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_SIM_MODEL_BASE::onLibrarayPathText ), NULL, this ); m_libraryPathText->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_SIM_MODEL_BASE::onLibraryPathTextEnter ), NULL, this ); m_browseButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SIM_MODEL_BASE::onBrowseButtonClick ), NULL, this ); m_browseButton->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_SIM_MODEL_BASE::onBrowseButtonUpdate ), NULL, this ); diff --git a/eeschema/dialogs/dialog_sim_model_base.fbp b/eeschema/dialogs/dialog_sim_model_base.fbp index aa0a3e0686..e1ec299aaa 100644 --- a/eeschema/dialogs/dialog_sim_model_base.fbp +++ b/eeschema/dialogs/dialog_sim_model_base.fbp @@ -407,6 +407,7 @@ onLibraryPathTextKillFocus + onLibrarayPathText onLibraryPathTextEnter diff --git a/eeschema/dialogs/dialog_sim_model_base.h b/eeschema/dialogs/dialog_sim_model_base.h index 6d06fe30cb..0311180cc6 100644 --- a/eeschema/dialogs/dialog_sim_model_base.h +++ b/eeschema/dialogs/dialog_sim_model_base.h @@ -91,6 +91,7 @@ class DIALOG_SIM_MODEL_BASE : public DIALOG_SHIM virtual void onRadioButton( wxCommandEvent& event ) { event.Skip(); } virtual void onLibraryPathLabelUpdate( wxUpdateUIEvent& event ) { event.Skip(); } virtual void onLibraryPathTextKillFocus( wxFocusEvent& event ) { event.Skip(); } + virtual void onLibrarayPathText( wxCommandEvent& event ) { event.Skip(); } virtual void onLibraryPathTextEnter( wxCommandEvent& event ) { event.Skip(); } virtual void onBrowseButtonClick( wxCommandEvent& event ) { event.Skip(); } virtual void onBrowseButtonUpdate( wxUpdateUIEvent& event ) { event.Skip(); }