From 30dbcbbcf5971fd2a91b7e43cd0bfc4f9c5eb711 Mon Sep 17 00:00:00 2001 From: Marek Roszko Date: Tue, 20 Sep 2022 23:38:06 -0400 Subject: [PATCH] Only search the current tab on events --- common/widgets/search_pane.cpp | 26 +++++++++++++++++++++++++- common/widgets/search_pane_tab.cpp | 11 +++++++++-- include/widgets/search_pane.h | 6 +++++- include/widgets/search_pane_tab.h | 3 ++- pcbnew/widgets/pcb_search_pane.cpp | 1 + 5 files changed, 42 insertions(+), 5 deletions(-) diff --git a/common/widgets/search_pane.cpp b/common/widgets/search_pane.cpp index 003d4b4b29..806c92d0d0 100644 --- a/common/widgets/search_pane.cpp +++ b/common/widgets/search_pane.cpp @@ -59,10 +59,19 @@ void SEARCH_PANE::AddSearcher( SEARCH_HANDLER* aHandler ) void SEARCH_PANE::RefreshSearch() +{ + SEARCH_PANE_TAB* tab = GetCurrentTab(); + + if( tab ) + tab->Search( m_lastQuery ); +} + + +void SEARCH_PANE::ClearAllResults() { for( SEARCH_PANE_TAB* tab : m_tabs ) { - tab->Search( m_lastQuery ); + tab->Clear(); } } @@ -79,4 +88,19 @@ void SEARCH_PANE::OnSearchTextEntry( wxCommandEvent& aEvent ) void SEARCH_PANE::FocusSearch() { m_searchCtrl1->SetFocus(); +} + + +void SEARCH_PANE::OnNotebookPageChanged( wxBookCtrlEvent& aEvent ) +{ + SEARCH_PANE_TAB* tab = GetCurrentTab(); + + if( tab ) + tab->Search( m_lastQuery ); +} + + +SEARCH_PANE_TAB* SEARCH_PANE::GetCurrentTab() const +{ + return dynamic_cast( m_notebook->GetCurrentPage() ); } \ No newline at end of file diff --git a/common/widgets/search_pane_tab.cpp b/common/widgets/search_pane_tab.cpp index f4dcc2e501..e8fe1b784f 100644 --- a/common/widgets/search_pane_tab.cpp +++ b/common/widgets/search_pane_tab.cpp @@ -31,11 +31,11 @@ SEARCH_PANE_LISTVIEW::SEARCH_PANE_LISTVIEW( SEARCH_HANDLER* handler, wxWindow* p RefreshColumnNames(); - Bind( wxEVT_LIST_ITEM_SELECTED, &SEARCH_PANE_LISTVIEW::onItemSelected, this ); + Bind( wxEVT_LIST_ITEM_SELECTED, &SEARCH_PANE_LISTVIEW::OnItemSelected, this ); } -void SEARCH_PANE_LISTVIEW::onItemSelected( wxListEvent& aEvent ) +void SEARCH_PANE_LISTVIEW::OnItemSelected( wxListEvent& aEvent ) { long idx = aEvent.GetIndex(); @@ -89,6 +89,13 @@ void SEARCH_PANE_TAB::Search( wxString& query ) } +void SEARCH_PANE_TAB::Clear() +{ + m_listView->SetItemCount( 0 ); + m_listView->Refresh(); +} + + void SEARCH_PANE_TAB::RefreshColumnNames() { m_listView->RefreshColumnNames(); diff --git a/include/widgets/search_pane.h b/include/widgets/search_pane.h index 45750e1c21..cf9ca6a20d 100644 --- a/include/widgets/search_pane.h +++ b/include/widgets/search_pane.h @@ -54,13 +54,17 @@ public: void AddSearcher( SEARCH_HANDLER* aHandler ); void OnSearchTextEntry( wxCommandEvent& aEvent ) override; + void OnNotebookPageChanged( wxBookCtrlEvent& aEvent ) override; void RefreshSearch(); void OnLanguageChange(); void FocusSearch(); + void ClearAllResults(); + +protected: + SEARCH_PANE_TAB* GetCurrentTab() const; private: - EDA_DRAW_FRAME* m_frame; std::vector m_handlers; std::vector m_tabs; diff --git a/include/widgets/search_pane_tab.h b/include/widgets/search_pane_tab.h index c9e71291bf..0382cb838a 100644 --- a/include/widgets/search_pane_tab.h +++ b/include/widgets/search_pane_tab.h @@ -39,7 +39,7 @@ public: protected: wxString OnGetItemText( long item, long column ) const override; - void onItemSelected( wxListEvent& aEvent ); + void OnItemSelected( wxListEvent& aEvent ); private: SEARCH_HANDLER* m_handler; @@ -54,6 +54,7 @@ public: const wxSize& aSize = wxDefaultSize ); void Search( wxString& query ); + void Clear(); void RefreshColumnNames(); SEARCH_HANDLER* GetSearchHandler() const { return m_handler; } diff --git a/pcbnew/widgets/pcb_search_pane.cpp b/pcbnew/widgets/pcb_search_pane.cpp index 29297068b7..2894d2d0ab 100644 --- a/pcbnew/widgets/pcb_search_pane.cpp +++ b/pcbnew/widgets/pcb_search_pane.cpp @@ -67,6 +67,7 @@ void PCB_SEARCH_PANE::onBoardChanged( wxCommandEvent& event ) if( m_brd != nullptr ) m_brd->AddListener( this ); + ClearAllResults(); RefreshSearch(); event.Skip();