From 8619705e4434bec98c5665fdb10626fb8fe62a6b Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 2 Mar 2023 17:50:39 +0000 Subject: [PATCH] Hook up AddField handler to GRID_TRICKS for SCH dialogs. Fixes https://gitlab.com/kicad/code/kicad/issues/git/14153 --- common/grid_tricks.cpp | 1 + eeschema/dialogs/dialog_label_properties.cpp | 12 ++++++++---- eeschema/dialogs/dialog_lib_symbol_properties.cpp | 6 +++++- eeschema/dialogs/dialog_sheet_properties.cpp | 6 +++++- eeschema/dialogs/dialog_symbol_properties.cpp | 6 +++++- eeschema/fields_grid_table.h | 5 +++-- eeschema/sch_validators.cpp | 10 +++++----- 7 files changed, 32 insertions(+), 14 deletions(-) diff --git a/common/grid_tricks.cpp b/common/grid_tricks.cpp index 9661904e26..c6a617cb17 100644 --- a/common/grid_tricks.cpp +++ b/common/grid_tricks.cpp @@ -424,6 +424,7 @@ void GRID_TRICKS::onCharHook( wxKeyEvent& ev ) { wxCommandEvent dummy; m_addHandler( dummy ); + handled = true; } } else if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() == 'V' ) diff --git a/eeschema/dialogs/dialog_label_properties.cpp b/eeschema/dialogs/dialog_label_properties.cpp index cf84c01e42..f9fe4928ee 100644 --- a/eeschema/dialogs/dialog_label_properties.cpp +++ b/eeschema/dialogs/dialog_label_properties.cpp @@ -110,7 +110,11 @@ DIALOG_LABEL_PROPERTIES::DIALOG_LABEL_PROPERTIES( SCH_EDIT_FRAME* aParent, SCH_L m_grid->SetDefaultRowSize( m_grid->GetDefaultRowSize() + 4 ); m_grid->SetTable( m_fields ); - m_grid->PushEventHandler( new FIELDS_GRID_TRICKS( m_grid, this ) ); + m_grid->PushEventHandler( new FIELDS_GRID_TRICKS( m_grid, this, + [&]( wxCommandEvent& aEvent ) + { + OnAddField( aEvent ); + } ) ); m_grid->SetSelectionMode( wxGrid::wxGridSelectRows ); // Show/hide columns according to user's preference @@ -603,7 +607,7 @@ void DIALOG_LABEL_PROPERTIES::OnAddField( wxCommandEvent& event ) if( !m_grid->CommitPendingChanges() ) return; - int fieldID = m_fields->size(); + int fieldID = (int) m_fields->size(); wxString fieldName; if( (int) fieldID == m_currentLabel->GetMandatoryFieldCount() @@ -637,8 +641,8 @@ void DIALOG_LABEL_PROPERTIES::OnAddField( wxCommandEvent& event ) wxGridTableMessage msg( m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 ); m_grid->ProcessTableMessage( msg ); - m_grid->MakeCellVisible( m_fields->size() - 1, 0 ); - m_grid->SetGridCursor( m_fields->size() - 1, fieldName == wxT( "Netclass" ) ? 1 : 0 ); + m_grid->MakeCellVisible( (int) m_fields->size() - 1, 0 ); + m_grid->SetGridCursor( (int) m_fields->size() - 1, 0 ); m_grid->EnableCellEditControl(); m_grid->ShowCellEditControl(); diff --git a/eeschema/dialogs/dialog_lib_symbol_properties.cpp b/eeschema/dialogs/dialog_lib_symbol_properties.cpp index a3e9402e1f..afb195bfff 100644 --- a/eeschema/dialogs/dialog_lib_symbol_properties.cpp +++ b/eeschema/dialogs/dialog_lib_symbol_properties.cpp @@ -65,7 +65,11 @@ DIALOG_LIB_SYMBOL_PROPERTIES::DIALOG_LIB_SYMBOL_PROPERTIES( SYMBOL_EDIT_FRAME* a m_grid->SetDefaultRowSize( m_grid->GetDefaultRowSize() + 4 ); m_fields = new FIELDS_GRID_TABLE( this, aParent, m_grid, m_libEntry ); m_grid->SetTable( m_fields ); - m_grid->PushEventHandler( new FIELDS_GRID_TRICKS( m_grid, this ) ); + m_grid->PushEventHandler( new FIELDS_GRID_TRICKS( m_grid, this, + [&]( wxCommandEvent& aEvent ) + { + OnAddField( aEvent ); + } ) ); m_grid->SetSelectionMode( wxGrid::wxGridSelectRows ); // Show/hide columns according to the user's preference diff --git a/eeschema/dialogs/dialog_sheet_properties.cpp b/eeschema/dialogs/dialog_sheet_properties.cpp index 79b33ae733..04f00a9300 100644 --- a/eeschema/dialogs/dialog_sheet_properties.cpp +++ b/eeschema/dialogs/dialog_sheet_properties.cpp @@ -61,7 +61,11 @@ DIALOG_SHEET_PROPERTIES::DIALOG_SHEET_PROPERTIES( SCH_EDIT_FRAME* aParent, SCH_S m_grid->SetDefaultRowSize( m_grid->GetDefaultRowSize() + 4 ); m_grid->SetTable( m_fields ); - m_grid->PushEventHandler( new FIELDS_GRID_TRICKS( m_grid, this ) ); + m_grid->PushEventHandler( new FIELDS_GRID_TRICKS( m_grid, this, + [&]( wxCommandEvent& aEvent ) + { + OnAddField( aEvent ); + } ) ); m_grid->SetSelectionMode( wxGrid::wxGridSelectRows ); // Show/hide columns according to user's preference diff --git a/eeschema/dialogs/dialog_symbol_properties.cpp b/eeschema/dialogs/dialog_symbol_properties.cpp index e550ca5f11..a7639022b2 100644 --- a/eeschema/dialogs/dialog_symbol_properties.cpp +++ b/eeschema/dialogs/dialog_symbol_properties.cpp @@ -325,7 +325,11 @@ DIALOG_SYMBOL_PROPERTIES::DIALOG_SYMBOL_PROPERTIES( SCH_EDIT_FRAME* aParent, m_pinGrid->SetDefaultRowSize( m_pinGrid->GetDefaultRowSize() + 4 ); m_fieldsGrid->SetTable( m_fields ); - m_fieldsGrid->PushEventHandler( new FIELDS_GRID_TRICKS( m_fieldsGrid, this ) ); + m_fieldsGrid->PushEventHandler( new FIELDS_GRID_TRICKS( m_fieldsGrid, this, + [&]( wxCommandEvent& aEvent ) + { + OnAddField( aEvent ); + } ) ); m_fieldsGrid->SetSelectionMode( wxGrid::wxGridSelectRows ); // Show/hide columns according to user's preference diff --git a/eeschema/fields_grid_table.h b/eeschema/fields_grid_table.h index 37bd4d74ff..74412c4367 100644 --- a/eeschema/fields_grid_table.h +++ b/eeschema/fields_grid_table.h @@ -38,8 +38,9 @@ class SCH_LABEL_BASE; class FIELDS_GRID_TRICKS : public GRID_TRICKS { public: - FIELDS_GRID_TRICKS( WX_GRID* aGrid, DIALOG_SHIM* aDialog ) : - GRID_TRICKS( aGrid ), + FIELDS_GRID_TRICKS( WX_GRID* aGrid, DIALOG_SHIM* aDialog, + std::function aAddHandler ) : + GRID_TRICKS( aGrid, std::move( aAddHandler ) ), m_dlg( aDialog ) {} diff --git a/eeschema/sch_validators.cpp b/eeschema/sch_validators.cpp index 95ec8a69e9..deb9d1275e 100644 --- a/eeschema/sch_validators.cpp +++ b/eeschema/sch_validators.cpp @@ -142,17 +142,17 @@ bool SCH_FIELD_VALIDATOR::Validate( wxWindow* aParent ) { wxArrayString badCharsFound; - for( const wxString& excludeChar : GetExcludes() ) + for( const wxUniCharRef& excludeChar : GetCharExcludes() ) { if( val.Find( excludeChar ) != wxNOT_FOUND ) { - if( excludeChar == wxT( "\r" ) ) + if( excludeChar == '\r' ) badCharsFound.Add( _( "carriage return" ) ); - else if( excludeChar == wxT( "\n" ) ) + else if( excludeChar == '\n' ) badCharsFound.Add( _( "line feed" ) ); - else if( excludeChar == wxT( "\t" ) ) + else if( excludeChar == '\t' ) badCharsFound.Add( _( "tab" ) ); - else if( excludeChar == wxT( " " ) ) + else if( excludeChar == ' ' ) badCharsFound.Add( _( "space" ) ); else badCharsFound.Add( wxString::Format( wxT( "'%s'" ), excludeChar ) );