31#include <wx/tokenzr.h>
32#include <wx/wupdlock.h>
33#include <wx/settings.h>
50 return wxSize( GetOwner()->GetWidth(), GetTextExtent(
m_text ).y );
53 bool GetValue( wxVariant& aValue )
const override
59 bool SetValue(
const wxVariant& aValue )
override
61 m_text = aValue.GetString();
65 void SetAttr(
const wxDataViewItemAttr& aAttr )
override
70 wxDataViewItemAttr realAttr = aAttr;
71 realAttr.SetStrikethrough(
false );
73 wxDataViewCustomRenderer::SetAttr( realAttr );
76 bool Render( wxRect aRect, wxDC *dc,
int aState )
override
78 RenderBackground( dc, aRect );
83 points[0] = aRect.GetTopLeft();
84 points[1] = aRect.GetTopRight() + wxPoint( -4, 0 );
85 points[2] = aRect.GetTopRight() + wxPoint( 0, aRect.GetHeight() / 2 );
86 points[3] = aRect.GetBottomRight() + wxPoint( -4, 1 );
87 points[4] = aRect.GetBottomLeft() + wxPoint( 0, 1 );
88 points[5] = aRect.GetTopLeft();
91 dc->DrawLines( 6, points );
97 if( aState & wxDATAVIEW_CELL_SELECTED )
98 dc->SetTextForeground( wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOXHIGHLIGHTTEXT ) );
101 RenderText(
m_text, 0, aRect, dc, 0 );
113 return wxDataViewItem(
const_cast<void*
>(
static_cast<void const*
>( aNode ) ) );
124 const wxString& aPinnedKey ) :
127 m_sort_mode( BEST_MATCH ),
128 m_show_units( true ),
129 m_preselect_unit( 0 ),
167 for(
const std::pair<const wxString, wxDataViewColumn*>& pair :
m_colNameMap )
187 const wxString& aDesc,
199 const std::vector<LIB_TREE_ITEM*>& aItemList,
200 bool pinned,
bool presorted )
214 wxWindowUpdateLocker updateLock(
m_widget );
233 m_widget->Collapse( wxDataViewItem( &*child ) );
245 wxStringTokenizer tokenizer( aSearch );
246 bool firstTerm =
true;
248 while( tokenizer.HasMoreTokens() )
251 wxString term = tokenizer.GetNextToken().Lower();
257 if( term.Contains(
":" ) )
260 wxString lib = term.BeforeFirst(
':' );
261 wxString itemName = term.AfterFirst(
':' );
288 wxDataViewItem item =
ToItem( firstMatch );
299 wxDataViewItem parent =
GetParent( item );
314 aDataViewCtrl->AssociateModel(
this );
333 doAddColumn( colName, colName == wxT(
"Description" ) );
372 wxString translatedHeader = aTranslate ? wxGetTranslation( aHeader ) : aHeader;
383 wxDataViewColumn* col =
new wxDataViewColumn( translatedHeader,
new LIB_TREE_RENDERER(),
385 wxDATAVIEW_CELL_INERT );
388 col->SetMinWidth( headerMinWidth.x );
430 return node ? node->
m_Unit : 0;
443 return ToNode( aSelection );
452 n += lib->m_Children.size();
467 return ToItem( lib.get() );
469 for( std::unique_ptr<LIB_TREE_NODE>& alias: lib->m_Children )
472 return ToItem( alias.get() );
478 return wxDataViewItem();
489 wxDataViewItemArray& aChildren )
const
492 unsigned int count = 0;
494 if( node->
m_Type == LIB_TREE_NODE::TYPE::ROOT
498 for( std::unique_ptr<LIB_TREE_NODE>
const& child: node->
m_Children )
500 if( child->m_Score > 0 )
502 aChildren.Add(
ToItem( &*child ) );
514 wxDataViewColumn* col =
nullptr;
519 for( ; idx <
m_columns.size() - 1; idx++ )
529 totalWidth += col->GetWidth();
532 int remainingWidth =
m_widget->GetSize().x - totalWidth;
546 std::vector<int> widths;
548 for(
const wxDataViewColumn* col :
m_columns )
549 widths.emplace_back( col->GetWidth() );
551 wxASSERT( widths.size() );
565 colIt->second += walk;
569 colIt->second -= walk;
607 if( !node || !parent || parent->
m_Type == LIB_TREE_NODE::TYPE::ROOT )
615 const wxDataViewItem& aItem,
616 unsigned int aCol )
const
620 aVariant = wxEmptyString;
645 else if( key == wxT(
"Description" ) )
648 valueStr = wxEmptyString;
654 valueStr.Replace( wxS(
"\n" ), wxS(
" " ) );
662 wxDataViewItemAttr& aAttr )
const
668 wxCHECK( node,
false );
675 aAttr.SetItalic(
true );
686 for( std::unique_ptr<LIB_TREE_NODE>& node: aNode.
m_Children )
688 if( !f( node.get() ) )
704 if( n->
m_Type == LIB_TREE_NODE::TYPE::ITEM && n->
m_Score > 1 )
708 else if( n->m_Score > firstMatch->m_Score )
711 m_widget->ExpandAncestors( ToItem( n ) );
728 m_widget->ExpandAncestors( ToItem( n ) );
736 m_widget->ExpandAncestors( ToItem( n ) );
751 if( !child->m_Name.StartsWith(
"-- " ) )
761 if( n->
m_Type == LIB_TREE_NODE::TYPE::ITEM )
764 m_widget->ExpandAncestors( ToItem( n ) );
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
The base frame for deriving all KiCad main window classes.
APP_SETTINGS_BASE * KifaceSettings() const
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
A logical library item identifier and consists of various portions much like a URI.
bool IsValid() const
Check if this LID_ID is valid.
const UTF8 & GetLibItemName() const
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
A mix-in to provide polymorphism between items stored in libraries (symbols, aliases and footprints).
int GetUnitFor(const wxDataViewItem &aSelection) const
Return the unit for the given item.
LIB_ID m_preselect_lib_id
LIB_TREE_NODE::TYPE GetTypeFor(const wxDataViewItem &aSelection) const
Return node type for the given item.
bool GetAttr(const wxDataViewItem &aItem, unsigned int aCol, wxDataViewItemAttr &aAttr) const override
Get any formatting for an item.
LIB_TREE_NODE_ROOT m_tree
std::map< wxString, int > m_colWidths
void FinishTreeInitialization()
A final-stage initialization to be called after the window hierarchy has been realized and the window...
void addColumnIfNecessary(const wxString &aHeader)
void PinLibrary(LIB_TREE_NODE *aTreeNode)
virtual wxDataViewItem GetCurrentDataViewItem()
void SetPreselectNode(const LIB_ID &aLibId, int aUnit)
Set the symbol name to be selected if there are no search results.
static LIB_TREE_NODE * ToNode(wxDataViewItem aItem)
Convert wxDataViewItem -> #SYM_TREE_NODE.
LIB_ID GetAliasFor(const wxDataViewItem &aSelection) const
Return the alias for the given item.
~LIB_TREE_MODEL_ADAPTER()
Destructor.
void AttachTo(wxDataViewCtrl *aDataViewCtrl)
Attach to a wxDataViewCtrl and initialize it.
void DoAddLibrary(const wxString &aNodeName, const wxString &aDesc, const std::vector< LIB_TREE_ITEM * > &aItemList, bool pinned, bool presorted)
Add the given list of symbols by alias.
void SetShownColumns(const std::vector< wxString > &aColumnNames)
Sets which columns are shown in the widget.
static wxDataViewItem ToItem(const LIB_TREE_NODE *aNode)
Convert #SYM_TREE_NODE -> wxDataViewItem.
virtual bool isSymbolModel()=0
bool IsContainer(const wxDataViewItem &aItem) const override
Check whether an item can have children.
static const wxString GetPinningSymbol()
void ShowUnits(bool aShow)
Whether or not to show units.
LIB_TREE_NODE * GetTreeNodeFor(const wxDataViewItem &aSelection) const
unsigned int GetChildren(const wxDataViewItem &aItem, wxDataViewItemArray &aChildren) const override
Populate a list of all the children of an item.
void SaveSettings()
Save the column widths to the config file.
@ NAME_COL
Library or library item name column.
std::map< unsigned, wxString > m_colIdxMap
wxDataViewColumn * doAddColumn(const wxString &aHeader, bool aTranslate=true)
LIB_TREE_MODEL_ADAPTER(EDA_BASE_FRAME *aParent, const wxString &aPinnedKey)
Create the adapter.
std::vector< wxDataViewColumn * > m_columns
std::vector< wxString > GetShownColumns() const
wxDataViewCtrl * m_widget
int GetItemCount() const
Return the number of symbols loaded in the tree.
const LIB_TREE_NODE * ShowResults()
Find and expand successful search results.
std::vector< wxString > m_shownColumns
void GetValue(wxVariant &aVariant, const wxDataViewItem &aItem, unsigned int aCol) const override
Get the value of an item.
void UnpinLibrary(LIB_TREE_NODE *aTreeNode)
std::map< wxString, wxDataViewColumn * > m_colNameMap
bool HasContainerColumns(const wxDataViewItem &aItem) const override
Check whether a container has columns too.
wxDataViewItem GetParent(const wxDataViewItem &aItem) const override
Get the parent of an item.
LIB_TREE_NODE_LIBRARY & DoAddLibraryNode(const wxString &aNodeName, const wxString &aDesc, bool pinned)
std::vector< wxString > m_availableColumns
EDA_BASE_FRAME * m_parent
wxDataViewItem FindItem(const LIB_ID &aLibId)
Returns tree item corresponding to part.
void UpdateSearchString(const wxString &aSearch, bool aState)
Set the search string provided by the user.
std::function< bool(LIB_TREE_NODE &aNode)> * m_filter
LIB_TREE_NODE_ITEM & AddItem(LIB_TREE_ITEM *aItem)
Construct a new alias node, add it to this library, and return it.
LIB_TREE_NODE_LIBRARY & AddLib(wxString const &aName, wxString const &aDesc)
Construct an empty library node, add it to the root, and return it.
void UpdateScore(EDA_COMBINED_MATCHER *aMatcher, const wxString &aLib, std::function< bool(LIB_TREE_NODE &aNode)> *aFilter) override
Update the score for this part.
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
void SortNodes(bool aUseScores)
Sort child nodes quickly and recursively (IntrinsicRanks must have been set).
std::map< wxString, wxString > m_Fields
List of weighted search terms.
virtual void ResetScore()
Initialize scores recursively.
void AssignIntrinsicRanks(bool presorted=false)
Store intrinsic ranks on all children of this node.
void SetAttr(const wxDataViewItemAttr &aAttr) override
bool SetValue(const wxVariant &aValue) override
wxSize GetSize() const override
bool GetValue(wxVariant &aValue) const override
bool Render(wxRect aRect, wxDC *dc, int aState) override
void UnpinLibrary(const wxString &aLibrary, bool isSymbolLibrary)
void PinLibrary(const wxString &aLibrary, bool isSymbolLibrary)
static void recursiveDescent(wxSizer *aSizer, std::map< int, wxString > &aLabels)
Base window classes and related definitions.
Abstract pattern-matching tool and implementations.
void recursiveDescent(LIB_TREE_NODE &aNode, const std::function< bool(const LIB_TREE_NODE *)> &f)
static const int kDataViewIndent
wxSize GetTextSize(const wxString &aSingleLine, wxWindow *aWindow)
Return the size of aSingleLine of text when it is rendered in aWindow using whatever font is currentl...
wxString UnescapeString(const wxString &aSource)
std::vector< wxString > columns
Ordered list of visible columns in the tree.
std::map< wxString, int > column_widths
Column widths, keyed by header name.
Functions to provide common constants and other functions to assist in making a consistent UI.