From bbb8173b61bdc125ec973a6745b364b9723352a7 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 31 Jan 2021 22:58:34 +0000 Subject: [PATCH] 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 --- eeschema/sch_screen.cpp | 4 +-- eeschema/symbol_editor/symbol_edit_frame.cpp | 28 ++++++++++--------- eeschema/symbol_editor/symbol_edit_frame.h | 2 +- eeschema/symbol_editor/symbol_editor.cpp | 5 +++- .../symbol_editor/symbol_library_manager.cpp | 11 ++------ .../symbol_editor/symbol_library_manager.h | 7 ++--- .../symbol_tree_synchronizing_adapter.cpp | 26 ++++++++--------- eeschema/symbol_tree_synchronizing_adapter.h | 4 +-- 8 files changed, 40 insertions(+), 47 deletions(-) diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp index c67d56bca3..b7a1ea5891 100644 --- a/eeschema/sch_screen.cpp +++ b/eeschema/sch_screen.cpp @@ -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; diff --git a/eeschema/symbol_editor/symbol_edit_frame.cpp b/eeschema/symbol_editor/symbol_edit_frame.cpp index 536a78f739..69da158cd1 100644 --- a/eeschema/symbol_editor/symbol_edit_frame.cpp +++ b/eeschema/symbol_editor/symbol_edit_frame.cpp @@ -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() ); diff --git a/eeschema/symbol_editor/symbol_edit_frame.h b/eeschema/symbol_editor/symbol_edit_frame.h index 893d66f33f..72a303ac08 100644 --- a/eeschema/symbol_editor/symbol_edit_frame.h +++ b/eeschema/symbol_editor/symbol_edit_frame.h @@ -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. diff --git a/eeschema/symbol_editor/symbol_editor.cpp b/eeschema/symbol_editor/symbol_editor.cpp index b677b1fbf0..e7b8ea50ab 100644 --- a/eeschema/symbol_editor/symbol_editor.cpp +++ b/eeschema/symbol_editor/symbol_editor.cpp @@ -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(); } } diff --git a/eeschema/symbol_editor/symbol_library_manager.cpp b/eeschema/symbol_editor/symbol_library_manager.cpp index f8eb9afdd1..8f68ba9c3f 100644 --- a/eeschema/symbol_editor/symbol_library_manager.cpp +++ b/eeschema/symbol_editor/symbol_library_manager.cpp @@ -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 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(); } diff --git a/eeschema/symbol_editor/symbol_library_manager.h b/eeschema/symbol_editor/symbol_library_manager.h index d14af3aa27..b68c1a22c6 100644 --- a/eeschema/symbol_editor/symbol_library_manager.h +++ b/eeschema/symbol_editor/symbol_library_manager.h @@ -105,11 +105,8 @@ public: /** * Updates the #SYMBOL_LIBRARY_MANAGER data to synchronize with Symbol Library Table. */ - void Sync( bool aForce = false, - std::function aProgressCallback - = []( int, int, const wxString& ) - { - } ); + void Sync( const wxString& aForceRefresh, + std::function aProgressCallback ); int GetHash() const; diff --git a/eeschema/symbol_tree_synchronizing_adapter.cpp b/eeschema/symbol_tree_synchronizing_adapter.cpp index 7728c42ef4..4f3cdaf7e9 100644 --- a/eeschema/symbol_tree_synchronizing_adapter.cpp +++ b/eeschema/symbol_tree_synchronizing_adapter.cpp @@ -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 aProgressCallback ) +void SYMBOL_TREE_SYNCHRONIZING_ADAPTER::Sync( const wxString& aForceRefresh, + std::function 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() ); } diff --git a/eeschema/symbol_tree_synchronizing_adapter.h b/eeschema/symbol_tree_synchronizing_adapter.h index c3689c690c..70a52474e2 100644 --- a/eeschema/symbol_tree_synchronizing_adapter.h +++ b/eeschema/symbol_tree_synchronizing_adapter.h @@ -41,8 +41,8 @@ public: bool IsContainer( const wxDataViewItem& aItem ) const override; - void Sync( bool aForce = false, - std::function aProgressCallback = [](int, int, const wxString&){} ); + void Sync( const wxString& aForceRefresh, + std::function aProgressCallback ); int GetLibrariesCount() const override;