From 2d24edf84fc2f05f56cca163daafcd032d5fcc5b Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Sun, 17 Aug 2025 17:33:16 -0400 Subject: [PATCH] Re-enable library configuration dialog --- common/lib_table_grid_tricks.cpp | 19 +++++++++++-------- eeschema/dialogs/panel_sym_lib_table.cpp | 15 ++++++++++----- eeschema/libraries/symbol_library_adapter.h | 4 ++-- include/lib_table_grid.h | 11 +++++++++-- include/libraries/library_manager.h | 4 ++++ 5 files changed, 36 insertions(+), 17 deletions(-) diff --git a/common/lib_table_grid_tricks.cpp b/common/lib_table_grid_tricks.cpp index 56ed27b953..a6c493af4f 100644 --- a/common/lib_table_grid_tricks.cpp +++ b/common/lib_table_grid_tricks.cpp @@ -19,6 +19,7 @@ #include "lib_table_grid_tricks.h" #include "lib_table_grid.h" +#include #include #include @@ -89,16 +90,18 @@ void LIB_TABLE_GRID_TRICKS::showPopupMenu( wxMenu& menu, wxGridEvent& aEvent ) bool showSettings = false; - // TODO(JE) library tables -#if 0 - if( m_sel_row_count == 1 && tbl->At( m_sel_row_start )->SupportsSettingsDialog() ) + if( LIBRARY_MANAGER_ADAPTER* adapter = tbl->Adapter() ) { - showSettings = true; - menu.Append( LIB_TABLE_GRID_TRICKS_LIBRARY_SETTINGS, - wxString::Format( _( "Library settings for %s..." ), - tbl->GetValue( m_sel_row_start, 2 ) ) ); + wxString nickname = tbl->GetValue( m_sel_row_start, COL_NICKNAME ); + + if( m_sel_row_count == 1 && adapter->SupportsConfigurationDialog( nickname ) ) + { + showSettings = true; + menu.Append( LIB_TABLE_GRID_TRICKS_LIBRARY_SETTINGS, + wxString::Format( _( "Library settings for %s..." ), nickname ) ); + } } -#endif + if( showActivate || showDeactivate || showSetVisible || showUnsetVisible || showSettings ) menu.AppendSeparator(); diff --git a/eeschema/dialogs/panel_sym_lib_table.cpp b/eeschema/dialogs/panel_sym_lib_table.cpp index e0ba0e8cf0..535ac45b91 100644 --- a/eeschema/dialogs/panel_sym_lib_table.cpp +++ b/eeschema/dialogs/panel_sym_lib_table.cpp @@ -93,8 +93,8 @@ class SYMBOL_LIB_TABLE_GRID : public LIB_TABLE_GRID friend class SYMBOL_GRID_TRICKS; public: - SYMBOL_LIB_TABLE_GRID( const LIBRARY_TABLE& aTableToEdit ) : - LIB_TABLE_GRID( aTableToEdit ) + SYMBOL_LIB_TABLE_GRID( const LIBRARY_TABLE& aTableToEdit, SYMBOL_LIBRARY_ADAPTER* aAdapter ) : + LIB_TABLE_GRID( aTableToEdit, aAdapter ) { } @@ -418,9 +418,12 @@ PANEL_SYM_LIB_TABLE::PANEL_SYM_LIB_TABLE( DIALOG_EDIT_LIBRARY_TABLES* aParent, P std::optional table = Pgm().GetLibraryManager().Table( LIBRARY_TABLE_TYPE::SYMBOL, LIBRARY_TABLE_SCOPE::GLOBAL ); wxASSERT( table ); + + SYMBOL_LIBRARY_ADAPTER* adapter = PROJECT_SCH::SymbolLibAdapter( m_project ); + // wxGrid only supports user owned tables if they exist past end of ~wxGrid(), // so make it a grid owned table. - m_global_grid->SetTable( new SYMBOL_LIB_TABLE_GRID( *table.value() ) ); + m_global_grid->SetTable( new SYMBOL_LIB_TABLE_GRID( *table.value(), adapter ) ); // TODO(JE) should use translated string here but type is stored as untranslated string // Maybe type storage needs to be enum? @@ -452,7 +455,7 @@ PANEL_SYM_LIB_TABLE::PANEL_SYM_LIB_TABLE( DIALOG_EDIT_LIBRARY_TABLES* aParent, P if( projectTable ) { - m_project_grid->SetTable( new SYMBOL_LIB_TABLE_GRID( *projectTable.value() ), true ); + m_project_grid->SetTable( new SYMBOL_LIB_TABLE_GRID( *projectTable.value(), adapter ), true ); setupGrid( m_project_grid ); } else @@ -918,7 +921,9 @@ void PANEL_SYM_LIB_TABLE::onReset( wxCommandEvent& event ) LIBRARY_TABLE_SCOPE::GLOBAL ); wxASSERT( newTable ); - m_global_grid->SetTable( new SYMBOL_LIB_TABLE_GRID( *newTable.value() ) ); + SYMBOL_LIBRARY_ADAPTER* adapter = PROJECT_SCH::SymbolLibAdapter( &m_parent->Kiway().Prj() ); + + m_global_grid->SetTable( new SYMBOL_LIB_TABLE_GRID( *newTable.value(), adapter ) ); m_global_grid->PopEventHandler( true ); setupGrid( m_global_grid ); m_parent->m_GlobalTableChanged = true; diff --git a/eeschema/libraries/symbol_library_adapter.h b/eeschema/libraries/symbol_library_adapter.h index 6514f90ac4..4ffe3aee7a 100644 --- a/eeschema/libraries/symbol_library_adapter.h +++ b/eeschema/libraries/symbol_library_adapter.h @@ -77,9 +77,9 @@ public: std::vector GetSubLibraries( const wxString& aNickname ) const; - bool SupportsConfigurationDialog( const wxString& aNickname ) const; + bool SupportsConfigurationDialog( const wxString& aNickname ) const override; - void ShowConfigurationDialog( const wxString& aNickname, wxWindow* aParent ) const; + void ShowConfigurationDialog( const wxString& aNickname, wxWindow* aParent ) const override; enum class SYMBOL_TYPE { diff --git a/include/lib_table_grid.h b/include/lib_table_grid.h index fef97597da..142fd2f3be 100644 --- a/include/lib_table_grid.h +++ b/include/lib_table_grid.h @@ -25,6 +25,7 @@ #include class LIB_TABLE_GRID_TRICKS; +class LIBRARY_MANAGER_ADAPTER; /// The library table grid column order is established by this sequence. enum COL_ORDER @@ -50,8 +51,9 @@ class KICOMMON_API LIB_TABLE_GRID : public wxGridTableBase friend class LIB_TABLE_GRID_TRICKS; public: - LIB_TABLE_GRID( const LIBRARY_TABLE& aTableToEdit ) : - m_table( aTableToEdit ) + LIB_TABLE_GRID( const LIBRARY_TABLE& aTableToEdit, LIBRARY_MANAGER_ADAPTER* aAdapter = nullptr ) : + m_table( aTableToEdit ), + m_adapter( aAdapter ) {} //------------------------------------------------ @@ -92,6 +94,8 @@ public: LIBRARY_TABLE& Table() { return m_table; } + LIBRARY_MANAGER_ADAPTER* Adapter() const { return m_adapter; } + protected: virtual LIBRARY_TABLE_ROW& at( size_t aIndex ); @@ -111,6 +115,9 @@ protected: /// Working copy of a table LIBRARY_TABLE m_table; + + /// Handle to the adapter for the type of table this grid represents (may be null) + LIBRARY_MANAGER_ADAPTER* m_adapter; }; diff --git a/include/libraries/library_manager.h b/include/libraries/library_manager.h index d7d7488c5d..5d1f159d50 100644 --- a/include/libraries/library_manager.h +++ b/include/libraries/library_manager.h @@ -266,6 +266,10 @@ public: /// Return true if the given nickname exists and is not a read-only library virtual bool IsWritable( const wxString& aNickname ) const { return false; } + virtual bool SupportsConfigurationDialog( const wxString& aNickname ) const { return false; } + + virtual void ShowConfigurationDialog( const wxString& aNickname, wxWindow* aParent ) const {}; + protected: virtual std::map& globalLibs() = 0; virtual std::map& globalLibs() const = 0;