De-templatify CMP_TREE_MODEL_ADAPTER::FindAndExpand
std::function lets this be a plain method instead of a template; this cleans up the header a bit and possibly reduces a bit of bloat
This commit is contained in:
parent
b2f1d22bbf
commit
72cfd38979
|
@ -368,6 +368,31 @@ int CMP_TREE_MODEL_ADAPTER::WidthFor( wxString const& aHeading, int aCol )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool CMP_TREE_MODEL_ADAPTER::FindAndExpand(
|
||||||
|
CMP_TREE_NODE& aNode,
|
||||||
|
std::function<bool( CMP_TREE_NODE const* )> aFunc )
|
||||||
|
{
|
||||||
|
for( auto& node: aNode.Children )
|
||||||
|
{
|
||||||
|
if( aFunc( &*node ) )
|
||||||
|
{
|
||||||
|
auto item = wxDataViewItem(
|
||||||
|
const_cast<void*>( static_cast<void const*>( &*node ) ) );
|
||||||
|
m_widget->ExpandAncestors( item );
|
||||||
|
m_widget->EnsureVisible( item );
|
||||||
|
m_widget->Select( item );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if( FindAndExpand( *node, aFunc ) )
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool CMP_TREE_MODEL_ADAPTER::ShowResults()
|
bool CMP_TREE_MODEL_ADAPTER::ShowResults()
|
||||||
{
|
{
|
||||||
return FindAndExpand( m_tree,
|
return FindAndExpand( m_tree,
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include <wx/hashmap.h>
|
#include <wx/hashmap.h>
|
||||||
#include <wx/dataview.h>
|
#include <wx/dataview.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
class LIB_ALIAS;
|
class LIB_ALIAS;
|
||||||
class PART_LIB;
|
class PART_LIB;
|
||||||
|
@ -333,28 +334,9 @@ private:
|
||||||
*
|
*
|
||||||
* @return whether a node was expanded
|
* @return whether a node was expanded
|
||||||
*/
|
*/
|
||||||
template<typename Func>
|
bool FindAndExpand(
|
||||||
bool FindAndExpand( CMP_TREE_NODE& aNode, Func f )
|
CMP_TREE_NODE& aNode,
|
||||||
{
|
std::function<bool( CMP_TREE_NODE const* )> aFunc );
|
||||||
for( auto& node: aNode.Children )
|
|
||||||
{
|
|
||||||
if( f( &*node ) )
|
|
||||||
{
|
|
||||||
auto item = wxDataViewItem(
|
|
||||||
const_cast<void*>( static_cast<void const*>( &*node ) ) );
|
|
||||||
m_widget->ExpandAncestors( item );
|
|
||||||
m_widget->EnsureVisible( item );
|
|
||||||
m_widget->Select( item );
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if( FindAndExpand( *node, f ) )
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find and expand successful search results
|
* Find and expand successful search results
|
||||||
|
|
Loading…
Reference in New Issue