Passing a string to LIBRARY_TABLE's c'tor doesn't do what you think it does.

Also fixes nested tables being deleted out from under
the dialog.

Also fixes a bug where PANEL_DESIGN_BLOCK_LIB_TABLE
had fallen behind the the other two.
This commit is contained in:
Jeff Young
2026-01-20 13:18:46 +00:00
parent a8fcc466cd
commit f4e025596b
12 changed files with 47 additions and 33 deletions
@@ -245,10 +245,10 @@ protected:
void openTable( const LIBRARY_TABLE_ROW& aRow ) override
{
wxString uri = LIBRARY_MANAGER::ExpandURI( aRow.URI(), Pgm().GetSettingsManager().Prj() );
auto nestedTable = std::make_unique<LIBRARY_TABLE>( uri, LIBRARY_TABLE_SCOPE::GLOBAL );
wxFileName fn( LIBRARY_MANAGER::ExpandURI( aRow.URI(), Pgm().GetSettingsManager().Prj() ) );
std::shared_ptr<LIBRARY_TABLE> child = std::make_shared<LIBRARY_TABLE>( fn, LIBRARY_TABLE_SCOPE::GLOBAL );
m_panel->AddTable( nestedTable.get(), aRow.Nickname(), true );
m_panel->OpenTable( child, aRow.Nickname() );
}
wxString getTablePreamble() override
@@ -261,7 +261,7 @@ protected:
};
void PANEL_DESIGN_BLOCK_LIB_TABLE::OpenTable( LIBRARY_TABLE* aTable, const wxString& aTitle )
void PANEL_DESIGN_BLOCK_LIB_TABLE::OpenTable( const std::shared_ptr<LIBRARY_TABLE>& aTable, const wxString& aTitle )
{
for( int ii = 2; ii < (int) m_notebook->GetPageCount(); ++ii )
{
@@ -276,7 +276,8 @@ void PANEL_DESIGN_BLOCK_LIB_TABLE::OpenTable( LIBRARY_TABLE* aTable, const wxStr
}
}
AddTable( aTable, aTitle, true );
m_nestedTables.push_back( aTable );
AddTable( aTable.get(), aTitle, true );
// Something is pretty fishy with wxAuiNotebook::ChangeSelection(); on Mac at least it
// results in a re-entrant call where the second call is one page behind.
@@ -43,7 +43,7 @@ public:
bool TransferDataFromWindow() override;
void AddTable( LIBRARY_TABLE* table, const wxString& aTitle, bool aClosable );
void OpenTable( LIBRARY_TABLE* table, const wxString& aTitle );
void OpenTable( const std::shared_ptr<LIBRARY_TABLE>& table, const wxString& aTitle );
private:
/**
@@ -84,6 +84,8 @@ private:
wxString m_lastProjectLibDir; //< Transient (unsaved) last browsed folder when adding a
// project level library.
std::vector<std::shared_ptr<LIBRARY_TABLE>> m_nestedTables;
std::map<DESIGN_BLOCK_IO_MGR::DESIGN_BLOCK_FILE_T, IO_BASE::IO_FILE_DESC> m_supportedDesignBlockFiles;
};
+1 -1
View File
@@ -284,7 +284,7 @@ void LIB_TABLE_GRID_TRICKS::paste_text( const wxString& cb_text )
{
// paste the LIB_TABLE_ROWs of s-expr, starting at column 0 regardless of current cursor column.
if( LIBRARY_TABLE tempTable( cb_text, tbl->Table().Scope() ); tempTable.IsOk() )
if( LIBRARY_TABLE tempTable( true, cb_text, tbl->Table().Scope() ); tempTable.IsOk() )
{
std::ranges::copy( tempTable.Rows(),
std::inserter( tbl->Table().Rows(), tbl->Table().Rows().begin() ) );
+2 -2
View File
@@ -83,8 +83,8 @@ void LIB_TABLE_NOTEBOOK_PANEL::AddTable( wxAuiNotebook* aNotebook, const wxStrin
bool LIB_TABLE_NOTEBOOK_PANEL::TableModified()
{
wxFileName uri = GetModel()->Table().Path();
std::unique_ptr<LIBRARY_TABLE> sourceTable = std::make_unique<LIBRARY_TABLE>( uri, LIBRARY_TABLE_SCOPE::GLOBAL );
wxFileName file( GetModel()->Table().Path() );
std::unique_ptr<LIBRARY_TABLE> sourceTable = std::make_unique<LIBRARY_TABLE>( file, LIBRARY_TABLE_SCOPE::GLOBAL );
return GetModel()->Table() != *sourceTable;
}
+2 -2
View File
@@ -82,7 +82,7 @@ void LIBRARY_MANAGER::loadTables( const wxString& aTablePath, LIBRARY_TABLE_SCOP
if( fn.IsFileReadable() )
{
auto table = std::make_unique<LIBRARY_TABLE>( fn, aScope );
std::unique_ptr<LIBRARY_TABLE> table = std::make_unique<LIBRARY_TABLE>( fn, aScope );
wxCHECK2( table->Type() == type, continue );
aTarget[type] = std::move( table );
loadNestedTables( *aTarget[type] );
@@ -99,7 +99,7 @@ void LIBRARY_MANAGER::loadNestedTables( LIBRARY_TABLE& aRootTable )
{
std::unordered_set<wxString> seenTables;
std::function<void(LIBRARY_TABLE&)> processOneTable =
std::function<void( LIBRARY_TABLE& )> processOneTable =
[&]( LIBRARY_TABLE& aTable )
{
seenTables.insert( aTable.Path() );
+11 -8
View File
@@ -57,15 +57,15 @@ LIBRARY_TABLE::LIBRARY_TABLE( const wxFileName &aPath, LIBRARY_TABLE_SCOPE aScop
{
LIBRARY_TABLE_PARSER parser;
wxFileName file( aPath );
WX_FILENAME::ResolvePossibleSymlinks( file );
m_path = file.GetAbsolutePath();
wxFileName fn( aPath );
WX_FILENAME::ResolvePossibleSymlinks( fn );
m_path = fn.GetAbsolutePath();
if( !file.FileExists() )
if( !fn.FileExists() )
{
m_ok = false;
m_errorDescription = wxString::Format( _( "The library table path '%s' does not exist" ),
file.GetFullPath() );
fn.GetFullPath() );
return;
}
@@ -83,14 +83,17 @@ LIBRARY_TABLE::LIBRARY_TABLE( const wxFileName &aPath, LIBRARY_TABLE_SCOPE aScop
}
LIBRARY_TABLE::LIBRARY_TABLE( const wxString &aBuffer, LIBRARY_TABLE_SCOPE aScope ) :
/**
* Note: @param aFromClipboard isn't actually used, but might keep people from calling this with a string
* filepath, which isn't going to do what they expected.
*/
LIBRARY_TABLE::LIBRARY_TABLE( bool aFromClipboard, const wxString &aBuffer, LIBRARY_TABLE_SCOPE aScope ) :
m_path( wxEmptyString ),
m_scope( aScope )
{
LIBRARY_TABLE_PARSER parser;
tl::expected<LIBRARY_TABLE_IR, LIBRARY_PARSE_ERROR> ir =
parser.ParseBuffer( aBuffer.ToStdString() );
tl::expected<LIBRARY_TABLE_IR, LIBRARY_PARSE_ERROR> ir = parser.ParseBuffer( aBuffer.ToStdString() );
if( ir.has_value() )
{
+6 -5
View File
@@ -189,10 +189,10 @@ protected:
void openTable( const LIBRARY_TABLE_ROW& aRow ) override
{
wxFileName file( LIBRARY_MANAGER::ExpandURI( aRow.URI(), Pgm().GetSettingsManager().Prj() ) );
auto nestedTable = std::make_unique<LIBRARY_TABLE>( file, LIBRARY_TABLE_SCOPE::GLOBAL );
wxFileName fn( LIBRARY_MANAGER::ExpandURI( aRow.URI(), Pgm().GetSettingsManager().Prj() ) );
std::shared_ptr<LIBRARY_TABLE> child = std::make_shared<LIBRARY_TABLE>( fn, LIBRARY_TABLE_SCOPE::GLOBAL );
m_panel->OpenTable( nestedTable.get(), aRow.Nickname() );
m_panel->OpenTable( child, aRow.Nickname() );
}
wxString getTablePreamble() override
@@ -210,7 +210,7 @@ protected:
};
void PANEL_SYM_LIB_TABLE::OpenTable( LIBRARY_TABLE* aTable, const wxString& aTitle )
void PANEL_SYM_LIB_TABLE::OpenTable( const std::shared_ptr<LIBRARY_TABLE>& aTable, const wxString& aTitle )
{
for( int ii = 2; ii < (int) m_notebook->GetPageCount(); ++ii )
{
@@ -225,7 +225,8 @@ void PANEL_SYM_LIB_TABLE::OpenTable( LIBRARY_TABLE* aTable, const wxString& aTit
}
}
AddTable( aTable, aTitle, true );
m_nestedTables.push_back( aTable );
AddTable( aTable.get(), aTitle, true );
// Something is pretty fishy with wxAuiNotebook::ChangeSelection(); on Mac at least it
// results in a re-entrant call where the second call is one page behind.
+3 -1
View File
@@ -45,7 +45,7 @@ public:
bool TransferDataFromWindow() override;
void AddTable( LIBRARY_TABLE* table, const wxString& aTitle, bool aClosable );
void OpenTable( LIBRARY_TABLE* table, const wxString& aTitle );
void OpenTable( const std::shared_ptr<LIBRARY_TABLE>& table, const wxString& aTitle );
private:
/**
@@ -89,6 +89,8 @@ private:
wxString m_lastProjectLibDir; //< Transient (unsaved) last browsed folder when adding a
// project level library.
std::vector<std::shared_ptr<LIBRARY_TABLE>> m_nestedTables;
std::map<SCH_IO_MGR::SCH_FILE_T, IO_BASE::IO_FILE_DESC> m_supportedSymFiles;
};
+1 -1
View File
@@ -380,7 +380,7 @@ bool SCH_EDIT_FRAME::LoadSheetFromFile( SCH_SHEET* aSheet, SCH_SHEET_PATH* aCurr
}
wxFileName symLibTableFn( fileName.GetPath(), FILEEXT::SymbolLibraryTableFileName );
LIBRARY_TABLE table( symLibTableFn.GetFullPath(), LIBRARY_TABLE_SCOPE::PROJECT );
LIBRARY_TABLE table( symLibTableFn, LIBRARY_TABLE_SCOPE::PROJECT );
// If there are any new or duplicate libraries, check to see if it's possible that
// there could be any missing libraries that would cause broken symbol library links.
+3 -1
View File
@@ -140,10 +140,12 @@ public:
/**
* Creates a library table from parsed text
* @param aFromClipboard isn't actually used, but might keep people from calling this with a string
* filepath, which isn't going to do what they expected.
* @param aBuffer is a string containing data to parse
* @param aScope is the scope of this table (is it global or part of a project)
*/
LIBRARY_TABLE( const wxString &aBuffer, LIBRARY_TABLE_SCOPE aScope );
LIBRARY_TABLE( bool aFromClipboard, const wxString &aBuffer, LIBRARY_TABLE_SCOPE aScope );
~LIBRARY_TABLE() = default;
+6 -5
View File
@@ -179,10 +179,10 @@ protected:
void openTable( const LIBRARY_TABLE_ROW& aRow ) override
{
wxFileName uri = LIBRARY_MANAGER::ExpandURI( aRow.URI(), Pgm().GetSettingsManager().Prj() );
auto nestedTable = std::make_unique<LIBRARY_TABLE>( uri, LIBRARY_TABLE_SCOPE::GLOBAL );
wxFileName fn( LIBRARY_MANAGER::ExpandURI( aRow.URI(), Pgm().GetSettingsManager().Prj() ) );
std::shared_ptr<LIBRARY_TABLE> child = std::make_shared<LIBRARY_TABLE>( fn, LIBRARY_TABLE_SCOPE::GLOBAL );
m_panel->OpenTable( nestedTable.get(), aRow.Nickname() );
m_panel->OpenTable( child, aRow.Nickname() );
}
wxString getTablePreamble() override
@@ -195,7 +195,7 @@ protected:
};
void PANEL_FP_LIB_TABLE::OpenTable( LIBRARY_TABLE* aTable, const wxString& aTitle )
void PANEL_FP_LIB_TABLE::OpenTable( const std::shared_ptr<LIBRARY_TABLE>& aTable, const wxString& aTitle )
{
for( int ii = 2; ii < (int) m_notebook->GetPageCount(); ++ii )
{
@@ -210,7 +210,8 @@ void PANEL_FP_LIB_TABLE::OpenTable( LIBRARY_TABLE* aTable, const wxString& aTitl
}
}
AddTable( aTable, aTitle, true );
m_nestedTables.push_back( aTable );
AddTable( aTable.get(), aTitle, true );
// Something is pretty fishy with wxAuiNotebook::ChangeSelection(); on Mac at least it
// results in a re-entrant call where the second call is one page behind.
+3 -1
View File
@@ -43,7 +43,7 @@ public:
bool TransferDataFromWindow() override;
void AddTable( LIBRARY_TABLE* table, const wxString& aTitle, bool aClosable );
void OpenTable( LIBRARY_TABLE* table, const wxString& aTitle );
void OpenTable( const std::shared_ptr<LIBRARY_TABLE>& table, const wxString& aTitle );
private:
/**
@@ -87,5 +87,7 @@ private:
wxString m_lastProjectLibDir; //< Transient (unsaved) last browsed folder when adding a
// project level library.
std::vector<std::shared_ptr<LIBRARY_TABLE>> m_nestedTables;
std::map<PCB_IO_MGR::PCB_FILE_T, IO_BASE::IO_FILE_DESC> m_supportedFpFiles;
};