Remove and re-add saved-as libraries when Syncing tree.

Also removes the aForce parameter as it was always true anyway.

Fixes https://gitlab.com/kicad/code/kicad/issues/7357
This commit is contained in:
Jeff Young 2021-01-31 22:58:34 +00:00
parent 8567739a7a
commit bbb8173b61
8 changed files with 40 additions and 47 deletions

View File

@ -62,8 +62,8 @@
SCH_SCREEN::SCH_SCREEN( EDA_ITEM* aParent ) :
BASE_SCREEN( aParent, SCH_SCREEN_T ),
m_paper( wxT( "A4" ) ),
m_fileFormatVersionAtLoad( 0 )
m_fileFormatVersionAtLoad( 0 ),
m_paper( wxT( "A4" ) )
{
m_modification_sync = 0;
m_refCount = 0;

View File

@ -900,7 +900,7 @@ wxString SYMBOL_EDIT_FRAME::getTargetLib() const
}
void SYMBOL_EDIT_FRAME::SyncLibraries( bool aShowProgress )
void SYMBOL_EDIT_FRAME::SyncLibraries( bool aShowProgress, const wxString& aForceRefresh )
{
LIB_ID selected;
@ -912,15 +912,19 @@ void SYMBOL_EDIT_FRAME::SyncLibraries( bool aShowProgress )
APP_PROGRESS_DIALOG 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 ) );
} );
m_libMgr->Sync( aForceRefresh,
[&]( int progress, int max, const wxString& libName )
{
progressDlg.Update( progress,
wxString::Format( _( "Loading library '%s'" ), libName ) );
} );
}
else
{
m_libMgr->Sync( true );
m_libMgr->Sync( aForceRefresh,
[&]( int progress, int max, const wxString& libName )
{
} );
}
if( m_treePane )
@ -1355,9 +1359,8 @@ bool SYMBOL_EDIT_FRAME::addLibTableEntry( const wxString& aLibFile, TABLE_SCOPE
}
catch( const IO_ERROR& ioe )
{
wxString msg;
msg.Printf( _( "Error saving %s symbol library table." ),
( aScope == GLOBAL_LIB_TABLE ) ? _( "global" ) : _( "project" ) );
wxString msg = aScope == GLOBAL_LIB_TABLE ? _( "Error saving global library table." )
: _( "Error saving project library table." );
wxMessageDialog dlg( this, msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
dlg.SetExtendedMessage( ioe.What() );
@ -1411,9 +1414,8 @@ bool SYMBOL_EDIT_FRAME::replaceLibTableEntry( const wxString& aLibNickname,
}
catch( const IO_ERROR& ioe )
{
wxString msg;
msg.Printf( _( "Error saving %s symbol library table." ),
( isGlobalTable ) ? _( "global" ) : _( "project" ) );
wxString msg = isGlobalTable ? _( "Error saving global library table." )
: _( "Error saving project library table." );
wxMessageDialog dlg( this, msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
dlg.SetExtendedMessage( ioe.What() );

View File

@ -292,7 +292,7 @@ public:
* Synchronize the library manager to the symbol library table, and then the symbol tree
* to the library manager. Optionally displays a progress dialog.
*/
void SyncLibraries( bool aShowProgress );
void SyncLibraries( bool aShowProgress, const wxString& aForceRefresh = wxEmptyString );
/**
* Filter, sort, and redisplay the library tree.

View File

@ -553,6 +553,7 @@ void SYMBOL_EDIT_FRAME::SaveLibraryAs()
m_treePane->GetLibTree()->RefreshLibTree();
}
void SYMBOL_EDIT_FRAME::SaveSymbolAs()
{
wxCHECK( getTargetLibId().IsValid(), /* void */ );
@ -1033,11 +1034,13 @@ bool SYMBOL_EDIT_FRAME::saveLibrary( const wxString& aLibrary, bool aNewFile )
{
bool resyncLibTree = false;
wxString originalLibNickname = getTargetLib();
wxString forceRefresh;
switch( type )
{
case SAVE_AS_HELPER::SAH_TYPE::REPLACE_TABLE_ENTRY:
resyncLibTree = replaceLibTableEntry( originalLibNickname, fn.GetFullPath() );
forceRefresh = originalLibNickname;
break;
case SAVE_AS_HELPER::SAH_TYPE::ADD_GLOBAL_TABLE_ENTRY:
@ -1056,7 +1059,7 @@ bool SYMBOL_EDIT_FRAME::saveLibrary( const wxString& aLibrary, bool aNewFile )
if( resyncLibTree )
{
FreezeSearchTree();
SyncLibraries( true );
SyncLibraries( true, forceRefresh );
ThawSearchTree();
}
}

View File

@ -45,18 +45,13 @@ SYMBOL_LIBRARY_MANAGER::SYMBOL_LIBRARY_MANAGER( SYMBOL_EDIT_FRAME& aFrame ) :
}
void SYMBOL_LIBRARY_MANAGER::Sync( bool aForce,
void SYMBOL_LIBRARY_MANAGER::Sync( const wxString& aForceRefresh,
std::function<void( int, int, const wxString& )> aProgressCallback )
{
m_logger.Activate();
{
int libTableHash = symTable()->GetModifyHash();
if( aForce || m_syncHash != libTableHash )
{
getAdapter()->Sync( aForce, aProgressCallback );
m_syncHash = libTableHash;
}
getAdapter()->Sync( aForceRefresh, aProgressCallback );
m_syncHash = symTable()->GetModifyHash();
}
m_logger.Deactivate();
}

View File

@ -105,11 +105,8 @@ public:
/**
* Updates the #SYMBOL_LIBRARY_MANAGER data to synchronize with Symbol Library Table.
*/
void Sync( bool aForce = false,
std::function<void( int, int, const wxString& )> aProgressCallback
= []( int, int, const wxString& )
{
} );
void Sync( const wxString& aForceRefresh,
std::function<void( int, int, const wxString& )> aProgressCallback );
int GetHash() const;

View File

@ -63,17 +63,12 @@ bool SYMBOL_TREE_SYNCHRONIZING_ADAPTER::IsContainer( const wxDataViewItem& aItem
#define PROGRESS_INTERVAL_MILLIS 120
void SYMBOL_TREE_SYNCHRONIZING_ADAPTER::Sync( bool aForce,
std::function<void( int, int, const wxString& )> aProgressCallback )
void SYMBOL_TREE_SYNCHRONIZING_ADAPTER::Sync( const wxString& aForceRefresh,
std::function<void( int, int, const wxString& )> aProgressCallback )
{
wxLongLong nextUpdate = wxGetUTCTimeMillis() + (PROGRESS_INTERVAL_MILLIS / 2);
int libMgrHash = m_libMgr->GetHash();
if( !aForce && m_lastSyncHash == libMgrHash )
return;
m_lastSyncHash = libMgrHash;
m_lastSyncHash = m_libMgr->GetHash();
int i = 0, max = GetLibrariesCount();
// Process already stored libraries
@ -87,18 +82,19 @@ void SYMBOL_TREE_SYNCHRONIZING_ADAPTER::Sync( bool aForce,
nextUpdate = wxGetUTCTimeMillis() + PROGRESS_INTERVAL_MILLIS;
}
// There is a bug in SYMBOL_LIBRARY_MANAGER::LibraryExists() that uses the buffered modified
// libraries before the symbol library table which prevents the library from being
// removed from the tree control.
// There is a bug in SYMBOL_LIBRARY_MANAGER::LibraryExists() that uses the buffered
// modified libraries before the symbol library table which prevents the library from
// being removed from the tree control.
if( !m_libMgr->LibraryExists( name, true )
|| !m_frame->Prj().SchSymbolLibTable()->HasLibrary( name, true )
|| ( m_frame->Prj().SchSymbolLibTable()->FindRow( name, true ) !=
m_frame->Prj().SchSymbolLibTable()->FindRow( name, false ) ) )
|| !m_frame->Prj().SchSymbolLibTable()->HasLibrary( name, true )
|| m_frame->Prj().SchSymbolLibTable()->FindRow( name, true ) !=
m_frame->Prj().SchSymbolLibTable()->FindRow( name, false )
|| name == aForceRefresh )
{
it = deleteLibrary( it );
continue;
}
else if( aForce || m_libMgr->GetLibraryHash( name ) != m_libHashes[name] )
else
{
updateLibrary( *(LIB_TREE_NODE_LIB*) it->get() );
}

View File

@ -41,8 +41,8 @@ public:
bool IsContainer( const wxDataViewItem& aItem ) const override;
void Sync( bool aForce = false,
std::function<void( int, int, const wxString&)> aProgressCallback = [](int, int, const wxString&){} );
void Sync( const wxString& aForceRefresh,
std::function<void( int, int, const wxString&)> aProgressCallback );
int GetLibrariesCount() const override;