mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-09-14 02:03:12 +02:00
Rework libtree SearchTerms to honour shownColumns.
Fixes https://gitlab.com/kicad/code/kicad/-/issues/21419
This commit is contained in:
parent
a8df4b16e2
commit
34e075e112
@ -79,7 +79,7 @@ void DESIGN_BLOCK_TREE_MODEL_ADAPTER::AddLibraries( EDA_BASE_FRAME* aParent )
|
|||||||
DoAddLibrary( libName, library->GetDescr(), getDesignBlocks( aParent, libName ), pinned, true );
|
DoAddLibrary( libName, library->GetDescr(), getDesignBlocks( aParent, libName ), pinned, true );
|
||||||
}
|
}
|
||||||
|
|
||||||
m_tree.AssignIntrinsicRanks();
|
m_tree.AssignIntrinsicRanks( m_shownColumns );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include <lib_tree_model.h>
|
#include <lib_tree_model.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <core/kicad_algo.h>
|
||||||
#include <eda_pattern_match.h>
|
#include <eda_pattern_match.h>
|
||||||
#include <lib_tree_item.h>
|
#include <lib_tree_item.h>
|
||||||
#include <pgm_base.h>
|
#include <pgm_base.h>
|
||||||
@ -30,8 +31,23 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void LIB_TREE_NODE::AssignIntrinsicRanks( bool presorted )
|
void LIB_TREE_NODE::RebuildSearchTerms( const std::vector<wxString>& aShownColumns )
|
||||||
{
|
{
|
||||||
|
m_SearchTerms = m_sourceSearchTerms;
|
||||||
|
|
||||||
|
for( const auto& [name, value] : m_Fields )
|
||||||
|
{
|
||||||
|
if( alg::contains( aShownColumns, name ) )
|
||||||
|
m_SearchTerms.push_back( SEARCH_TERM( value, 4 ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LIB_TREE_NODE::AssignIntrinsicRanks( const std::vector<wxString>& aShownColumns, bool presorted )
|
||||||
|
{
|
||||||
|
for( std::unique_ptr<LIB_TREE_NODE>& child: m_Children )
|
||||||
|
child->RebuildSearchTerms( aShownColumns );
|
||||||
|
|
||||||
std::vector<LIB_TREE_NODE*> sort_buf;
|
std::vector<LIB_TREE_NODE*> sort_buf;
|
||||||
|
|
||||||
if( presorted )
|
if( presorted )
|
||||||
@ -174,7 +190,7 @@ LIB_TREE_NODE_ITEM::LIB_TREE_NODE_ITEM( LIB_TREE_NODE* aParent, LIB_TREE_ITEM* a
|
|||||||
|
|
||||||
aItem->GetChooserFields( m_Fields );
|
aItem->GetChooserFields( m_Fields );
|
||||||
|
|
||||||
m_SearchTerms = aItem->GetSearchTerms();
|
m_sourceSearchTerms = aItem->GetSearchTerms();
|
||||||
|
|
||||||
m_IsRoot = aItem->IsRoot();
|
m_IsRoot = aItem->IsRoot();
|
||||||
|
|
||||||
@ -204,7 +220,7 @@ void LIB_TREE_NODE_ITEM::Update( LIB_TREE_ITEM* aItem )
|
|||||||
|
|
||||||
aItem->GetChooserFields( m_Fields );
|
aItem->GetChooserFields( m_Fields );
|
||||||
|
|
||||||
m_SearchTerms = aItem->GetSearchTerms();
|
m_sourceSearchTerms = aItem->GetSearchTerms();
|
||||||
|
|
||||||
m_IsRoot = aItem->IsRoot();
|
m_IsRoot = aItem->IsRoot();
|
||||||
m_Children.clear();
|
m_Children.clear();
|
||||||
|
@ -242,7 +242,7 @@ LIB_TREE_NODE_LIBRARY& LIB_TREE_MODEL_ADAPTER::DoAddLibrary( const wxString& aNo
|
|||||||
for( LIB_TREE_ITEM* item: aItemList )
|
for( LIB_TREE_ITEM* item: aItemList )
|
||||||
lib_node.AddItem( item );
|
lib_node.AddItem( item );
|
||||||
|
|
||||||
lib_node.AssignIntrinsicRanks( presorted );
|
lib_node.AssignIntrinsicRanks( m_shownColumns, presorted );
|
||||||
|
|
||||||
return lib_node;
|
return lib_node;
|
||||||
}
|
}
|
||||||
@ -453,6 +453,9 @@ void LIB_TREE_MODEL_ADAPTER::SetShownColumns( const std::vector<wxString>& aColu
|
|||||||
|
|
||||||
if( recreate && m_widget )
|
if( recreate && m_widget )
|
||||||
recreateColumns();
|
recreateColumns();
|
||||||
|
|
||||||
|
for( std::unique_ptr<LIB_TREE_NODE>& lib: m_tree.m_Children )
|
||||||
|
lib->AssignIntrinsicRanks( m_shownColumns );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1012,7 +1012,10 @@ void LIB_TREE::onHeaderContextMenu( wxDataViewEvent& aEvent )
|
|||||||
m_adapter->GetShownColumns() );
|
m_adapter->GetShownColumns() );
|
||||||
|
|
||||||
if( dlg.ShowModal() == wxID_OK )
|
if( dlg.ShowModal() == wxID_OK )
|
||||||
|
{
|
||||||
m_adapter->SetShownColumns( dlg.EnabledList() );
|
m_adapter->SetShownColumns( dlg.EnabledList() );
|
||||||
|
Regenerate( true );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_previewDisabled = false;
|
m_previewDisabled = false;
|
||||||
|
@ -50,13 +50,6 @@ std::vector<SEARCH_TERM> LIB_SYMBOL::GetSearchTerms()
|
|||||||
while( keywordTokenizer.HasMoreTokens() )
|
while( keywordTokenizer.HasMoreTokens() )
|
||||||
terms.emplace_back( SEARCH_TERM( keywordTokenizer.GetNextToken(), 4 ) );
|
terms.emplace_back( SEARCH_TERM( keywordTokenizer.GetNextToken(), 4 ) );
|
||||||
|
|
||||||
// TODO(JE) rework this later so we can highlight matches in their column
|
|
||||||
std::map<wxString, wxString> fields;
|
|
||||||
GetChooserFields( fields );
|
|
||||||
|
|
||||||
for( const auto& [ name, text ] : fields )
|
|
||||||
terms.emplace_back( SEARCH_TERM( text, 4 ) );
|
|
||||||
|
|
||||||
// Also include keywords as one long string, just in case
|
// Also include keywords as one long string, just in case
|
||||||
terms.emplace_back( SEARCH_TERM( GetKeyWords(), 1 ) );
|
terms.emplace_back( SEARCH_TERM( GetKeyWords(), 1 ) );
|
||||||
terms.emplace_back( SEARCH_TERM( GetDescription(), 1 ) );
|
terms.emplace_back( SEARCH_TERM( GetDescription(), 1 ) );
|
||||||
@ -113,7 +106,6 @@ LIB_SYMBOL::LIB_SYMBOL( const wxString& aName, LIB_SYMBOL* aParent, SYMBOL_LIB*
|
|||||||
{
|
{
|
||||||
SCH_FIELD* field = new SCH_FIELD( this, id );
|
SCH_FIELD* field = new SCH_FIELD( this, id );
|
||||||
field->SetVisible( visible );
|
field->SetVisible( visible );
|
||||||
field->SetShowInChooser( false );
|
|
||||||
m_drawings[SCH_FIELD_T].push_back( field );
|
m_drawings[SCH_FIELD_T].push_back( field );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -189,7 +189,7 @@ bool SYMBOL_TREE_MODEL_ADAPTER::AddLibraries( const std::vector<wxString>& aNick
|
|||||||
|
|
||||||
KIID::CreateNilUuids( false );
|
KIID::CreateNilUuids( false );
|
||||||
|
|
||||||
m_tree.AssignIntrinsicRanks();
|
m_tree.AssignIntrinsicRanks( m_shownColumns );
|
||||||
|
|
||||||
if( progressReporter )
|
if( progressReporter )
|
||||||
{
|
{
|
||||||
|
@ -136,7 +136,7 @@ void SYMBOL_TREE_SYNCHRONIZING_ADAPTER::Sync( const wxString& aForceRefresh,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_tree.AssignIntrinsicRanks();
|
m_tree.AssignIntrinsicRanks( m_shownColumns );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -198,7 +198,7 @@ void SYMBOL_TREE_SYNCHRONIZING_ADAPTER::updateLibrary( LIB_TREE_NODE_LIBRARY& aL
|
|||||||
aLibNode.AddItem( symbol );
|
aLibNode.AddItem( symbol );
|
||||||
}
|
}
|
||||||
|
|
||||||
aLibNode.AssignIntrinsicRanks();
|
aLibNode.AssignIntrinsicRanks( m_shownColumns );
|
||||||
m_libHashes[aLibNode.m_Name] = m_libMgr->GetLibraryHash( aLibNode.m_Name );
|
m_libHashes[aLibNode.m_Name] = m_libMgr->GetLibraryHash( aLibNode.m_Name );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,11 +83,16 @@ public:
|
|||||||
virtual void UpdateScore( const std::vector<std::unique_ptr<EDA_COMBINED_MATCHER>>& aMatchers,
|
virtual void UpdateScore( const std::vector<std::unique_ptr<EDA_COMBINED_MATCHER>>& aMatchers,
|
||||||
std::function<bool( LIB_TREE_NODE& aNode )>* aFilter ) = 0;
|
std::function<bool( LIB_TREE_NODE& aNode )>* aFilter ) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rebuild search terms from source search terms and shown fields.
|
||||||
|
*/
|
||||||
|
void RebuildSearchTerms( const std::vector<wxString>& aShownColumns );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store intrinsic ranks on all children of this node. See m_IntrinsicRank
|
* Store intrinsic ranks on all children of this node. See m_IntrinsicRank
|
||||||
* member doc for more information.
|
* member doc for more information.
|
||||||
*/
|
*/
|
||||||
void AssignIntrinsicRanks( bool presorted = false );
|
void AssignIntrinsicRanks( const std::vector<wxString>& aShownColumns, bool presorted = false );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sort child nodes quickly and recursively (IntrinsicRanks must have been set).
|
* Sort child nodes quickly and recursively (IntrinsicRanks must have been set).
|
||||||
@ -142,6 +147,9 @@ public:
|
|||||||
|
|
||||||
bool m_IsRecentlyUsedGroup;
|
bool m_IsRecentlyUsedGroup;
|
||||||
bool m_IsAlreadyPlacedGroup;
|
bool m_IsAlreadyPlacedGroup;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::vector<SEARCH_TERM> m_sourceSearchTerms;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -204,7 +204,13 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Sort the tree and assign ranks after adding libraries.
|
* Sort the tree and assign ranks after adding libraries.
|
||||||
*/
|
*/
|
||||||
void AssignIntrinsicRanks() { m_tree.AssignIntrinsicRanks(); }
|
void AssignIntrinsicRanks()
|
||||||
|
{
|
||||||
|
m_tree.AssignIntrinsicRanks( m_shownColumns );
|
||||||
|
|
||||||
|
for( const std::unique_ptr<LIB_TREE_NODE>& child : m_tree.m_Children )
|
||||||
|
child->AssignIntrinsicRanks( m_shownColumns );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the search string provided by the user.
|
* Set the search string provided by the user.
|
||||||
@ -418,6 +424,7 @@ protected:
|
|||||||
std::vector<wxString> m_availableColumns;
|
std::vector<wxString> m_availableColumns;
|
||||||
|
|
||||||
wxDataViewCtrl* m_widget;
|
wxDataViewCtrl* m_widget;
|
||||||
|
std::vector<wxString> m_shownColumns; // Stored in display order
|
||||||
|
|
||||||
private:
|
private:
|
||||||
EDA_BASE_FRAME* m_parent;
|
EDA_BASE_FRAME* m_parent;
|
||||||
@ -434,7 +441,6 @@ private:
|
|||||||
std::vector<wxDataViewColumn*> m_columns;
|
std::vector<wxDataViewColumn*> m_columns;
|
||||||
std::map<wxString, wxDataViewColumn*> m_colNameMap;
|
std::map<wxString, wxDataViewColumn*> m_colNameMap;
|
||||||
std::map<wxString, int> m_colWidths;
|
std::map<wxString, int> m_colWidths;
|
||||||
std::vector<wxString> m_shownColumns; // Stored in display order
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // LIB_TREE_MODEL_ADAPTER_H
|
#endif // LIB_TREE_MODEL_ADAPTER_H
|
||||||
|
@ -71,7 +71,7 @@ void FP_TREE_MODEL_ADAPTER::AddLibraries( EDA_BASE_FRAME* aParent )
|
|||||||
DoAddLibrary( libName, library->GetDescr(), getFootprints( libName ), pinned, true );
|
DoAddLibrary( libName, library->GetDescr(), getFootprints( libName ), pinned, true );
|
||||||
}
|
}
|
||||||
|
|
||||||
m_tree.AssignIntrinsicRanks();
|
m_tree.AssignIntrinsicRanks( m_shownColumns );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ void FP_TREE_SYNCHRONIZING_ADAPTER::Sync( FP_LIB_TABLE* aLibs )
|
|||||||
}
|
}
|
||||||
|
|
||||||
if( m_libMap.size() > count )
|
if( m_libMap.size() > count )
|
||||||
m_tree.AssignIntrinsicRanks();
|
m_tree.AssignIntrinsicRanks( m_shownColumns );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -173,7 +173,7 @@ void FP_TREE_SYNCHRONIZING_ADAPTER::updateLibrary( LIB_TREE_NODE_LIBRARY& aLibNo
|
|||||||
for( LIB_TREE_ITEM* footprint : footprints )
|
for( LIB_TREE_ITEM* footprint : footprints )
|
||||||
aLibNode.AddItem( footprint );
|
aLibNode.AddItem( footprint );
|
||||||
|
|
||||||
aLibNode.AssignIntrinsicRanks();
|
aLibNode.AssignIntrinsicRanks( m_shownColumns );
|
||||||
m_libMap.insert( aLibNode.m_Name );
|
m_libMap.insert( aLibNode.m_Name );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user