Library Editor: progress dialog when loading libraries

This commit is contained in:
Maciej Suminski 2017-11-22 12:06:17 +01:00
parent efaf429a71
commit 8b0041bf9a
9 changed files with 57 additions and 9 deletions

View File

@ -233,6 +233,14 @@ public:
*/
int GetComponentsCount() const;
/**
* Return the number of libraries loaded in the tree.
*/
virtual int GetLibrariesCount() const
{
return m_tree.Children.size();
}
/**
* Returns tree item corresponding to part.
*

View File

@ -42,13 +42,13 @@ LIB_MANAGER::LIB_MANAGER( LIB_EDIT_FRAME& aFrame )
}
void LIB_MANAGER::Sync( bool aForce )
void LIB_MANAGER::Sync( bool aForce, std::function<void(int, int, const wxString&)> aProgressCallback )
{
int libTableHash = m_symbolTable->GetModifyHash();
if( aForce || m_syncHash != libTableHash )
{
getAdapter()->Sync( aForce );
getAdapter()->Sync( aForce, aProgressCallback );
m_syncHash = libTableHash;
}
}

View File

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

View File

@ -80,20 +80,21 @@ bool LIB_MANAGER_ADAPTER::IsContainer( const wxDataViewItem& aItem ) const
}
void LIB_MANAGER_ADAPTER::Sync( bool aForce )
void LIB_MANAGER_ADAPTER::Sync( bool aForce, std::function<void(int, int, const wxString&)> aProgressCallback )
{
wxBusyCursor cursor;
int libMgrHash = m_libMgr->GetHash();
if( !aForce && m_lastSyncHash == libMgrHash )
return;
m_lastSyncHash = libMgrHash;
int i = 0, max = GetLibrariesCount();
// Process already stored libraries
for( auto it = m_tree.Children.begin(); it != m_tree.Children.end(); /* iteration inside */ )
{
const wxString& name = it->get()->Name;
aProgressCallback( i++, max, name );
if( !m_libMgr->LibraryExists( name ) )
{
@ -112,13 +113,30 @@ void LIB_MANAGER_ADAPTER::Sync( bool aForce )
for( const auto& libName : m_libMgr->GetLibraryNames() )
{
if( m_libHashes.count( libName ) == 0 )
{
aProgressCallback( i++, max, libName );
AddLibrary( libName );
}
}
finishUpdate();
}
int LIB_MANAGER_ADAPTER::GetLibrariesCount() const
{
int count = CMP_TREE_MODEL_ADAPTER_BASE::GetLibrariesCount();
for( const auto& libName : m_libMgr->GetLibraryNames() )
{
if( m_libHashes.count( libName ) == 0 )
++count;
}
return count;
}
void LIB_MANAGER_ADAPTER::updateLibrary( CMP_TREE_NODE_LIB& aLibNode )
{
if( m_libHashes.count( aLibNode.Name ) == 0 )

View File

@ -45,7 +45,10 @@ public:
void UpdateLibrary( const wxString& aLibraryName );
void Sync( bool aForce = false );
void Sync( bool aForce = false, std::function<void(int, int, const wxString&)> aProgressCallback
= [](int, int, const wxString&){} );
int GetLibrariesCount() const override;
protected:
void updateLibrary( CMP_TREE_NODE_LIB& aLibNode );

View File

@ -61,6 +61,7 @@
#include <wildcards_and_files_ext.h>
#include <menus_helpers.h>
#include <wx/progdlg.h>
wxString LIB_EDIT_FRAME:: m_aliasName;
@ -483,7 +484,7 @@ void LIB_EDIT_FRAME::OnToggleSearchTree( wxCommandEvent& event )
void LIB_EDIT_FRAME::OnEditSymbolLibTable( wxCommandEvent& aEvent )
{
SCH_BASE_FRAME::OnEditSymbolLibTable( aEvent );
m_libMgr->Sync( true );
SyncLibraries();
m_treePane->Refresh();
}
@ -1613,6 +1614,19 @@ 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() )

View File

@ -692,6 +692,11 @@ public:
*/
SYMBOL_LIB_TABLE* SelectSymLibTable();
/**
* Synchronize the library manager and the symbol library table. Displays a progress dialog.
*/
void SyncLibraries();
private:
///> Helper screen used when no part is loaded
SCH_SCREEN* m_dummyScreen;

View File

@ -38,7 +38,7 @@ CMP_TREE_PANE::CMP_TREE_PANE( LIB_EDIT_FRAME* aParent, LIB_MANAGER* aLibMgr )
// Create widgets
wxBoxSizer* boxSizer = new wxBoxSizer( wxVERTICAL );
m_libMgr->Sync();
m_libEditFrame->SyncLibraries();
m_tree = new COMPONENT_TREE( this, &SYMBOL_LIB_TABLE::GetGlobalLibTable(),
m_libMgr->GetAdapter(), COMPONENT_TREE::SEARCH );

View File

@ -46,7 +46,6 @@ public:
}
protected:
void onSymLibTableSelected( wxCommandEvent& aEvent );
void onComponentSelected( wxCommandEvent& aEvent );
LIB_EDIT_FRAME* m_libEditFrame;