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
35
37{
38public:
40 ACTION_MENU( true, nullptr ),
41 m_frame( aFrame )
42 {
43 Add( _( "Zoom to Selection" ), _( "Toggle zooming to selections in the search pane" ),
44 ID_TOGGLE_ZOOM_TO_SELECTION, BITMAPS::zoom_fit_to_objects, true );
45 Add( _( "Pan to Selection" ), _( "Toggle panning to selections in the search pane" ),
46 ID_TOGGLE_PAN_TO_SELECTION, BITMAPS::zoom_center_on_screen, true );
47
49 }
50
51 OPT_TOOL_EVENT eventHandler( const wxMenuEvent& aEvent ) override
52 {
54 const int id = aEvent.GetId();
55 const wxMenuItem* item = FindItem( id );
56
57 switch( id )
58 {
60 settings.selection_zoom =
64 break;
66 settings.selection_zoom =
70 break;
71 }
72 return OPT_TOOL_EVENT();
73 }
74
75private:
77 {
79
80 wxMenuItem* zoomCb = FindItem( ID_TOGGLE_ZOOM_TO_SELECTION );
81 wxMenuItem* panCb = FindItem( ID_TOGGLE_PAN_TO_SELECTION );
82
83 zoomCb->Check( settings.selection_zoom
85 panCb->Check( settings.selection_zoom
87 }
88
89private:
91};
92
93
95 SEARCH_PANE_BASE( aFrame ),
96 m_frame( aFrame )
97{
98 m_frame->Bind( EDA_LANG_CHANGED, &SEARCH_PANE::OnLanguageChange, this );
99
101
102 m_menuButton->SetBitmap( KiBitmapBundle( BITMAPS::config ) );
103 m_menuButton->Bind( wxEVT_LEFT_DOWN,
104 [&]( wxMouseEvent& event )
105 {
106 PopupMenu( m_menu );
107 } );
108}
109
110
112{
113 m_frame->Unbind( EDA_LANG_CHANGED, &SEARCH_PANE::OnLanguageChange, this );
114
115 delete m_menu;
116}
117
118
119void SEARCH_PANE::OnLanguageChange( wxCommandEvent& aEvent )
120{
121 m_searchCtrl1->SetDescriptiveText( _( "Search" ) );
122
123 for( size_t i = 0; i < m_notebook->GetPageCount(); ++i )
124 {
125 wxWindow* page = m_notebook->GetPage( i );
126 SEARCH_PANE_TAB* tab = dynamic_cast<SEARCH_PANE_TAB*>( page );
127
128 wxCHECK( tab, /* void */ );
129
130 tab->RefreshColumnNames();
131 m_notebook->SetPageText( i, wxGetTranslation( tab->GetSearchHandler()->GetName() ) );
132 }
133
134 aEvent.Skip();
135}
136
137
139{
140 SEARCH_PANE_TAB* tab = new SEARCH_PANE_TAB( aHandler, m_notebook );
141
142 m_notebook->AddPage( tab, wxGetTranslation( aHandler->GetName() ) );
143 m_handlers.push_back( aHandler );
144 m_tabs.push_back( tab );
145}
146
147
149{
151
152 if( tab )
153 tab->Search( m_lastQuery );
154}
155
156
158{
159 for( SEARCH_PANE_TAB* tab : m_tabs )
160 tab->Clear();
161}
162
163
164void SEARCH_PANE::OnSearchTextEntry( wxCommandEvent& aEvent )
165{
166 wxString query = m_searchCtrl1->GetValue();
167 m_lastQuery = query;
168
170}
171
172
174{
175 m_searchCtrl1->SetFocus();
176}
177
178
179void SEARCH_PANE::OnNotebookPageChanged( wxBookCtrlEvent& aEvent )
180{
182
183 if( tab )
184 tab->Search( m_lastQuery );
185}
186
187
188void SEARCH_PANE::OnSize( wxSizeEvent& aEvent )
189{
190 if( APP_SETTINGS_BASE* cfg = m_frame->config() )
191 m_frame->SaveSettings( cfg );
192
193 aEvent.Skip();
194}
195
196
198{
199 return dynamic_cast<SEARCH_PANE_TAB*>( m_notebook->GetCurrentPage() );
200}
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:92
SEARCH_PANE m_SearchPane
Definition: app_settings.h:190
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:44
Class SEARCH_PANE_BASE.
wxNotebook * m_notebook
wxSearchCtrl * m_searchCtrl1
STD_BITMAP_BUTTON * m_menuButton
EDA_DRAW_FRAME & m_frame
Definition: search_pane.cpp:90
SEARCH_PANE_MENU(EDA_DRAW_FRAME &aFrame)
Definition: search_pane.cpp:39
void updateZoomPanCheckboxes()
Definition: search_pane.cpp:76
OPT_TOOL_EVENT eventHandler(const wxMenuEvent &aEvent) override
Event handler stub.
Definition: search_pane.cpp:51
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:85
void OnLanguageChange(wxCommandEvent &aEvent)
EDA_DRAW_FRAME * m_frame
Definition: search_pane.h:87
SEARCH_PANE(EDA_DRAW_FRAME *aFrame)
Definition: search_pane.cpp:94
SEARCH_PANE_TAB * GetCurrentTab() const
ACTION_MENU * m_menu
Definition: search_pane.h:88
virtual ~SEARCH_PANE()
std::vector< SEARCH_HANDLER * > m_handlers
Definition: search_pane.h:84
void ClearAllResults()
void FocusSearch()
wxString m_lastQuery
Definition: search_pane.h:86
void OnSize(wxSizeEvent &aEvent) override
void SetBitmap(const wxBitmapBundle &aBmp)
#define _(s)
#define ID_TOGGLE_ZOOM_TO_SELECTION
Definition: search_pane.cpp:32
#define ID_TOGGLE_PAN_TO_SELECTION
Definition: search_pane.cpp:33
std::optional< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:633