Filter must return true for libraries.

Also fixes a bug where a single symbol library wasn't expanded
due to the presence of the "-- already placed --" and
"-- recently used --" pseudo-libraries.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/16074
This commit is contained in:
Jeff Young 2023-11-13 15:44:41 +00:00
parent 229bcc7308
commit 752d2d5295
3 changed files with 17 additions and 8 deletions

View File

@ -669,11 +669,21 @@ const LIB_TREE_NODE* LIB_TREE_MODEL_ADAPTER::ShowResults()
// If still no matches expand a single library if there is only one // If still no matches expand a single library if there is only one
if( !firstMatch ) if( !firstMatch )
{ {
int libraries = 0;
for( const std::unique_ptr<LIB_TREE_NODE>& child : m_tree.m_Children )
{
if( !child->m_Name.StartsWith( "-- " ) )
libraries++;
}
if( libraries != 1 )
return nullptr;
recursiveDescent( m_tree, recursiveDescent( m_tree,
[&]( const LIB_TREE_NODE* n ) [&]( const LIB_TREE_NODE* n )
{ {
if( n->m_Type == LIB_TREE_NODE::TYPE::LIB_ITEM if( n->m_Type == LIB_TREE_NODE::TYPE::LIB_ITEM )
&& n->m_Parent->m_Parent->m_Children.size() == 1 )
{ {
firstMatch = n; firstMatch = n;
m_widget->ExpandAncestors( ToItem( n ) ); m_widget->ExpandAncestors( ToItem( n ) );

View File

@ -61,7 +61,7 @@ public:
* see SCH_BASE_FRAME::SelectSymbolFromLibrary() for details. * see SCH_BASE_FRAME::SelectSymbolFromLibrary() for details.
* if aFilter == NULL, remove all filtering. * if aFilter == NULL, remove all filtering.
*/ */
void SetFilter( std::function<bool( LIB_TREE_NODE& aNode )>* aFilter ); void SetFilter( std::function<bool( LIB_TREE_NODE& aNode )>* aFilter );
private: private:
void OnPaint( wxPaintEvent& aEvent ); void OnPaint( wxPaintEvent& aEvent );

View File

@ -103,13 +103,12 @@ PANEL_SYMBOL_CHOOSER::PANEL_SYMBOL_CHOOSER( SCH_BASE_FRAME* aFrame, wxWindow* aP
if( aFilter->GetFilterPowerSymbols() ) if( aFilter->GetFilterPowerSymbols() )
{ {
// HACK ALERT: the only filter ever used for symbols is the power filter, so we // HACK ALERT: when loading symbols we presume that *any* filter is a power symbol
// just look for the function pointer being non-null. (What the function does is // filter. So the filter only needs to return true for libraries.
// therefore immaterial as it's never called.)
static std::function<bool( LIB_TREE_NODE& )> powerFilter = static std::function<bool( LIB_TREE_NODE& )> powerFilter =
[]( LIB_TREE_NODE& ) -> bool []( LIB_TREE_NODE& aNode ) -> bool
{ {
return false; return true;
}; };
adapter->SetFilter( &powerFilter ); adapter->SetFilter( &powerFilter );