KiCad PCB EDA Suite
Loading...
Searching...
No Matches
search_pane.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2022-2023 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "widgets/search_pane.h"
21
22
23#include <tool/action_menu.h>
25#include <eda_draw_frame.h>
26#include <bitmaps.h>
27#include <kiway.h>
29
30
31#define ID_TOGGLE_ZOOM_TO_SELECTION 14000
32#define ID_TOGGLE_PAN_TO_SELECTION 14001
33
34
36{
37public:
38 SEARCH_PANE_MENU( EDA_DRAW_FRAME& aFrame ) : ACTION_MENU( true, nullptr ), m_frame( aFrame )
39 {
40 Add( _( "Zoom to Selection" ), _( "Toggle zooming to selections in the search pane" ),
41 ID_TOGGLE_ZOOM_TO_SELECTION, BITMAPS::zoom_fit_to_objects, true );
42 Add( _( "Pan to Selection" ), _( "Toggle panning to selections in the search pane" ),
43 ID_TOGGLE_PAN_TO_SELECTION, BITMAPS::zoom_center_on_screen, true );
44
46 }
47
48
49 OPT_TOOL_EVENT eventHandler( const wxMenuEvent& aEvent ) override
50 {
52 const int id = aEvent.GetId();
53 const wxMenuItem* item = FindItem( id );
54
55 switch( id )
56 {
58 settings.selection_zoom =
62 break;
64 settings.selection_zoom =
68 break;
69 }
70 return OPT_TOOL_EVENT();
71 }
72
73private:
75 {
77
78 wxMenuItem* zoomCb = FindItem( ID_TOGGLE_ZOOM_TO_SELECTION );
79 wxMenuItem* panCb = FindItem( ID_TOGGLE_PAN_TO_SELECTION );
80
81 zoomCb->Check( settings.selection_zoom
83 panCb->Check( settings.selection_zoom
85 }
86
88};
89
90
92 SEARCH_PANE_BASE( aFrame ),
93 m_frame( aFrame )
94{
95 m_frame->Bind( EDA_LANG_CHANGED, &SEARCH_PANE::OnLanguageChange, this );
96
98
99 m_menuButton->SetBitmap( KiBitmapBundle( BITMAPS::config ) );
100 m_menuButton->Bind( wxEVT_LEFT_DOWN,
101 [&]( wxMouseEvent& event )
102 {
103 PopupMenu( m_menu );
104 } );
105}
106
107
109{
110 m_frame->Unbind( EDA_LANG_CHANGED, &SEARCH_PANE::OnLanguageChange, this );
111
112 delete m_menu;
113}
114
115
116void SEARCH_PANE::OnLanguageChange( wxCommandEvent& aEvent )
117{
118 m_searchCtrl1->SetDescriptiveText( _( "Search" ) );
119
120 for( size_t i = 0; i < m_notebook->GetPageCount(); ++i )
121 {
122 wxWindow* page = m_notebook->GetPage( i );
123 SEARCH_PANE_TAB* tab = dynamic_cast<SEARCH_PANE_TAB*>( page );
124
125 wxCHECK( tab, /* void */ );
126
127 tab->RefreshColumnNames();
128 m_notebook->SetPageText( i, wxGetTranslation( tab->GetSearchHandler()->GetName() ) );
129 }
130
131 aEvent.Skip();
132}
133
134
136{
137 SEARCH_PANE_TAB* tab = new SEARCH_PANE_TAB( aHandler, m_notebook );
138
139 m_notebook->AddPage( tab, wxGetTranslation( aHandler->GetName() ) );
140 m_handlers.push_back( aHandler );
141 m_tabs.push_back( tab );
142}
143
144
146{
148
149 if( tab )
150 tab->Search( m_lastQuery );
151}
152
153
155{
156 for( SEARCH_PANE_TAB* tab : m_tabs )
157 {
158 tab->Clear();
159 }
160}
161
162
163void SEARCH_PANE::OnSearchTextEntry( wxCommandEvent& aEvent )
164{
165 wxString query = m_searchCtrl1->GetValue();
166 m_lastQuery = query;
167
169}
170
171
173{
174 m_searchCtrl1->SetFocus();
175}
176
177
178void SEARCH_PANE::OnNotebookPageChanged( wxBookCtrlEvent& aEvent )
179{
181
182 if( tab )
183 tab->Search( m_lastQuery );
184}
185
186
188{
189 return dynamic_cast<SEARCH_PANE_TAB*>( m_notebook->GetCurrentPage() );
190}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
Definition: bitmap.cpp:110
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:49
wxMenuItem * Add(const wxString &aLabel, int aId, BITMAPS aIcon)
Add a wxWidgets-style entry to the menu.
SEARCH_PANE m_SearchPane
Definition: app_settings.h:182
virtual APP_SETTINGS_BASE * config() const
Returns the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
The base class for create windows for drawing purpose.
wxString GetName() const
Definition: search_pane.h:41
Class SEARCH_PANE_BASE.
wxNotebook * m_notebook
wxSearchCtrl * m_searchCtrl1
wxBitmapButton * m_menuButton
EDA_DRAW_FRAME & m_frame
Definition: search_pane.cpp:87
SEARCH_PANE_MENU(EDA_DRAW_FRAME &aFrame)
Definition: search_pane.cpp:38
void updateZoomPanCheckboxes()
Definition: search_pane.cpp:74
OPT_TOOL_EVENT eventHandler(const wxMenuEvent &aEvent) override
Event handler stub.
Definition: search_pane.cpp:49
void Search(wxString &query)
SEARCH_HANDLER * GetSearchHandler() const
void RefreshSearch()
void AddSearcher(SEARCH_HANDLER *aHandler)
void OnSearchTextEntry(wxCommandEvent &aEvent) override
void OnNotebookPageChanged(wxBookCtrlEvent &aEvent) override
std::vector< SEARCH_PANE_TAB * > m_tabs
Definition: search_pane.h:87
void OnLanguageChange(wxCommandEvent &aEvent)
EDA_DRAW_FRAME * m_frame
Definition: search_pane.h:89
SEARCH_PANE(EDA_DRAW_FRAME *aFrame)
Definition: search_pane.cpp:91
SEARCH_PANE_TAB * GetCurrentTab() const
ACTION_MENU * m_menu
Definition: search_pane.h:90
virtual ~SEARCH_PANE()
std::vector< SEARCH_HANDLER * > m_handlers
Definition: search_pane.h:86
void ClearAllResults()
void FocusSearch()
wxString m_lastQuery
Definition: search_pane.h:88
#define _(s)
#define ID_TOGGLE_ZOOM_TO_SELECTION
Definition: search_pane.cpp:31
#define ID_TOGGLE_PAN_TO_SELECTION
Definition: search_pane.cpp:32
std::optional< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:629