28#include <wx/settings.h>
41wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>
46 return wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>( adapter );
53 aParent->GetViewerSettingsBase()->m_LibTree ),
70 return node ? node->
m_Type == LIB_TREE_NODE::TYPE::LIBRARY :
true;
74#define PROGRESS_INTERVAL_MILLIS 120
77 std::function<
void(
int,
int,
const wxString& )> aProgressCallback )
85 for(
auto it =
m_tree.m_Children.begin(); it !=
m_tree.m_Children.end(); )
87 const wxString&
name = it->get()->m_Name;
89 if( wxGetUTCTimeMillis() > nextUpdate )
91 aProgressCallback( i, max,
name );
102 ||
name == aForceRefresh )
121 for(
const wxString& libName :
m_libMgr->GetLibraryNames() )
125 if( wxGetUTCTimeMillis() > nextUpdate )
127 aProgressCallback( i++, max, libName );
150 for(
const wxString& libName :
m_libMgr->GetLibraryNames() )
170 else if( hashIt->second !=
m_libMgr->GetLibraryHash( aLibNode.
m_Name ) )
173 std::list<LIB_SYMBOL*> symbols =
m_libMgr->EnumerateSymbols( aLibNode.
m_Name );
178 auto symbolIt = std::find_if( symbols.begin(), symbols.end(),
181 return a->GetName() == (*nodeIt)->m_LibId.GetLibItemName().wx_str();
184 if( symbolIt != symbols.end() )
189 symbols.erase( symbolIt );
209LIB_TREE_NODE::PTR_VECTOR::iterator
214 return m_tree.m_Children.erase( aLibNodeIt );
223 return wxDataViewItem();
228 unsigned int aCol )
const
232 aVariant = wxEmptyString;
243 node->
m_Name =
m_frame->GetCurSymbol()->GetLibId().GetUniStringLibItemName();
251 if( node->
m_Type == LIB_TREE_NODE::TYPE::LIBRARY )
254 aVariant = aVariant.GetString() +
" *";
256 else if( node->
m_Type == LIB_TREE_NODE::TYPE::ITEM )
259 aVariant = aVariant.GetString() +
" *";
267 if( node->
m_Type == LIB_TREE_NODE::TYPE::LIBRARY )
276 aVariant =
_(
"(failed to load)" ) + wxS(
" " ) + aVariant.GetString();
278 aVariant =
_(
"(read-only)" ) + wxS(
" " ) + aVariant.GetString();
290 if( key == wxT(
"Description" ) )
292 else if( node->
m_Fields.count( key ) )
293 valueStr = node->
m_Fields.at( key );
295 valueStr = wxEmptyString;
297 valueStr.Replace( wxS(
"\n" ), wxS(
" " ) );
299 if( !aVariant.GetString().IsEmpty() )
301 if( !valueStr.IsEmpty() )
302 aVariant = valueStr + wxS(
" - " ) + aVariant.GetString();
315 wxDataViewItemAttr& aAttr )
const
321 wxCHECK( node,
false );
324 if( node->
m_Type == LIB_TREE_NODE::TYPE::LIBRARY && !
m_libMgr->IsLibraryLoaded( node->
m_Name ) )
326 aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
338 case LIB_TREE_NODE::TYPE::LIBRARY:
347 aAttr.SetStrikethrough(
true );
354 case LIB_TREE_NODE::TYPE::ITEM:
364 aAttr.SetStrikethrough(
true );
381 wxCHECK( node,
false );
391 const wxDataViewItem& aItem )
401 wxBoxSizer* mainSizer =
new wxBoxSizer( wxVERTICAL );
402 aParent->SetSizer( mainSizer );
408 wxBoxSizer* panelSizer =
new wxBoxSizer( wxVERTICAL );
409 panel->SetSizer( panelSizer );
414 preview->SetLayoutDirection( wxLayout_LeftToRight );
416 panelSizer->Add( preview, 1, wxEXPAND | wxALL, 1 );
417 mainSizer->Add( panel, 1, wxEXPAND, 0 );
427 wxWindow* previewWindow = wxWindow::FindWindowByName(
c_previewName, aParent );
431 preview->GetCanvas()->SetEvtHandlerEnabled(
false );
432 preview->GetCanvas()->StopDrawing();
static const COLOR4D BLACK
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Symbol library management helper that is specific to the symbol library editor frame.
Define a library symbol object.
const LIB_ID & GetLibId() const override
const wxString & GetDescr() const
Return the description of the library referenced by this row.
LIB_TREE_MODEL_ADAPTER(EDA_BASE_FRAME *aParent, const wxString &aPinnedKey, APP_SETTINGS_BASE::LIB_TREE &aSettingsStruct)
Create the adapter.
LIB_TREE_NODE_ROOT m_tree
static LIB_TREE_NODE * ToNode(wxDataViewItem aItem)
Convert wxDataViewItem -> #SYM_TREE_NODE.
static wxDataViewItem ToItem(const LIB_TREE_NODE *aNode)
Convert #SYM_TREE_NODE -> wxDataViewItem.
static const wxString GetPinningSymbol()
@ NAME_COL
Library or library item name column.
std::map< unsigned, wxString > m_colIdxMap
virtual int GetLibrariesCount() const
Return the number of libraries loaded in the tree.
wxDataViewCtrl * m_widget
std::vector< wxString > m_shownColumns
LIB_TREE_NODE_LIBRARY & DoAddLibraryNode(const wxString &aNodeName, const wxString &aDesc, bool pinned)
wxDataViewItem FindItem(const LIB_ID &aLibId)
Returns tree item corresponding to part.
void Update(LIB_TREE_ITEM *aItem)
Update the node using data from a LIB_ALIAS object.
LIB_TREE_NODE_ITEM & AddItem(LIB_TREE_ITEM *aItem)
Construct a new alias node, add it to this library, and return it.
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
std::map< wxString, wxString > m_Fields
List of weighted search terms.
void AssignIntrinsicRanks(const std::vector< wxString > &aShownColumns, bool presorted=false)
Store intrinsic ranks on all children of this node.
virtual COMMON_SETTINGS * GetCommonSettings() const
The backing store for a PROJECT, in JSON format.
static SYMBOL_LIB_TABLE * SchSymbolLibTable(PROJECT *aProject)
Accessor for project symbol library table.
Handle actions for the various symbol editor and viewers.
The symbol library editor main window.
Class to handle modifications to the symbol libraries.
SYMBOL_LIB_TABLE_ROW * GetLibrary(const wxString &aLibrary) const
Find a single library within the (aggregate) library table.
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_IO object i...
LIB_TREE_NODE::PTR_VECTOR::iterator deleteLibrary(LIB_TREE_NODE::PTR_VECTOR::iterator &aLibNodeIt)
SYMBOL_LIBRARY_MANAGER * m_libMgr
void GetValue(wxVariant &aVariant, wxDataViewItem const &aItem, unsigned int aCol) const override
SYMBOL_EDIT_FRAME * m_frame
bool GetAttr(wxDataViewItem const &aItem, unsigned int aCol, wxDataViewItemAttr &aAttr) const override
void ShutdownPreview(wxWindow *aParent) override
void updateLibrary(LIB_TREE_NODE_LIBRARY &aLibNode)
wxDataViewItem GetCurrentDataViewItem() override
static wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > Create(SYMBOL_EDIT_FRAME *aParent, SYMBOL_LIBRARY_MANAGER *aLibs)
void ShowPreview(wxWindow *aParent, const wxDataViewItem &aItem) override
int GetLibrariesCount() const override
Return the number of libraries loaded in the tree.
int m_lastSyncHash
SYMBOL_LIBRARY_MANAGER hash value returned in the last synchronization.
void Sync(const wxString &aForceRefresh, std::function< void(int, int, const wxString &)> aProgressCallback)
TOOL_INTERACTIVE * GetContextMenuTool() override
bool IsContainer(const wxDataViewItem &aItem) const override
bool HasPreview(const wxDataViewItem &aItem) override
std::map< wxString, int > m_libHashes
Hashes to decide whether a library needs an update.
SYMBOL_TREE_SYNCHRONIZING_ADAPTER(SYMBOL_EDIT_FRAME *aParent, SYMBOL_LIBRARY_MANAGER *aLibMgr)
void SetBorders(bool aLeft, bool aRight, bool aTop, bool aBottom)
void SetBorderColor(const KIGFX::COLOR4D &aColor)
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
PGM_BASE & Pgm()
The global program "get" accessor.
wxString UnescapeString(const wxString &aSource)
std::vector< wxString > pinned_symbol_libs
#define PROGRESS_INTERVAL_MILLIS
static const wxString c_previewName