From 9ce4f0a0b525aaadb22346bbdb249a226e424992 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 26 Sep 2022 21:57:32 +0100 Subject: [PATCH] ADDED setting page number from hierarchy tree. Fixes https://gitlab.com/kicad/code/kicad/issues/8352 --- eeschema/hierarch.cpp | 51 +++++++++++++++++++++++++++++++++++++++++-- eeschema/hierarch.h | 7 +++++- 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/eeschema/hierarch.cpp b/eeschema/hierarch.cpp index 633b8c8dfb..d6dbace83f 100644 --- a/eeschema/hierarch.cpp +++ b/eeschema/hierarch.cpp @@ -36,7 +36,7 @@ #include #include - +#include "wx/generic/textdlgg.h" /** * Store an SCH_SHEET_PATH of each sheet in hierarchy. @@ -98,6 +98,7 @@ HIERARCHY_NAVIG_PANEL::HIERARCHY_NAVIG_PANEL( SCH_EDIT_FRAME* aParent ) : // Enable selection events Bind( wxEVT_TREE_ITEM_ACTIVATED, &HIERARCHY_NAVIG_PANEL::onSelectSheetPath, this ); Bind( wxEVT_TREE_SEL_CHANGED, &HIERARCHY_NAVIG_PANEL::onSelectSheetPath, this ); + Bind( wxEVT_TREE_ITEM_RIGHT_CLICK, &HIERARCHY_NAVIG_PANEL::onRightClick, this ); m_events_bound = true; } @@ -107,6 +108,7 @@ HIERARCHY_NAVIG_PANEL::~HIERARCHY_NAVIG_PANEL() { Unbind( wxEVT_TREE_ITEM_ACTIVATED, &HIERARCHY_NAVIG_PANEL::onSelectSheetPath, this ); Unbind( wxEVT_TREE_SEL_CHANGED, &HIERARCHY_NAVIG_PANEL::onSelectSheetPath, this ); + Unbind( wxEVT_TREE_ITEM_RIGHT_CLICK, &HIERARCHY_NAVIG_PANEL::onRightClick, this ); } @@ -142,6 +144,7 @@ void HIERARCHY_NAVIG_PANEL::UpdateHierarchySelection() // Disable selection events Unbind( wxEVT_TREE_ITEM_ACTIVATED, &HIERARCHY_NAVIG_PANEL::onSelectSheetPath, this ); Unbind( wxEVT_TREE_SEL_CHANGED, &HIERARCHY_NAVIG_PANEL::onSelectSheetPath, this ); + Unbind( wxEVT_TREE_ITEM_RIGHT_CLICK, &HIERARCHY_NAVIG_PANEL::onRightClick, this ); m_events_bound = false; } @@ -175,6 +178,7 @@ void HIERARCHY_NAVIG_PANEL::UpdateHierarchySelection() // Enable selection events Bind( wxEVT_TREE_ITEM_ACTIVATED, &HIERARCHY_NAVIG_PANEL::onSelectSheetPath, this ); Bind( wxEVT_TREE_SEL_CHANGED, &HIERARCHY_NAVIG_PANEL::onSelectSheetPath, this ); + Bind( wxEVT_TREE_ITEM_RIGHT_CLICK, &HIERARCHY_NAVIG_PANEL::onRightClick, this ); m_events_bound = true; } @@ -192,6 +196,7 @@ void HIERARCHY_NAVIG_PANEL::UpdateHierarchyTree() // Disable selection events Unbind( wxEVT_TREE_ITEM_ACTIVATED, &HIERARCHY_NAVIG_PANEL::onSelectSheetPath, this ); Unbind( wxEVT_TREE_SEL_CHANGED, &HIERARCHY_NAVIG_PANEL::onSelectSheetPath, this ); + Unbind( wxEVT_TREE_ITEM_RIGHT_CLICK, &HIERARCHY_NAVIG_PANEL::onRightClick, this ); m_events_bound = false; } @@ -215,6 +220,7 @@ void HIERARCHY_NAVIG_PANEL::UpdateHierarchyTree() // Enable selection events Bind( wxEVT_TREE_ITEM_ACTIVATED, &HIERARCHY_NAVIG_PANEL::onSelectSheetPath, this ); Bind( wxEVT_TREE_SEL_CHANGED, &HIERARCHY_NAVIG_PANEL::onSelectSheetPath, this ); + Bind( wxEVT_TREE_ITEM_RIGHT_CLICK, &HIERARCHY_NAVIG_PANEL::onRightClick, this ); m_events_bound = true; } @@ -223,7 +229,7 @@ void HIERARCHY_NAVIG_PANEL::UpdateHierarchyTree() } -void HIERARCHY_NAVIG_PANEL::onSelectSheetPath( wxTreeEvent& event ) +void HIERARCHY_NAVIG_PANEL::onSelectSheetPath( wxTreeEvent& aEvent ) { wxTreeItemId itemSel = m_tree->GetSelection(); TREE_ITEM_DATA* itemData = static_cast( m_tree->GetItemData( itemSel ) ); @@ -234,6 +240,47 @@ void HIERARCHY_NAVIG_PANEL::onSelectSheetPath( wxTreeEvent& event ) } +void HIERARCHY_NAVIG_PANEL::onRightClick( wxTreeEvent& aEvent ) +{ + wxMenu ctxMenu; + + ctxMenu.Append( 1, _( "Edit Page Number" ) ); + + if( GetPopupMenuSelectionFromUser( ctxMenu ) == 1 ) + { + wxTreeItemId itemSel = m_tree->GetSelection(); + TREE_ITEM_DATA* itemData = static_cast( m_tree->GetItemData( itemSel ) ); + + wxString msg; + wxString sheetPath = itemData->m_SheetPath.PathHumanReadable( false ); + wxString pageNumber = itemData->m_SheetPath.GetPageNumber(); + + msg.Printf( _( "Enter page number for sheet path%s" ), + ( sheetPath.Length() > 20 ) ? "\n" + sheetPath : " " + sheetPath ); + + wxTextEntryDialog dlg( m_frame, msg, _( "Edit Sheet Page Number" ), pageNumber ); + + dlg.SetTextValidator( wxFILTER_ALPHANUMERIC ); // No white space. + + if( dlg.ShowModal() == wxID_OK && dlg.GetValue() != itemData->m_SheetPath.GetPageNumber() ) + { + m_frame->SaveCopyInUndoList( itemData->m_SheetPath.LastScreen(), + itemData->m_SheetPath.Last(), UNDO_REDO::CHANGED, false ); + + itemData->m_SheetPath.SetPageNumber( dlg.GetValue() ); + + if( itemData->m_SheetPath == m_frame->GetCurrentSheet() ) + { + m_frame->GetScreen()->SetPageNumber( dlg.GetValue() ); + m_frame->OnPageSettingsChange(); + } + + m_frame->OnModify(); + } + } +} + + wxString HIERARCHY_NAVIG_PANEL::getRootString() { SCH_SHEET* rootSheet = &m_frame->Schematic().Root(); diff --git a/eeschema/hierarch.h b/eeschema/hierarch.h index 9e9f5afa21..b7e23432ee 100644 --- a/eeschema/hierarch.h +++ b/eeschema/hierarch.h @@ -96,7 +96,12 @@ private: * Open the selected sheet and display the corresponding screen when a tree item is * selected. */ - void onSelectSheetPath( wxTreeEvent& event ); + void onSelectSheetPath( wxTreeEvent& aEvent ); + + /** + * Handle a right-click in the tree. + */ + void onRightClick( wxTreeEvent& aEvent ); /** * @return String with page number in parenthesis