Library Editor: progress dialog when loading libraries
This commit is contained in:
parent
efaf429a71
commit
8b0041bf9a
|
@ -233,6 +233,14 @@ public:
|
||||||
*/
|
*/
|
||||||
int GetComponentsCount() const;
|
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.
|
* Returns tree item corresponding to part.
|
||||||
*
|
*
|
||||||
|
|
|
@ -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();
|
int libTableHash = m_symbolTable->GetModifyHash();
|
||||||
|
|
||||||
if( aForce || m_syncHash != libTableHash )
|
if( aForce || m_syncHash != libTableHash )
|
||||||
{
|
{
|
||||||
getAdapter()->Sync( aForce );
|
getAdapter()->Sync( aForce, aProgressCallback );
|
||||||
m_syncHash = libTableHash;
|
m_syncHash = libTableHash;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,8 @@ public:
|
||||||
/**
|
/**
|
||||||
* Updates the LIB_MANAGER data to synchronize with Symbol Library Table.
|
* 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;
|
int GetHash() const;
|
||||||
|
|
||||||
|
|
|
@ -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();
|
int libMgrHash = m_libMgr->GetHash();
|
||||||
|
|
||||||
if( !aForce && m_lastSyncHash == libMgrHash )
|
if( !aForce && m_lastSyncHash == libMgrHash )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_lastSyncHash = libMgrHash;
|
m_lastSyncHash = libMgrHash;
|
||||||
|
int i = 0, max = GetLibrariesCount();
|
||||||
|
|
||||||
// Process already stored libraries
|
// Process already stored libraries
|
||||||
for( auto it = m_tree.Children.begin(); it != m_tree.Children.end(); /* iteration inside */ )
|
for( auto it = m_tree.Children.begin(); it != m_tree.Children.end(); /* iteration inside */ )
|
||||||
{
|
{
|
||||||
const wxString& name = it->get()->Name;
|
const wxString& name = it->get()->Name;
|
||||||
|
aProgressCallback( i++, max, name );
|
||||||
|
|
||||||
if( !m_libMgr->LibraryExists( name ) )
|
if( !m_libMgr->LibraryExists( name ) )
|
||||||
{
|
{
|
||||||
|
@ -112,13 +113,30 @@ void LIB_MANAGER_ADAPTER::Sync( bool aForce )
|
||||||
for( const auto& libName : m_libMgr->GetLibraryNames() )
|
for( const auto& libName : m_libMgr->GetLibraryNames() )
|
||||||
{
|
{
|
||||||
if( m_libHashes.count( libName ) == 0 )
|
if( m_libHashes.count( libName ) == 0 )
|
||||||
|
{
|
||||||
|
aProgressCallback( i++, max, libName );
|
||||||
AddLibrary( libName );
|
AddLibrary( libName );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
finishUpdate();
|
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 )
|
void LIB_MANAGER_ADAPTER::updateLibrary( CMP_TREE_NODE_LIB& aLibNode )
|
||||||
{
|
{
|
||||||
if( m_libHashes.count( aLibNode.Name ) == 0 )
|
if( m_libHashes.count( aLibNode.Name ) == 0 )
|
||||||
|
|
|
@ -45,7 +45,10 @@ public:
|
||||||
|
|
||||||
void UpdateLibrary( const wxString& aLibraryName );
|
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:
|
protected:
|
||||||
void updateLibrary( CMP_TREE_NODE_LIB& aLibNode );
|
void updateLibrary( CMP_TREE_NODE_LIB& aLibNode );
|
||||||
|
|
|
@ -61,6 +61,7 @@
|
||||||
#include <wildcards_and_files_ext.h>
|
#include <wildcards_and_files_ext.h>
|
||||||
|
|
||||||
#include <menus_helpers.h>
|
#include <menus_helpers.h>
|
||||||
|
#include <wx/progdlg.h>
|
||||||
|
|
||||||
|
|
||||||
wxString LIB_EDIT_FRAME:: m_aliasName;
|
wxString LIB_EDIT_FRAME:: m_aliasName;
|
||||||
|
@ -483,7 +484,7 @@ void LIB_EDIT_FRAME::OnToggleSearchTree( wxCommandEvent& event )
|
||||||
void LIB_EDIT_FRAME::OnEditSymbolLibTable( wxCommandEvent& aEvent )
|
void LIB_EDIT_FRAME::OnEditSymbolLibTable( wxCommandEvent& aEvent )
|
||||||
{
|
{
|
||||||
SCH_BASE_FRAME::OnEditSymbolLibTable( aEvent );
|
SCH_BASE_FRAME::OnEditSymbolLibTable( aEvent );
|
||||||
m_libMgr->Sync( true );
|
SyncLibraries();
|
||||||
m_treePane->Refresh();
|
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 )
|
bool LIB_EDIT_FRAME::backupFile( const wxFileName& aOriginalFile, const wxString& aBackupExt )
|
||||||
{
|
{
|
||||||
if( aOriginalFile.FileExists() )
|
if( aOriginalFile.FileExists() )
|
||||||
|
|
|
@ -692,6 +692,11 @@ public:
|
||||||
*/
|
*/
|
||||||
SYMBOL_LIB_TABLE* SelectSymLibTable();
|
SYMBOL_LIB_TABLE* SelectSymLibTable();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Synchronize the library manager and the symbol library table. Displays a progress dialog.
|
||||||
|
*/
|
||||||
|
void SyncLibraries();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
///> Helper screen used when no part is loaded
|
///> Helper screen used when no part is loaded
|
||||||
SCH_SCREEN* m_dummyScreen;
|
SCH_SCREEN* m_dummyScreen;
|
||||||
|
|
|
@ -38,7 +38,7 @@ CMP_TREE_PANE::CMP_TREE_PANE( LIB_EDIT_FRAME* aParent, LIB_MANAGER* aLibMgr )
|
||||||
// Create widgets
|
// Create widgets
|
||||||
wxBoxSizer* boxSizer = new wxBoxSizer( wxVERTICAL );
|
wxBoxSizer* boxSizer = new wxBoxSizer( wxVERTICAL );
|
||||||
|
|
||||||
m_libMgr->Sync();
|
m_libEditFrame->SyncLibraries();
|
||||||
m_tree = new COMPONENT_TREE( this, &SYMBOL_LIB_TABLE::GetGlobalLibTable(),
|
m_tree = new COMPONENT_TREE( this, &SYMBOL_LIB_TABLE::GetGlobalLibTable(),
|
||||||
m_libMgr->GetAdapter(), COMPONENT_TREE::SEARCH );
|
m_libMgr->GetAdapter(), COMPONENT_TREE::SEARCH );
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,6 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void onSymLibTableSelected( wxCommandEvent& aEvent );
|
|
||||||
void onComponentSelected( wxCommandEvent& aEvent );
|
void onComponentSelected( wxCommandEvent& aEvent );
|
||||||
|
|
||||||
LIB_EDIT_FRAME* m_libEditFrame;
|
LIB_EDIT_FRAME* m_libEditFrame;
|
||||||
|
|
Loading…
Reference in New Issue