From c8d2a9340b9f6e020ccb8da718797a0cb1b09a88 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 28 Jan 2024 21:20:01 +0000 Subject: [PATCH] ADDED: ExpandAll/CollapseAll for hierarchy pane. --- common/widgets/wx_html_report_panel_base.fbp | 2 +- eeschema/widgets/hierarchy_pane.cpp | 94 ++++++++++++++++---- eeschema/widgets/hierarchy_pane.h | 8 +- 3 files changed, 82 insertions(+), 22 deletions(-) diff --git a/common/widgets/wx_html_report_panel_base.fbp b/common/widgets/wx_html_report_panel_base.fbp index b000ab0f95..72dcec45e0 100644 --- a/common/widgets/wx_html_report_panel_base.fbp +++ b/common/widgets/wx_html_report_panel_base.fbp @@ -132,7 +132,7 @@ - onRightClick + onTreeItemRightClick diff --git a/eeschema/widgets/hierarchy_pane.cpp b/eeschema/widgets/hierarchy_pane.cpp index 99c411296f..0971cc15ca 100644 --- a/eeschema/widgets/hierarchy_pane.cpp +++ b/eeschema/widgets/hierarchy_pane.cpp @@ -91,7 +91,7 @@ HIERARCHY_PANE::HIERARCHY_PANE( SCH_EDIT_FRAME* aParent ) : m_tree->AssignImageList( imageList ); - sizer->Add( m_tree, 1, wxEXPAND, wxBORDER_NONE, 0 ); + sizer->Add( m_tree, 1, wxEXPAND, wxBORDER_NONE ); m_events_bound = false; @@ -100,7 +100,9 @@ HIERARCHY_PANE::HIERARCHY_PANE( SCH_EDIT_FRAME* aParent ) : // Enable selection events Bind( wxEVT_TREE_ITEM_ACTIVATED, &HIERARCHY_PANE::onSelectSheetPath, this ); Bind( wxEVT_TREE_SEL_CHANGED, &HIERARCHY_PANE::onSelectSheetPath, this ); - Bind( wxEVT_TREE_ITEM_RIGHT_CLICK, &HIERARCHY_PANE::onRightClick, this ); + Bind( wxEVT_TREE_ITEM_RIGHT_CLICK, &HIERARCHY_PANE::onTreeItemRightClick, this ); + Bind( wxEVT_CHAR_HOOK, &HIERARCHY_PANE::onCharHook, this ); + m_tree->Bind( wxEVT_RIGHT_UP, &HIERARCHY_PANE::onRightClick, this ); m_events_bound = true; } @@ -110,7 +112,9 @@ HIERARCHY_PANE::~HIERARCHY_PANE() { Unbind( wxEVT_TREE_ITEM_ACTIVATED, &HIERARCHY_PANE::onSelectSheetPath, this ); Unbind( wxEVT_TREE_SEL_CHANGED, &HIERARCHY_PANE::onSelectSheetPath, this ); - Unbind( wxEVT_TREE_ITEM_RIGHT_CLICK, &HIERARCHY_PANE::onRightClick, this ); + Unbind( wxEVT_TREE_ITEM_RIGHT_CLICK, &HIERARCHY_PANE::onTreeItemRightClick, this ); + Unbind( wxEVT_CHAR_HOOK, &HIERARCHY_PANE::onCharHook, this ); + m_tree->Unbind( wxEVT_RIGHT_UP, &HIERARCHY_PANE::onRightClick, this ); } @@ -146,7 +150,7 @@ void HIERARCHY_PANE::UpdateHierarchySelection() // Disable selection events Unbind( wxEVT_TREE_ITEM_ACTIVATED, &HIERARCHY_PANE::onSelectSheetPath, this ); Unbind( wxEVT_TREE_SEL_CHANGED, &HIERARCHY_PANE::onSelectSheetPath, this ); - Unbind( wxEVT_TREE_ITEM_RIGHT_CLICK, &HIERARCHY_PANE::onRightClick, this ); + Unbind( wxEVT_TREE_ITEM_RIGHT_CLICK, &HIERARCHY_PANE::onTreeItemRightClick, this ); m_events_bound = false; } @@ -193,7 +197,7 @@ void HIERARCHY_PANE::UpdateHierarchySelection() // Enable selection events Bind( wxEVT_TREE_ITEM_ACTIVATED, &HIERARCHY_PANE::onSelectSheetPath, this ); Bind( wxEVT_TREE_SEL_CHANGED, &HIERARCHY_PANE::onSelectSheetPath, this ); - Bind( wxEVT_TREE_ITEM_RIGHT_CLICK, &HIERARCHY_PANE::onRightClick, this ); + Bind( wxEVT_TREE_ITEM_RIGHT_CLICK, &HIERARCHY_PANE::onTreeItemRightClick, this ); m_events_bound = true; } @@ -211,7 +215,7 @@ void HIERARCHY_PANE::UpdateHierarchyTree() // Disable selection events Unbind( wxEVT_TREE_ITEM_ACTIVATED, &HIERARCHY_PANE::onSelectSheetPath, this ); Unbind( wxEVT_TREE_SEL_CHANGED, &HIERARCHY_PANE::onSelectSheetPath, this ); - Unbind( wxEVT_TREE_ITEM_RIGHT_CLICK, &HIERARCHY_PANE::onRightClick, this ); + Unbind( wxEVT_TREE_ITEM_RIGHT_CLICK, &HIERARCHY_PANE::onTreeItemRightClick, this ); m_events_bound = false; } @@ -235,7 +239,7 @@ void HIERARCHY_PANE::UpdateHierarchyTree() // Enable selection events Bind( wxEVT_TREE_ITEM_ACTIVATED, &HIERARCHY_PANE::onSelectSheetPath, this ); Bind( wxEVT_TREE_SEL_CHANGED, &HIERARCHY_PANE::onSelectSheetPath, this ); - Bind( wxEVT_TREE_ITEM_RIGHT_CLICK, &HIERARCHY_PANE::onRightClick, this ); + Bind( wxEVT_TREE_ITEM_RIGHT_CLICK, &HIERARCHY_PANE::onTreeItemRightClick, this ); m_events_bound = true; } @@ -302,23 +306,41 @@ void HIERARCHY_PANE::UpdateLabelsHierarchyTree() } -void HIERARCHY_PANE::onRightClick( wxTreeEvent& aEvent ) +void HIERARCHY_PANE::onTreeItemRightClick( wxTreeEvent& aEvent ) { - wxTreeItemId itemSel = aEvent.GetItem(); + onRightClick( aEvent.GetItem() ); +} - if( !itemSel.IsOk() ) - return; - TREE_ITEM_DATA* itemData = static_cast( m_tree->GetItemData( itemSel ) ); +void HIERARCHY_PANE::onRightClick( wxMouseEvent& aEvent ) +{ + onRightClick( wxTreeItemId() ); +} - if( !itemData ) - return; - wxMenu ctxMenu; +void HIERARCHY_PANE::onRightClick( wxTreeItemId aItem ) +{ + wxMenu ctxMenu; + TREE_ITEM_DATA* itemData = nullptr; - ctxMenu.Append( 1, _( "Edit Page Number" ) ); + if( !aItem.IsOk() ) + aItem = m_tree->GetSelection(); - if( GetPopupMenuSelectionFromUser( ctxMenu ) == 1 ) + if( aItem.IsOk() ) + itemData = static_cast( m_tree->GetItemData( aItem ) ); + + if( itemData ) + { + ctxMenu.Append( 1, _( "Edit Page Number" ) ); + ctxMenu.AppendSeparator(); + } + + ctxMenu.Append( 2, ACTIONS::expandAll.GetMenuItem() ); + ctxMenu.Append( 3, ACTIONS::collapseAll.GetMenuItem() ); + + switch( GetPopupMenuSelectionFromUser( ctxMenu ) ) + { + case 1: { wxString msg; wxString sheetPath = itemData->m_SheetPath.PathHumanReadable( false, true ); @@ -352,6 +374,44 @@ void HIERARCHY_PANE::onRightClick( wxTreeEvent& aEvent ) UpdateLabelsHierarchyTree(); } + + break; + } + case 2: + m_tree->ExpandAll(); + break; + + case 3: + m_tree->CollapseAll(); + break; + } +} + + +void HIERARCHY_PANE::onCharHook( 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->ExpandAll(); + return; + } + else if( hotkey == ACTIONS::collapseAll.GetHotKey() + || hotkey == ACTIONS::collapseAll.GetHotKeyAlt() ) + { + m_tree->CollapseAll(); + return; } } diff --git a/eeschema/widgets/hierarchy_pane.h b/eeschema/widgets/hierarchy_pane.h index d39b39bcf9..3472eea5a9 100644 --- a/eeschema/widgets/hierarchy_pane.h +++ b/eeschema/widgets/hierarchy_pane.h @@ -105,10 +105,10 @@ private: */ void onSelectSheetPath( wxTreeEvent& aEvent ); - /** - * Handle a right-click in the tree. - */ - void onRightClick( wxTreeEvent& aEvent ); + void onTreeItemRightClick( wxTreeEvent& aEvent ); + void onRightClick( wxMouseEvent& aEvent ); + void onRightClick( wxTreeItemId aItem ); + void onCharHook( wxKeyEvent& aKeyStroke ); /** * @return String with page number in parenthesis