Show all symbol libraries by default.

Also fixes an issue where the plugin wasn't getting reset if the
library type was changed.
This commit is contained in:
Jeff Young 2020-07-17 18:32:16 +01:00
parent e7e1d5140e
commit 33480ecad1
7 changed files with 83 additions and 15 deletions

View File

@ -56,6 +56,8 @@ void FP_LIB_TABLE_ROW::SetType( const wxString& aType )
if( IO_MGR::PCB_FILE_T( -1 ) == type )
type = IO_MGR::KICAD_SEXP;
plugin.release();
}

View File

@ -91,9 +91,12 @@ wxString AddFileExtListToFilter( const std::vector<std::string>& aExts )
wxString files_filter = " (";
// Add extensions to the info message:
for( const auto& ext : aExts )
for( const std::string& ext : aExts )
{
files_filter << " *." << ext;
if( files_filter.length() > 2 )
files_filter << "; ";
files_filter << "*." << ext;
}
files_filter << ")|*.";
@ -190,6 +193,12 @@ wxString LegacySymbolLibFileWildcard()
}
wxString AllSymbolLibFilesWildcard()
{
return _( "All KiCad symbol library files" ) + AddFileExtListToFilter( { "kicad_sym", "lib" } );
}
wxString ProjectFileWildcard()
{
return _( "KiCad project files" ) + AddFileExtListToFilter( { "kicad_pro" } );

View File

@ -397,6 +397,39 @@ bool PANEL_SYM_LIB_TABLE::verifyTables()
}
}
for( SYMBOL_LIB_TABLE* table : { global_model(), project_model() } )
{
for( unsigned int r = 0; r < table->GetCount(); ++r )
{
SYMBOL_LIB_TABLE_ROW& row = dynamic_cast<SYMBOL_LIB_TABLE_ROW&>( table->At( r ) );
if( !row.GetIsEnabled() )
continue;
try
{
if( row.Refresh() )
{
if( table == global_model() )
m_parent->m_GlobalTableChanged = true;
else
m_parent->m_ProjectTableChanged = true;
}
}
catch( const IO_ERROR& ioe )
{
wxString msg = wxString::Format( _( "Symbol library \"%s\" failed to load.\n %s" ),
row.GetNickName(),
ioe.What() );
wxMessageDialog errdlg( this, msg, _( "Error Loading Library" ) );
errdlg.ShowModal();
return false;
}
}
}
return true;
}
@ -410,12 +443,11 @@ void PANEL_SYM_LIB_TABLE::pageChangedHandler( wxAuiNotebookEvent& event )
void PANEL_SYM_LIB_TABLE::browseLibrariesHandler( wxCommandEvent& event )
{
wxString wildcards = KiCadSymbolLibFileWildcard();
wxString wildcards = AllSymbolLibFilesWildcard()
+ "|" + KiCadSymbolLibFileWildcard()
+ "|" + LegacySymbolLibFileWildcard();
wildcards += "|" + LegacySymbolLibFileWildcard();
wxFileDialog dlg( this, _( "Select Library" ), m_lastBrowseDir,
wxEmptyString, wildcards,
wxFileDialog dlg( this, _( "Select Library" ), m_lastBrowseDir, wxEmptyString, wildcards,
wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE );
auto result = dlg.ShowModal();
@ -847,8 +879,7 @@ void InvokeSchEditSymbolLibTable( KIWAY* aKiway, wxWindow *aParent )
if( libEditor )
{
// Check if the currently selected symbol library been removed or disabled.
if( !currentLib.empty()
&& !projectTable->HasLibrary( currentLib, true ) )
if( !currentLib.empty() && !projectTable->HasLibrary( currentLib, true ) )
{
libEditor->SetCurLib( wxEmptyString );
libEditor->emptyScreen();

View File

@ -66,6 +66,23 @@ void SYMBOL_LIB_TABLE_ROW::SetType( const wxString& aType )
if( SCH_IO_MGR::SCH_FILE_T( -1 ) == type )
type = SCH_IO_MGR::SCH_LEGACY;
plugin.release();
}
bool SYMBOL_LIB_TABLE_ROW::Refresh()
{
if( !plugin )
{
wxArrayString dummyList;
plugin.set( SCH_IO_MGR::FindPlugin( type ) );
plugin->EnumerateSymbolLib( dummyList, GetFullURI( true ), GetProperties() );
return true;
}
return false;
}

View File

@ -75,6 +75,13 @@ public:
*/
void SetType( const wxString& aType ) override;
/**
* Attempt to reload the library.
* @return true if a reload was required.
* @throws IO_ERROR if the reload was unsuccessful.
*/
bool Refresh();
protected:
SYMBOL_LIB_TABLE_ROW( const SYMBOL_LIB_TABLE_ROW& aRow ) :
LIB_TABLE_ROW( aRow ),

View File

@ -95,7 +95,7 @@ void SYMBOL_TREE_SYNCHRONIZING_ADAPTER::Sync( bool aForce,
it = deleteLibrary( it );
continue;
}
else if( m_libMgr->GetLibraryHash( name ) != m_libHashes[name] )
else if( aForce || m_libMgr->GetLibraryHash( name ) != m_libHashes[name] )
{
updateLibrary( *(LIB_TREE_NODE_LIB*) it->get() );
}
@ -159,7 +159,8 @@ void SYMBOL_TREE_SYNCHRONIZING_ADAPTER::updateLibrary( LIB_TREE_NODE_LIB& aLibNo
for( auto nodeIt = aLibNode.m_Children.begin(); nodeIt != aLibNode.m_Children.end(); /**/ )
{
auto aliasIt = std::find_if( aliases.begin(), aliases.end(),
[&] ( const LIB_PART* a ) {
[&] ( const LIB_PART* a )
{
return a->GetName() == (*nodeIt)->m_Name;
} );

View File

@ -178,6 +178,7 @@ extern wxString PageLayoutDescrFileWildcard();
extern wxString SchematicSymbolFileWildcard();
extern wxString KiCadSymbolLibFileWildcard();
extern wxString LegacySymbolLibFileWildcard();
extern wxString AllSymbolLibFilesWildcard();
extern wxString ProjectFileWildcard();
extern wxString LegacyProjectFileWildcard();
extern wxString AllProjectFilesWildcard();