Library Editor: fixed an assert after canceling add library action
This commit is contained in:
parent
baec127852
commit
d76f7d7bd2
|
@ -527,18 +527,15 @@ wxString LIB_MANAGER::getLibraryName( const wxString& aFilePath )
|
|||
}
|
||||
|
||||
|
||||
bool LIB_MANAGER::addLibrary( const wxString& aFilePath, bool aCreate )
|
||||
bool LIB_MANAGER::addLibrary( const wxString& aFilePath, bool aCreate, SYMBOL_LIB_TABLE* aTable )
|
||||
{
|
||||
wxCHECK( aTable, false );
|
||||
wxString libName = getLibraryName( aFilePath );
|
||||
wxCHECK( !LibraryExists( libName ), false ); // either create or add an existing one
|
||||
|
||||
// Select the target library table (global/project)
|
||||
SYMBOL_LIB_TABLE* libTable = m_frame.SelectSymLibTable();
|
||||
wxCHECK( libTable, false );
|
||||
|
||||
SYMBOL_LIB_TABLE_ROW* libRow = new SYMBOL_LIB_TABLE_ROW( libName, aFilePath,
|
||||
SCH_IO_MGR::ShowType( SCH_IO_MGR::SCH_LEGACY ) );
|
||||
libTable->InsertRow( libRow );
|
||||
aTable->InsertRow( libRow );
|
||||
|
||||
if( aCreate )
|
||||
{
|
||||
|
@ -549,7 +546,7 @@ bool LIB_MANAGER::addLibrary( const wxString& aFilePath, bool aCreate )
|
|||
return false;
|
||||
}
|
||||
|
||||
libTable->CreateSymbolLib( libName );
|
||||
aTable->CreateSymbolLib( libName );
|
||||
}
|
||||
|
||||
getAdapter()->AddLibrary( libName );
|
||||
|
|
|
@ -82,17 +82,17 @@ public:
|
|||
/**
|
||||
* Creates an empty library and adds it to the library table. The library file is created.
|
||||
*/
|
||||
bool CreateLibrary( const wxString& aFilePath )
|
||||
bool CreateLibrary( const wxString& aFilePath, SYMBOL_LIB_TABLE* aTable )
|
||||
{
|
||||
return addLibrary( aFilePath, true );
|
||||
return addLibrary( aFilePath, true, aTable );
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an existing library. The library is added to the library table as well.
|
||||
*/
|
||||
bool AddLibrary( const wxString& aFilePath )
|
||||
bool AddLibrary( const wxString& aFilePath, SYMBOL_LIB_TABLE* aTable )
|
||||
{
|
||||
return addLibrary( aFilePath, false );
|
||||
return addLibrary( aFilePath, false, aTable );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -272,7 +272,7 @@ private:
|
|||
static wxString getLibraryName( const wxString& aFilePath );
|
||||
|
||||
///> Helper function to add either existing or create new library
|
||||
bool addLibrary( const wxString& aFilePath, bool aCreate );
|
||||
bool addLibrary( const wxString& aFilePath, bool aCreate, SYMBOL_LIB_TABLE* aTable );
|
||||
|
||||
SYMBOL_LIB_TABLE* m_symbolTable;
|
||||
|
||||
|
|
|
@ -1522,16 +1522,22 @@ bool LIB_EDIT_FRAME::addLibraryFile( bool aCreateNew )
|
|||
return false;
|
||||
}
|
||||
|
||||
// Select the target library table (global/project)
|
||||
SYMBOL_LIB_TABLE* libTable = selectSymLibTable();
|
||||
|
||||
if( !libTable )
|
||||
return false;
|
||||
|
||||
if( aCreateNew )
|
||||
{
|
||||
res = m_libMgr->CreateLibrary( fileName.GetFullPath() );
|
||||
res = m_libMgr->CreateLibrary( fileName.GetFullPath(), libTable );
|
||||
|
||||
if( !res )
|
||||
if( !res )
|
||||
DisplayError( this, _( "Could not create the library file. Check write permission." ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
res = m_libMgr->AddLibrary( fileName.GetFullPath() );
|
||||
res = m_libMgr->AddLibrary( fileName.GetFullPath(), libTable );
|
||||
|
||||
if( !res )
|
||||
DisplayError( this, _( "Could not open the library file." ) );
|
||||
|
@ -1608,7 +1614,20 @@ wxString LIB_EDIT_FRAME::getTargetLib() const
|
|||
}
|
||||
|
||||
|
||||
SYMBOL_LIB_TABLE* LIB_EDIT_FRAME::SelectSymLibTable()
|
||||
void LIB_EDIT_FRAME::SyncLibraries()
|
||||
{
|
||||
wxBusyCursor cursor;
|
||||
|
||||
wxProgressDialog progressDlg( _( "Loading symbol libraries" ),
|
||||
wxEmptyString, m_libMgr->GetAdapter()->GetLibrariesCount(), this );
|
||||
|
||||
m_libMgr->Sync( true, [&]( int progress, int max, const wxString& libName ) {
|
||||
progressDlg.Update( progress, wxString::Format( _( "Loading library '%s'" ), libName ) );
|
||||
} );
|
||||
}
|
||||
|
||||
|
||||
SYMBOL_LIB_TABLE* LIB_EDIT_FRAME::selectSymLibTable()
|
||||
{
|
||||
wxArrayString libTableNames;
|
||||
libTableNames.Add( _( "Global" ) );
|
||||
|
@ -1625,19 +1644,6 @@ SYMBOL_LIB_TABLE* LIB_EDIT_FRAME::SelectSymLibTable()
|
|||
}
|
||||
|
||||
|
||||
void LIB_EDIT_FRAME::SyncLibraries()
|
||||
{
|
||||
wxBusyCursor cursor;
|
||||
|
||||
wxProgressDialog progressDlg( _( "Loading symbol libraries" ),
|
||||
wxEmptyString, m_libMgr->GetAdapter()->GetLibrariesCount(), this );
|
||||
|
||||
m_libMgr->Sync( true, [&]( int progress, int max, const wxString& libName ) {
|
||||
progressDlg.Update( progress, wxString::Format( _( "Loading library '%s'" ), libName ) );
|
||||
} );
|
||||
}
|
||||
|
||||
|
||||
bool LIB_EDIT_FRAME::backupFile( const wxFileName& aOriginalFile, const wxString& aBackupExt )
|
||||
{
|
||||
if( aOriginalFile.FileExists() )
|
||||
|
|
|
@ -686,12 +686,6 @@ public:
|
|||
*/
|
||||
void SVG_PlotComponent( const wxString& aFullFileName );
|
||||
|
||||
/**
|
||||
* Displays a dialog asking the user to select a symbol library table.
|
||||
* @return Pointer to the selected symbol library table or nullptr if cancelled.
|
||||
*/
|
||||
SYMBOL_LIB_TABLE* SelectSymLibTable();
|
||||
|
||||
/**
|
||||
* Synchronize the library manager and the symbol library table. Displays a progress dialog.
|
||||
*/
|
||||
|
@ -701,6 +695,12 @@ private:
|
|||
///> Helper screen used when no part is loaded
|
||||
SCH_SCREEN* m_dummyScreen;
|
||||
|
||||
/**
|
||||
* Displays a dialog asking the user to select a symbol library table.
|
||||
* @return Pointer to the selected symbol library table or nullptr if cancelled.
|
||||
*/
|
||||
SYMBOL_LIB_TABLE* selectSymLibTable();
|
||||
|
||||
///> Creates a backup copy of a file with requested extension
|
||||
bool backupFile( const wxFileName& aOriginalFile, const wxString& aBackupExt );
|
||||
|
||||
|
|
Loading…
Reference in New Issue