ADDED: ExpandAll/CollapseAll for lib trees.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/8243
This commit is contained in:
Jeff Young 2024-01-28 18:28:54 +00:00
parent 4eefbc7815
commit 6856e59374
6 changed files with 101 additions and 1 deletions

View File

@ -298,6 +298,18 @@ TOOL_ACTION ACTIONS::rightJustify( TOOL_ACTION_ARGS()
.Tooltip( _( "Right-justify fields and text items" ) )
.Icon( BITMAPS::text_align_right ) );
TOOL_ACTION ACTIONS::expandAll( TOOL_ACTION_ARGS()
.Name( "common.Control.expandAll" )
.Scope( AS_GLOBAL )
.FriendlyName( _( "Expand All" ) )
.Icon( BITMAPS::up ) ); // JEY TODO: need icon
TOOL_ACTION ACTIONS::collapseAll( TOOL_ACTION_ARGS()
.Name( "common.Control.collapseAll" )
.Scope( AS_GLOBAL )
.FriendlyName( _( "Collapse All" ) )
.Icon( BITMAPS::down ) ); // JEY TODO: need icon
TOOL_ACTION ACTIONS::selectColumns( TOOL_ACTION_ARGS()
.Name( "common.InteractiveSelection.SelectColumns" )
.Scope( AS_GLOBAL )

View File

@ -98,6 +98,9 @@ LIB_TREE::LIB_TREE( wxWindow* aParent, const wxString& aRecentSearchesKey, LIB_T
menu.Append( 4201, _( "Sort by Best Match" ), wxEmptyString, wxITEM_CHECK );
menu.Append( 4202, _( "Sort Alphabetically" ), wxEmptyString, wxITEM_CHECK );
menu.AppendSeparator();
menu.Append( 4203, ACTIONS::expandAll.GetMenuItem() );
menu.Append( 4204, ACTIONS::collapseAll.GetMenuItem() );
if( m_adapter->GetSortMode() == LIB_TREE_MODEL_ADAPTER::BEST_MATCH )
menu.Check( 4201, true );
@ -117,8 +120,18 @@ LIB_TREE::LIB_TREE( wxWindow* aParent, const wxString& aRecentSearchesKey, LIB_T
m_adapter->SetSortMode( LIB_TREE_MODEL_ADAPTER::ALPHABETIC );
Regenerate( true );
}
else if( menu_id == 3 || menu_id == 4203 )
{
ExpandAll();
}
else if( menu_id == 4 || menu_id == 4204 )
{
CollapseAll();
}
} );
m_sort_ctrl->Bind( wxEVT_CHAR_HOOK, &LIB_TREE::onTreeCharHook, this );
search_sizer->Add( m_sort_ctrl, 0, wxEXPAND | wxRIGHT, 5 );
sizer->Add( search_sizer, 0, wxEXPAND | wxBOTTOM, 5 );
@ -335,6 +348,18 @@ void LIB_TREE::ExpandLibId( const LIB_ID& aLibId )
}
void LIB_TREE::ExpandAll()
{
m_tree_ctrl->ExpandAll();
}
void LIB_TREE::CollapseAll()
{
m_tree_ctrl->CollapseAll();
}
void LIB_TREE::SetSearchString( const wxString& aSearchString )
{
m_query_ctrl->ChangeValue( aSearchString );
@ -563,12 +588,36 @@ void LIB_TREE::onDebounceTimer( wxTimerEvent& aEvent )
void LIB_TREE::onQueryCharHook( wxKeyEvent& aKeyStroke )
{
int hotkey = aKeyStroke.GetKeyCode();
if( aKeyStroke.GetModifiers() & wxMOD_CONTROL )
hotkey += MD_CTRL;
if( aKeyStroke.GetModifiers() & wxMOD_ALT )
hotkey += MD_ALT;
if( aKeyStroke.GetModifiers() & wxMOD_SHIFT )
hotkey += MD_SHIFT;
if( hotkey == ACTIONS::expandAll.GetHotKey()
|| hotkey == ACTIONS::expandAll.GetHotKeyAlt() )
{
m_tree_ctrl->ExpandAll();
return;
}
else if( hotkey == ACTIONS::collapseAll.GetHotKey()
|| hotkey == ACTIONS::collapseAll.GetHotKeyAlt() )
{
m_tree_ctrl->CollapseAll();
return;
}
wxDataViewItem sel = m_tree_ctrl->GetSelection();
if( !sel.IsOk() )
sel = m_adapter->GetCurrentDataViewItem();
LIB_TREE_NODE::TYPE type = sel.IsOk() ? m_adapter->GetTypeFor( sel ) : LIB_TREE_NODE::INVALID;
LIB_TREE_NODE::TYPE type = sel.IsOk() ? m_adapter->GetTypeFor( sel ) : LIB_TREE_NODE::INVALID;
switch( aKeyStroke.GetKeyCode() )
{

View File

@ -128,3 +128,34 @@ wxDataViewItem WX_DATAVIEWCTRL::GetNextSibling( wxDataViewItem const& aItem )
return invalid;
}
void recursiveDescent( WX_DATAVIEWCTRL* aCtrl, wxDataViewItem aItem, bool aExpand )
{
wxDataViewItemArray children;
aCtrl->GetModel()->GetChildren( aItem, children );
for( size_t i = 0; i < children.size(); ++i )
recursiveDescent( aCtrl, children[i], aExpand );
if( aItem )
{
if( aExpand )
aCtrl->Expand( aItem );
else
aCtrl->Collapse( aItem );
}
}
void WX_DATAVIEWCTRL::ExpandAll()
{
recursiveDescent( this, wxDataViewItem(), true );
}
void WX_DATAVIEWCTRL::CollapseAll()
{
recursiveDescent( this, wxDataViewItem(), false );
}

View File

@ -77,6 +77,8 @@ public:
static TOOL_ACTION leftJustify;
static TOOL_ACTION centerJustify;
static TOOL_ACTION rightJustify;
static TOOL_ACTION expandAll;
static TOOL_ACTION collapseAll;
// Tables
static TOOL_ACTION selectRows;

View File

@ -124,6 +124,9 @@ public:
*/
void ExpandLibId( const LIB_ID& aLibId );
void ExpandAll();
void CollapseAll();
/**
* Save/restore search string.
*/

View File

@ -66,6 +66,9 @@ public:
wxDataViewItem GetNextSibling( wxDataViewItem const& aItem );
void DoSetToolTipText( const wxString &tip ) override {}
void ExpandAll();
void CollapseAll();
};
#endif // WX_DATAVIEWCTRL_H_