Show all library children if library name matches search
This commit is contained in:
parent
53c2543474
commit
a042d1aab4
|
@ -295,18 +295,18 @@ LIB_TREE_NODE_ITEM& LIB_TREE_NODE_LIBRARY::AddItem( LIB_TREE_ITEM* aItem )
|
|||
void LIB_TREE_NODE_LIBRARY::UpdateScore( EDA_COMBINED_MATCHER* aMatcher, const wxString& aLib,
|
||||
std::function<bool( LIB_TREE_NODE& aNode )>* aFilter )
|
||||
{
|
||||
int newScore = 0;
|
||||
int maxChildScore = 0;
|
||||
|
||||
for( std::unique_ptr<LIB_TREE_NODE>& child: m_Children )
|
||||
{
|
||||
child->UpdateScore( aMatcher, aLib, aFilter );
|
||||
newScore = std::max( newScore, child->m_Score );
|
||||
maxChildScore = std::max( maxChildScore, child->m_Score );
|
||||
}
|
||||
|
||||
// Each time UpdateScore is called for a library, child (item) scores may go up or down.
|
||||
// If the all go down to zero, we need to make sure to drop the library from the list.
|
||||
if( newScore > 0 )
|
||||
m_Score = std::max( m_Score, newScore );
|
||||
if( maxChildScore > 0 )
|
||||
m_Score = std::max( m_Score, maxChildScore );
|
||||
else
|
||||
m_Score = 0;
|
||||
|
||||
|
@ -320,7 +320,17 @@ void LIB_TREE_NODE_LIBRARY::UpdateScore( EDA_COMBINED_MATCHER* aMatcher, const w
|
|||
|
||||
// aMatcher test is additive
|
||||
if( aMatcher )
|
||||
m_Score += aMatcher->ScoreTerms( m_SearchTerms );
|
||||
{
|
||||
int ownScore = aMatcher->ScoreTerms( m_SearchTerms );
|
||||
m_Score += ownScore;
|
||||
|
||||
// If we have a hit on a library, show all children in that library
|
||||
if( maxChildScore <= 0 && ownScore > 0 )
|
||||
{
|
||||
for( std::unique_ptr<LIB_TREE_NODE>& child: m_Children )
|
||||
child->ForceScore( 1 );
|
||||
}
|
||||
}
|
||||
|
||||
// show all nodes if no search/filter/etc. criteria are given
|
||||
if( m_Children.empty() && !aMatcher && aLib.IsEmpty() && ( !aFilter || (*aFilter)(*this) ) )
|
||||
|
|
|
@ -89,6 +89,8 @@ public:
|
|||
*/
|
||||
virtual void ResetScore();
|
||||
|
||||
virtual void ForceScore( int aScore ) { m_Score = aScore; }
|
||||
|
||||
/**
|
||||
* Store intrinsic ranks on all children of this node. See m_IntrinsicRank
|
||||
* member doc for more information.
|
||||
|
|
Loading…
Reference in New Issue