From e811b9a2dd4eb6dd6837a3cabded657bdfcf9f03 Mon Sep 17 00:00:00 2001 From: Mike Williams Date: Tue, 3 May 2022 15:34:50 -0400 Subject: [PATCH] Hierarchy: update just selection on sheet change Fixes: https://gitlab.com/kicad/code/kicad/-/issues/11550 --- eeschema/hierarch.cpp | 31 ++++++++++++++++++++++++++++++- eeschema/hierarch.h | 5 +++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/eeschema/hierarch.cpp b/eeschema/hierarch.cpp index 9d7cc9d2ac..ec6007a8b1 100644 --- a/eeschema/hierarch.cpp +++ b/eeschema/hierarch.cpp @@ -205,6 +205,34 @@ void HIERARCHY_NAVIG_DLG::buildHierarchyTree( SCH_SHEET_PATH* aList, wxTreeItemI } +void HIERARCHY_NAVIG_DLG::UpdateHierarchySelection() +{ + m_currSheet = m_SchFrameEditor->GetCurrentSheet(); + + std::function selectSheet = [&]( const wxTreeItemId& id ) + { + wxCHECK_RET( id.IsOk(), wxT( "Invalid tree item" ) ); + + TreeItemData* itemData = static_cast( m_Tree->GetItemData( id ) ); + if( itemData->m_SheetPath == m_currSheet ) + { + m_Tree->EnsureVisible( id ); + m_Tree->SelectItem( id ); + } + + wxTreeItemIdValue cookie = id; + wxTreeItemId child = m_Tree->GetFirstChild( id, cookie ); + while( child.IsOk() ) + { + selectSheet( child ); + child = m_Tree->GetNextChild( child, cookie ); + } + }; + + selectSheet( m_Tree->GetRootItem() ); +} + + void HIERARCHY_NAVIG_DLG::UpdateHierarchyTree() { Freeze(); @@ -315,5 +343,6 @@ void SCH_EDIT_FRAME::DisplayCurrentSheet() TOOL_EVENT dummy; editTool->UpdateNetHighlighting( dummy ); - UpdateHierarchyNavigator(); + if( FindHierarchyNavigator() ) + FindHierarchyNavigator()->UpdateHierarchySelection(); } diff --git a/eeschema/hierarch.h b/eeschema/hierarch.h index 5f2ea06f2f..b949970db6 100644 --- a/eeschema/hierarch.h +++ b/eeschema/hierarch.h @@ -76,6 +76,11 @@ public: */ void UpdateHierarchyTree(); + /** + * Updates the tree's selection to match current page + */ + void UpdateHierarchySelection(); + private: /** * Create the hierarchical tree of the schematic.