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 The 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#include <memory>
23#include <tool/action_menu.h>
25#include <tool/tool_manager.h>
27#include <eda_draw_frame.h>
28#include <bitmaps.h>
29#include <kiway.h>
32
33
34#define ID_TOGGLE_ZOOM_TO_SELECTION 14000
35#define ID_TOGGLE_PAN_TO_SELECTION 14001
36#define ID_TOGGLE_SEARCH_HIDDEN_FIELDS 14002
37#define ID_TOGGLE_SEARCH_METADATA 14003
38
39
41{
42public:
43 SEARCH_PANE_MENU( SEARCH_PANE* aSearchPane, EDA_DRAW_FRAME& aFrame ) :
44 ACTION_MENU( true, nullptr ),
45 m_frame( aFrame ),
46 m_searchPane( aSearchPane )
47 {
48 Add( _( "Zoom to Selection" ), _( "Toggle zooming to selections in the search pane" ),
49 ID_TOGGLE_ZOOM_TO_SELECTION, BITMAPS::zoom_fit_to_objects, true );
50 Add( _( "Pan to Selection" ), _( "Toggle panning to selections in the search pane" ),
51 ID_TOGGLE_PAN_TO_SELECTION, BITMAPS::zoom_center_on_screen, true );
52
53 AppendSeparator();
54 Add( _( "Search Hidden Fields" ), wxEmptyString,
55 ID_TOGGLE_SEARCH_HIDDEN_FIELDS, BITMAPS::invisible_text, true );
56 Add( _( "Search Metadata" ), _( "Search library links, descriptions and keywords" ),
57 ID_TOGGLE_SEARCH_METADATA, BITMAPS::library, true );
58
60 }
61
62 OPT_TOOL_EVENT eventHandler( const wxMenuEvent& aEvent ) override
63 {
65 const int id = aEvent.GetId();
66 const wxMenuItem* item = FindItem( id );
67
68 switch( id )
69 {
74 break;
75
80 break;
81
83 settings.search_hidden_fields = item->IsChecked();
86 break;
87
89 settings.search_metadata = item->IsChecked();
92 break;
93 }
94
95 return OPT_TOOL_EVENT();
96 }
97
98private:
100 {
102
103 wxMenuItem* zoomCb = FindItem( ID_TOGGLE_ZOOM_TO_SELECTION );
104 wxMenuItem* panCb = FindItem( ID_TOGGLE_PAN_TO_SELECTION );
105 wxMenuItem* hiddenFieldsCb = FindItem( ID_TOGGLE_SEARCH_HIDDEN_FIELDS );
106 wxMenuItem* metadataCb = FindItem( ID_TOGGLE_SEARCH_METADATA );
107
110 hiddenFieldsCb->Check( settings.search_hidden_fields );
111 metadataCb->Check( settings.search_metadata );
112 }
113
114private:
117};
118
119
121 SEARCH_PANE_BASE( aFrame ),
122 m_frame( aFrame )
123{
124 m_frame->Bind( EDA_LANG_CHANGED, &SEARCH_PANE::OnLanguageChange, this );
125
126 m_menu = new SEARCH_PANE_MENU( this, *m_frame );
127
128 m_menuButton->SetBitmap( KiBitmapBundle( BITMAPS::config ) );
129 m_menuButton->Bind( wxEVT_LEFT_DOWN,
130 [&]( wxMouseEvent& event )
131 {
132 PopupMenu( m_menu );
133 } );
134
135 m_frame->Bind( wxEVT_AUI_PANE_CLOSE, &SEARCH_PANE::OnClosed, this );
136 Bind( wxEVT_CHAR_HOOK, &SEARCH_PANE::OnCharHook, this );
137}
138
139
141{
142 m_frame->Unbind( wxEVT_AUI_PANE_CLOSE, &SEARCH_PANE::OnClosed, this );
143 m_frame->Unbind( EDA_LANG_CHANGED, &SEARCH_PANE::OnLanguageChange, this );
144 Unbind( wxEVT_CHAR_HOOK, &SEARCH_PANE::OnCharHook, this );
145
146 m_handlers.clear();
147
148 delete m_menu;
149}
150
151
152void SEARCH_PANE::OnLanguageChange( wxCommandEvent& aEvent )
153{
154 m_searchCtrl1->SetDescriptiveText( _( "Search" ) );
155
156 for( size_t i = 0; i < m_notebook->GetPageCount(); ++i )
157 {
158 wxWindow* page = m_notebook->GetPage( i );
159 SEARCH_PANE_TAB* tab = dynamic_cast<SEARCH_PANE_TAB*>( page );
160
161 wxCHECK( tab, /* void */ );
162
163 tab->RefreshColumnNames();
164 m_notebook->SetPageText( i, wxGetTranslation( tab->GetSearchHandler()->GetName() ) );
165 }
166
167 aEvent.Skip();
168}
169
170
171void SEARCH_PANE::AddSearcher( const std::shared_ptr<SEARCH_HANDLER>& aHandler )
172{
173 SEARCH_PANE_TAB* tab = new SEARCH_PANE_TAB( aHandler, m_notebook );
174
175 m_notebook->AddPage( tab, wxGetTranslation( aHandler->GetName() ) );
176 m_handlers.push_back( aHandler );
177 m_tabs.push_back( tab );
178}
179
180
182{
184
185 if( tab )
186 tab->Search( m_lastQuery );
187}
188
189
191{
192 for( SEARCH_PANE_TAB* tab : m_tabs )
193 tab->Clear();
194}
195
196
197void SEARCH_PANE::OnSearchTextEntry( wxCommandEvent& aEvent )
198{
199 m_lastQuery = m_searchCtrl1->GetValue();
200
202}
203
204
206{
207 m_searchCtrl1->SetFocus();
208}
209
210
211void SEARCH_PANE::OnNotebookPageChanged( wxBookCtrlEvent& aEvent )
212{
214
215 if( tab )
216 tab->Search( m_lastQuery );
217}
218
219
220void SEARCH_PANE::OnClosed( wxAuiManagerEvent& aEvent )
221{
222 if( APP_SETTINGS_BASE* cfg = m_frame->config() )
223 m_frame->SaveSettings( cfg );
224
225 aEvent.Skip();
226}
227
228
230{
231 return dynamic_cast<SEARCH_PANE_TAB*>( m_notebook->GetCurrentPage() );
232}
233
234
235void SEARCH_PANE::OnCharHook( wxKeyEvent& aEvent )
236{
237 // Check if the event is from a child window of the search pane
238 wxWindow* eventObject = dynamic_cast<wxWindow*>( aEvent.GetEventObject() );
239
240 if( !eventObject || !IsDescendant( eventObject ) )
241 {
242 aEvent.Skip();
243 return;
244 }
245
246 // Try to let the tool framework handle the event
248 {
250 return;
251 }
252
253 aEvent.Skip();
254}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition: bitmap.cpp:110
Define 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.
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:108
SEARCH_PANE m_SearchPane
Definition: app_settings.h:227
void SetBitmap(const wxBitmapBundle &aBmp)
Set the bitmap shown when the button is enabled.
virtual APP_SETTINGS_BASE * config() const
Return the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
The base class for create windows for drawing purpose.
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
Class SEARCH_PANE_BASE.
wxNotebook * m_notebook
wxSearchCtrl * m_searchCtrl1
BITMAP_BUTTON * m_menuButton
SEARCH_PANE_MENU(SEARCH_PANE *aSearchPane, EDA_DRAW_FRAME &aFrame)
Definition: search_pane.cpp:43
EDA_DRAW_FRAME & m_frame
void updateZoomPanCheckboxes()
Definition: search_pane.cpp:99
OPT_TOOL_EVENT eventHandler(const wxMenuEvent &aEvent) override
Event handler stub.
Definition: search_pane.cpp:62
SEARCH_PANE * m_searchPane
void Search(wxString &query)
std::shared_ptr< SEARCH_HANDLER > GetSearchHandler() const
void RefreshSearch()
void OnSearchTextEntry(wxCommandEvent &aEvent) override
void OnNotebookPageChanged(wxBookCtrlEvent &aEvent) override
void OnCharHook(wxKeyEvent &aEvent)
std::vector< SEARCH_PANE_TAB * > m_tabs
Definition: search_pane.h:93
void OnLanguageChange(wxCommandEvent &aEvent)
EDA_DRAW_FRAME * m_frame
Definition: search_pane.h:95
void AddSearcher(const std::shared_ptr< SEARCH_HANDLER > &aHandler)
SEARCH_PANE(EDA_DRAW_FRAME *aFrame)
SEARCH_PANE_TAB * GetCurrentTab() const
ACTION_MENU * m_menu
Definition: search_pane.h:96
std::vector< std::shared_ptr< SEARCH_HANDLER > > m_handlers
Definition: search_pane.h:92
virtual ~SEARCH_PANE()
void ClearAllResults()
void FocusSearch()
wxString m_lastQuery
Definition: search_pane.h:94
void OnClosed(wxAuiManagerEvent &aEvent)
TOOL_DISPATCHER * GetToolDispatcher() const
Definition: tools_holder.h:57
virtual void DispatchWxEvent(wxEvent &aEvent)
Process wxEvents (mostly UI events), translate them to TOOL_EVENTs, and make tools handle those.
#define _(s)
#define ID_TOGGLE_ZOOM_TO_SELECTION
Definition: search_pane.cpp:34
#define ID_TOGGLE_SEARCH_HIDDEN_FIELDS
Definition: search_pane.cpp:36
#define ID_TOGGLE_PAN_TO_SELECTION
Definition: search_pane.cpp:35
#define ID_TOGGLE_SEARCH_METADATA
Definition: search_pane.cpp:37
std::optional< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:633