diff --git a/common/lib_tree_model.cpp b/common/lib_tree_model.cpp index 1d9978c0cf..107040e19e 100644 --- a/common/lib_tree_model.cpp +++ b/common/lib_tree_model.cpp @@ -206,7 +206,7 @@ void LIB_TREE_NODE_LIB_ID::Update( LIB_TREE_ITEM* aItem ) } -void LIB_TREE_NODE_LIB_ID::UpdateScore( EDA_COMBINED_MATCHER& aMatcher ) +void LIB_TREE_NODE_LIB_ID::UpdateScore( EDA_COMBINED_MATCHER& aMatcher, const wxString& aLib ) { if( m_Score <= 0 ) return; // Leaf nodes without scores are out of the game. @@ -218,6 +218,12 @@ void LIB_TREE_NODE_LIB_ID::UpdateScore( EDA_COMBINED_MATCHER& aMatcher ) m_Normalized = true; } + if( !aLib.IsEmpty() && m_Parent->m_MatchName != aLib ) + { + m_Score = 0; + return; + } + // Keywords and description we only count if the match string is at // least two characters long. That avoids spurious, low quality // matches. Most abbreviations are at three characters long. @@ -281,7 +287,7 @@ LIB_TREE_NODE_LIB_ID& LIB_TREE_NODE_LIB::AddItem( LIB_TREE_ITEM* aItem ) } -void LIB_TREE_NODE_LIB::UpdateScore( EDA_COMBINED_MATCHER& aMatcher ) +void LIB_TREE_NODE_LIB::UpdateScore( EDA_COMBINED_MATCHER& aMatcher, const wxString& aLib ) { m_Score = 0; @@ -291,13 +297,20 @@ void LIB_TREE_NODE_LIB::UpdateScore( EDA_COMBINED_MATCHER& aMatcher ) { for( std::unique_ptr& child: m_Children ) { - child->UpdateScore( aMatcher ); + child->UpdateScore( aMatcher, aLib ); m_Score = std::max( m_Score, child->m_Score ); } } else { // No children; we are a leaf. + + if( !aLib.IsEmpty() ) + { + m_Score = m_MatchName == aLib ? 1000 : 0; + return; + } + int found_pos = EDA_PATTERN_NOT_FOUND; int matchers_fired = 0; @@ -331,9 +344,9 @@ LIB_TREE_NODE_LIB& LIB_TREE_NODE_ROOT::AddLib( wxString const& aName, wxString c } -void LIB_TREE_NODE_ROOT::UpdateScore( EDA_COMBINED_MATCHER& aMatcher ) +void LIB_TREE_NODE_ROOT::UpdateScore( EDA_COMBINED_MATCHER& aMatcher, const wxString& aLib ) { for( std::unique_ptr& child: m_Children ) - child->UpdateScore( aMatcher ); + child->UpdateScore( aMatcher, aLib ); } diff --git a/common/lib_tree_model_adapter.cpp b/common/lib_tree_model_adapter.cpp index 31c2473f39..f65448b886 100644 --- a/common/lib_tree_model_adapter.cpp +++ b/common/lib_tree_model_adapter.cpp @@ -224,10 +224,18 @@ void LIB_TREE_MODEL_ADAPTER::UpdateSearchString( const wxString& aSearch, bool a while( tokenizer.HasMoreTokens() ) { - const wxString term = tokenizer.GetNextToken().Lower(); + wxString lib; + wxString term = tokenizer.GetNextToken().Lower(); + + if( term.Contains( ":" ) ) + { + lib = term.BeforeFirst( ':' ); + term = term.AfterFirst( ':' ); + } + EDA_COMBINED_MATCHER matcher( term ); - m_tree.UpdateScore( matcher ); + m_tree.UpdateScore( matcher, lib ); } m_tree.SortNodes(); diff --git a/include/lib_tree_model.h b/include/lib_tree_model.h index b31726151f..9e797f2943 100644 --- a/include/lib_tree_model.h +++ b/include/lib_tree_model.h @@ -81,7 +81,7 @@ public: * * @param aMatcher an EDA_COMBINED_MATCHER initialized with the search term */ - virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher ) = 0; + virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher, const wxString& aLib ) = 0; /** * Initialize score to kLowestDefaultScore, recursively. @@ -170,7 +170,7 @@ public: /** * Do nothing, units just take the parent's score */ - virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher ) override {} + virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher, const wxString& aLib ) override {} }; @@ -209,7 +209,7 @@ public: /** * Perform the actual search. */ - virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher ) override; + virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher, const wxString& aLib ) override; protected: /** @@ -250,7 +250,7 @@ public: */ LIB_TREE_NODE_LIB_ID& AddItem( LIB_TREE_ITEM* aItem ); - virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher ) override; + virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher, const wxString& aLib ) override; }; @@ -277,7 +277,7 @@ public: */ LIB_TREE_NODE_LIB& AddLib( wxString const& aName, wxString const& aDesc ); - virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher ) override; + virtual void UpdateScore( EDA_COMBINED_MATCHER& aMatcher, const wxString& aLib ) override; };