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
23#include <tool/action_menu.h>
25#include <eda_draw_frame.h>
26#include <bitmaps.h>
27#include <kiway.h>
30
31
32#define ID_TOGGLE_ZOOM_TO_SELECTION 14000
33#define ID_TOGGLE_PAN_TO_SELECTION 14001
34#define ID_TOGGLE_SEARCH_HIDDEN_FIELDS 14002
35#define ID_TOGGLE_SEARCH_METADATA 14003
36
37
39{
40public:
41 SEARCH_PANE_MENU( SEARCH_PANE* aSearchPane, EDA_DRAW_FRAME& aFrame ) :
42 ACTION_MENU( true, nullptr ),
43 m_frame( aFrame ),
44 m_searchPane( aSearchPane )
45 {
46 Add( _( "Zoom to Selection" ), _( "Toggle zooming to selections in the search pane" ),
47 ID_TOGGLE_ZOOM_TO_SELECTION, BITMAPS::zoom_fit_to_objects, true );
48 Add( _( "Pan to Selection" ), _( "Toggle panning to selections in the search pane" ),
49 ID_TOGGLE_PAN_TO_SELECTION, BITMAPS::zoom_center_on_screen, true );
50
51 AppendSeparator();
52 Add( _( "Search Hidden Fields" ), wxEmptyString,
53 ID_TOGGLE_SEARCH_HIDDEN_FIELDS, BITMAPS::invisible_text, true );
54 Add( _( "Search Metadata" ), _( "Search library links, descriptions and keywords" ),
55 ID_TOGGLE_SEARCH_METADATA, BITMAPS::library, true );
56
58 }
59
60 OPT_TOOL_EVENT eventHandler( const wxMenuEvent& aEvent ) override
61 {
63 const int id = aEvent.GetId();
64 const wxMenuItem* item = FindItem( id );
65
66 switch( id )
67 {
72 break;
73
78 break;
79
81 settings.search_hidden_fields = item->IsChecked();
84 break;
85
87 settings.search_metadata = item->IsChecked();
90 break;
91 }
92
93 return OPT_TOOL_EVENT();
94 }
95
96private:
98 {
100
101 wxMenuItem* zoomCb = FindItem( ID_TOGGLE_ZOOM_TO_SELECTION );
102 wxMenuItem* panCb = FindItem( ID_TOGGLE_PAN_TO_SELECTION );
103 wxMenuItem* hiddenFieldsCb = FindItem( ID_TOGGLE_SEARCH_HIDDEN_FIELDS );
104 wxMenuItem* metadataCb = FindItem( ID_TOGGLE_SEARCH_METADATA );
105
108 hiddenFieldsCb->Check( settings.search_hidden_fields );
109 metadataCb->Check( settings.search_metadata );
110 }
111
112private:
115};
116
117
119 SEARCH_PANE_BASE( aFrame ),
120 m_frame( aFrame )
121{
122 m_frame->Bind( EDA_LANG_CHANGED, &SEARCH_PANE::OnLanguageChange, this );
123
124 m_menu = new SEARCH_PANE_MENU( this, *m_frame );
125
126 m_menuButton->SetBitmap( KiBitmapBundle( BITMAPS::config ) );
127 m_menuButton->Bind( wxEVT_LEFT_DOWN,
128 [&]( wxMouseEvent& event )
129 {
130 PopupMenu( m_menu );
131 } );
132
133 m_frame->Bind( wxEVT_AUI_PANE_CLOSE, &SEARCH_PANE::OnClosed, this );
134}
135
136
138{
139 m_frame->Unbind( wxEVT_AUI_PANE_CLOSE, &SEARCH_PANE::OnClosed, this );
140 m_frame->Unbind( EDA_LANG_CHANGED, &SEARCH_PANE::OnLanguageChange, this );
141
142 delete m_menu;
143}
144
145
146void SEARCH_PANE::OnLanguageChange( wxCommandEvent& aEvent )
147{
148 m_searchCtrl1->SetDescriptiveText( _( "Search" ) );
149
150 for( size_t i = 0; i < m_notebook->GetPageCount(); ++i )
151 {
152 wxWindow* page = m_notebook->GetPage( i );
153 SEARCH_PANE_TAB* tab = dynamic_cast<SEARCH_PANE_TAB*>( page );
154
155 wxCHECK( tab, /* void */ );
156
157 tab->RefreshColumnNames();
158 m_notebook->SetPageText( i, wxGetTranslation( tab->GetSearchHandler()->GetName() ) );
159 }
160
161 aEvent.Skip();
162}
163
164
166{
167 SEARCH_PANE_TAB* tab = new SEARCH_PANE_TAB( aHandler, m_notebook );
168
169 m_notebook->AddPage( tab, wxGetTranslation( aHandler->GetName() ) );
170 m_handlers.push_back( aHandler );
171 m_tabs.push_back( tab );
172}
173
174
176{
178
179 if( tab )
180 tab->Search( m_lastQuery );
181}
182
183
185{
186 for( SEARCH_PANE_TAB* tab : m_tabs )
187 tab->Clear();
188}
189
190
191void SEARCH_PANE::OnSearchTextEntry( wxCommandEvent& aEvent )
192{
193 wxString query = m_searchCtrl1->GetValue();
194 m_lastQuery = query;
195
197}
198
199
201{
202 m_searchCtrl1->SetFocus();
203}
204
205
206void SEARCH_PANE::OnNotebookPageChanged( wxBookCtrlEvent& aEvent )
207{
209
210 if( tab )
211 tab->Search( m_lastQuery );
212}
213
214
215void SEARCH_PANE::OnClosed( wxAuiManagerEvent& aEvent )
216{
217 if( APP_SETTINGS_BASE* cfg = m_frame->config() )
218 m_frame->SaveSettings( cfg );
219
220 aEvent.Skip();
221}
222
223
225{
226 return dynamic_cast<SEARCH_PANE_TAB*>( m_notebook->GetCurrentPage() );
227}
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:226
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.
wxString GetName() const
Definition: search_pane.h:45
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:41
EDA_DRAW_FRAME & m_frame
void updateZoomPanCheckboxes()
Definition: search_pane.cpp:97
OPT_TOOL_EVENT eventHandler(const wxMenuEvent &aEvent) override
Event handler stub.
Definition: search_pane.cpp:60
SEARCH_PANE * m_searchPane
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:86
void OnLanguageChange(wxCommandEvent &aEvent)
EDA_DRAW_FRAME * m_frame
Definition: search_pane.h:88
SEARCH_PANE(EDA_DRAW_FRAME *aFrame)
SEARCH_PANE_TAB * GetCurrentTab() const
ACTION_MENU * m_menu
Definition: search_pane.h:89
virtual ~SEARCH_PANE()
std::vector< SEARCH_HANDLER * > m_handlers
Definition: search_pane.h:85
void ClearAllResults()
void FocusSearch()
wxString m_lastQuery
Definition: search_pane.h:87
void OnClosed(wxAuiManagerEvent &aEvent)
#define _(s)
#define ID_TOGGLE_ZOOM_TO_SELECTION
Definition: search_pane.cpp:32
#define ID_TOGGLE_SEARCH_HIDDEN_FIELDS
Definition: search_pane.cpp:34
#define ID_TOGGLE_PAN_TO_SELECTION
Definition: search_pane.cpp:33
#define ID_TOGGLE_SEARCH_METADATA
Definition: search_pane.cpp:35
std::optional< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:633