KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_sch_find.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) 2010 Wayne Stambaugh <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#include <dialog_sch_find.h>
26#include <tool/actions.h>
27#include <sch_edit_frame.h>
29
30
32 const wxPoint& aPosition, const wxSize& aSize, int aStyle ) :
33 DIALOG_SCH_FIND_BASE( aParent, wxID_ANY, _( "Find" ), aPosition, aSize,
34 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | aStyle ),
35 m_frame( aParent ),
36 m_findReplaceTool( m_frame->GetToolManager()->GetTool<SCH_FIND_REPLACE_TOOL>() ),
37 m_findReplaceData( aData ),
38 m_findDirty( true )
39{
40 wxASSERT_MSG( m_findReplaceData, wxT( "can't create find dialog without data" ) );
41
42 if( aStyle & wxFR_REPLACEDIALOG )
43 {
44 SetTitle( _( "Find and Replace" ) );
45 m_buttonReplace->Show( true );
46 m_buttonReplaceAll->Show( true );
47 m_staticReplace->Show( true );
48 m_comboReplace->Show( true );
49 m_cbSelectedOnly->Show( true );
50 m_cbReplaceReferences->Show( true );
51 m_checkRegexMatch->Show( true );
52 }
53
54 if( m_frame->GetFrameType() == FRAME_SCH_SYMBOL_EDITOR )
55 {
56 m_findReplaceData->searchAllPins = true;
57
59 m_cbSearchPins->Hide();
60 m_cbSearchNetNames->Hide();
62
63 m_staticline1->Hide();
64 m_searchPanelLink->Hide();
65 }
66
67 m_checkMatchCase->SetValue( m_findReplaceData->matchCase );
70
71 m_cbSearchHiddenFields->SetValue( m_findReplaceData->searchAllFields );
72 m_cbReplaceReferences->SetValue( m_findReplaceData->replaceReferences );
73 m_cbSearchPins->SetValue( m_findReplaceData->searchAllPins );
74 m_cbCurrentSheetOnly->SetValue( m_findReplaceData->searchCurrentSheetOnly );
75 m_cbCurrentSheetOnly->Enable( !m_findReplaceData->searchSelectedOnly );
76 m_cbSelectedOnly->SetValue( m_findReplaceData->searchSelectedOnly );
77 m_cbSearchNetNames->SetValue( m_findReplaceData->searchNetNames );
78
79 if( int hotkey = ACTIONS::showSearch.GetHotKey() )
80 {
81 wxString hotkeyHint = wxString::Format( wxT( " (%s)" ), KeyNameFromKeyCode( hotkey ) );
82 m_searchPanelLink->SetLabel( m_searchPanelLink->GetLabel() + hotkeyHint );
83 }
84
85 m_buttonFind->SetDefault();
87
88 // Adjust the height of the dialog to prevent controls from being hidden when
89 // switching between the find and find/replace modes of the dialog. This ignores
90 // the users preferred height if any of the controls would be hidden.
91 GetSizer()->SetSizeHints( this );
92 wxSize size = aSize;
93
94 if( aSize != wxDefaultSize )
95 {
96 wxSize bestSize = GetBestSize();
97
98 if( size.GetHeight() != bestSize.GetHeight() )
99 size.SetHeight( bestSize.GetHeight() );
100 }
101
102 SetSize( size );
103
104 GetSizer()->Fit( this ); // Needed on Ubuntu/Unity to display the dialog
105
106 // Set up tab order for proper keyboard navigation.
107 // This is needed because wxComboBox on GTK has issues with Tab key navigation.
108 m_tabOrder = {
126 };
127}
128
129
130void DIALOG_SCH_FIND::OnClose( wxCloseEvent& aEvent )
131{
132 // Notify the SCH_BASE_FRAME
133 m_frame->OnFindDialogClose();
134}
135
136
137void DIALOG_SCH_FIND::OnIdle( wxIdleEvent& aEvent )
138{
139 if( m_findDirty )
140 {
141 m_findReplaceTool->UpdateFind( ACTIONS::updateFind.MakeEvent() );
142 m_findDirty = false;
143 }
144}
145
146
147void DIALOG_SCH_FIND::OnCancel( wxCommandEvent& aEvent )
148{
149 wxCloseEvent dummy;
150 OnClose( dummy );
151}
152
153
154void DIALOG_SCH_FIND::onShowSearchPanel( wxHyperlinkEvent& event )
155{
156 wxCHECK2( m_frame->GetFrameType() == FRAME_SCH, /* void */ );
157
158 m_frame->GetToolManager()->RunAction( ACTIONS::showSearch );
159
160 EndModal( wxID_CANCEL );
161
162 CallAfter(
163 []()
164 {
165 if( wxWindow* frame = wxWindow::FindWindowByName( SCH_EDIT_FRAME_NAME ) )
166 static_cast<SCH_EDIT_FRAME*>( frame )->FocusSearch();
167 } );
168}
169
170
171void DIALOG_SCH_FIND::OnUpdateReplaceUI( wxUpdateUIEvent& aEvent )
172{
173 aEvent.Enable( HasFlag( wxFR_REPLACEDIALOG ) && !m_comboFind->GetValue().empty()
174 && m_findReplaceTool->HasMatch() );
175}
176
177
178void DIALOG_SCH_FIND::OnUpdateReplaceAllUI( wxUpdateUIEvent& aEvent )
179{
180 aEvent.Enable( HasFlag( wxFR_REPLACEDIALOG ) && !m_comboFind->GetValue().empty() );
181}
182
183
184void DIALOG_SCH_FIND::OnSearchForText( wxCommandEvent& aEvent )
185{
186 m_findReplaceData->findString = m_comboFind->GetValue();
187 m_findDirty = true;
188}
189
190
191void DIALOG_SCH_FIND::OnSearchForSelect( wxCommandEvent& aEvent )
192{
193 m_findReplaceData->findString = m_comboFind->GetValue();
194
195 // Move the search string to the top of the list if it isn't already there.
196 if( aEvent.GetSelection() != 0 )
197 {
198 wxString tmp = m_comboFind->GetValue();
199 m_comboFind->Delete( aEvent.GetSelection() );
200 m_comboFind->Insert( tmp, 0 );
201 m_comboFind->SetSelection( 0 );
202 }
203
204 m_findReplaceTool->UpdateFind( ACTIONS::updateFind.MakeEvent() );
205}
206
207
208void DIALOG_SCH_FIND::OnReplaceWithText( wxCommandEvent& aEvent )
209{
210 m_findReplaceData->replaceString = m_comboReplace->GetValue();
211}
212
213
214void DIALOG_SCH_FIND::OnReplaceWithSelect( wxCommandEvent& aEvent )
215{
216 m_findReplaceData->replaceString = m_comboReplace->GetValue();
217
218 // Move the replace string to the top of the list if it isn't already there.
219 if( aEvent.GetSelection() != 0 )
220 {
221 wxString tmp = m_comboReplace->GetValue();
222 m_comboReplace->Delete( aEvent.GetSelection() );
223 m_comboReplace->Insert( tmp, 0 );
224 m_comboReplace->SetSelection( 0 );
225 }
226}
227
228
229void DIALOG_SCH_FIND::OnSearchForEnter( wxCommandEvent& aEvent )
230{
231 OnFind( aEvent );
232}
233
234
235void DIALOG_SCH_FIND::OnReplaceWithEnter( wxCommandEvent& aEvent )
236{
237 OnFind( aEvent );
238}
239
240
241void DIALOG_SCH_FIND::OnOptions( wxCommandEvent& aEvent )
242{
243 updateFlags();
244 m_findDirty = true;
245}
246
248{
249 // Rebuild the search flags in m_findReplaceData from dialog settings
250 m_findReplaceData->matchCase = m_checkMatchCase->GetValue();
251 m_findReplaceData->searchAllFields = m_cbSearchHiddenFields->GetValue();
252 m_findReplaceData->searchAllPins = m_cbSearchPins->GetValue();
253 m_findReplaceData->searchCurrentSheetOnly = m_cbCurrentSheetOnly->GetValue();
254 m_findReplaceData->replaceReferences = m_cbReplaceReferences->GetValue();
255 m_findReplaceData->searchNetNames = m_cbSearchNetNames->GetValue();
256
257 if( m_checkWholeWord->GetValue() )
259 else if( m_checkRegexMatch->IsShown() && m_checkRegexMatch->GetValue() )
261 else
263
264 if( m_cbSelectedOnly->GetValue() )
265 {
266 m_cbCurrentSheetOnly->SetValue( true );
267 m_cbCurrentSheetOnly->Enable( false );
268 m_findReplaceData->searchSelectedOnly = true;
269 }
270 else
271 {
272 m_cbCurrentSheetOnly->Enable( true );
273 m_findReplaceData->searchSelectedOnly = false;
274 }
275}
276
277
278void DIALOG_SCH_FIND::OnFind( wxCommandEvent& aEvent )
279{
280 updateFlags(); // Ensure search flags are up to date
281
282 int index = m_comboFind->FindString( m_comboFind->GetValue(), true );
283
284 if( index == wxNOT_FOUND )
285 {
286 m_comboFind->Insert( m_comboFind->GetValue(), 0 );
287 }
288 else if( index != 0 )
289 {
290 /* Move the search string to the top of the list if it isn't already there. */
291 wxString tmp = m_comboFind->GetValue();
292 m_comboFind->Delete( index );
293 m_comboFind->Insert( tmp, 0 );
294 m_comboFind->SetSelection( 0 );
295 }
296
297 m_findReplaceTool->FindNext( ACTIONS::findNext.MakeEvent() );
298}
299
300
301void DIALOG_SCH_FIND::OnReplace( wxCommandEvent& aEvent )
302{
303 updateFlags(); // Ensure search flags are up to date
304
305 int index = m_comboReplace->FindString( m_comboReplace->GetValue(), true );
306
307 if( index == wxNOT_FOUND )
308 {
309 m_comboReplace->Insert( m_comboReplace->GetValue(), 0 );
310 }
311 else if( index != 0 )
312 {
313 /* Move the search string to the top of the list if it isn't already there. */
314 wxString tmp = m_comboReplace->GetValue();
315 m_comboReplace->Delete( index );
316 m_comboReplace->Insert( tmp, 0 );
317 m_comboReplace->SetSelection( 0 );
318 }
319
320 if( aEvent.GetId() == wxID_REPLACE )
321 m_findReplaceTool->ReplaceAndFindNext( ACTIONS::replaceAndFindNext.MakeEvent() );
322 else if( aEvent.GetId() == wxID_REPLACE_ALL )
323 m_findReplaceTool->ReplaceAll( ACTIONS::replaceAll.MakeEvent() );
324}
325
326
328{
329 int index = m_comboFind->FindString( m_comboFind->GetValue(), true );
330
331 if( index == wxNOT_FOUND )
332 {
333 m_comboFind->Insert( m_comboFind->GetValue(), 0 );
334 }
335 else if( index != 0 )
336 {
337 /* Move the search string to the top of the list if it isn't already there. */
338 wxString tmp = m_comboFind->GetValue();
339 m_comboFind->Delete( index );
340 m_comboFind->Insert( tmp, 0 );
341 }
342
343 return m_comboFind->GetStrings();
344}
345
346
347void DIALOG_SCH_FIND::SetFindEntries( const wxArrayString& aEntries, const wxString& aFindString )
348{
349 m_comboFind->Append( aEntries );
350
351 while( m_comboFind->GetCount() > 10 )
352 {
353 m_frame->GetFindHistoryList().pop_back();
354 m_comboFind->Delete( 9 );
355 }
356
357 if( !aFindString.IsEmpty() )
358 {
359 m_comboFind->SetValue( aFindString );
360 m_comboFind->SelectAll();
361 }
362 else if( m_comboFind->GetCount() )
363 {
364 m_comboFind->SetSelection( 0 );
365 m_comboFind->SelectAll();
366 }
367}
368
369
370void DIALOG_SCH_FIND::SetReplaceEntries( const wxArrayString& aEntries )
371{
372 m_comboReplace->Append( aEntries );
373
374 while( m_comboReplace->GetCount() > 10 )
375 {
376 m_frame->GetFindHistoryList().pop_back();
377 m_comboReplace->Delete( 9 );
378 }
379
380 if( m_comboReplace->GetCount() )
381 {
382 m_comboReplace->SetSelection( 0 );
383 m_comboFind->SelectAll();
384 }
385}
int index
static TOOL_ACTION replaceAll
Definition actions.h:123
static TOOL_ACTION updateFind
Definition actions.h:124
static TOOL_ACTION replaceAndFindNext
Definition actions.h:122
static TOOL_ACTION findNext
Definition actions.h:119
static TOOL_ACTION showSearch
Definition actions.h:116
wxCheckBox * m_cbSearchHiddenFields
wxRadioButton * m_radioForward
DIALOG_SCH_FIND_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Find"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
wxHyperlinkCtrl * m_searchPanelLink
wxRadioButton * m_radioBackward
void OnSearchForSelect(wxCommandEvent &aEvent) override
void OnReplaceWithEnter(wxCommandEvent &event) override
wxArrayString GetFindEntries() const
void OnIdle(wxIdleEvent &event) override
SCH_FIND_REPLACE_TOOL * m_findReplaceTool
SCH_SEARCH_DATA * m_findReplaceData
SCH_BASE_FRAME * m_frame
void OnUpdateReplaceUI(wxUpdateUIEvent &aEvent) override
void SetReplaceEntries(const wxArrayString &aEntries)
void SetFindEntries(const wxArrayString &aEntries, const wxString &aFindString)
void OnReplaceWithText(wxCommandEvent &aEvent) override
void OnReplaceWithSelect(wxCommandEvent &aEvent) override
DIALOG_SCH_FIND(SCH_BASE_FRAME *aParent, SCH_SEARCH_DATA *aData, const wxPoint &aPosition=wxDefaultPosition, const wxSize &aSize=wxDefaultSize, int aStyle=0)
void OnUpdateReplaceAllUI(wxUpdateUIEvent &aEvent) override
void OnSearchForText(wxCommandEvent &aEvent) override
void OnClose(wxCloseEvent &aEvent) override
void OnReplace(wxCommandEvent &aEvent) override
void OnSearchForEnter(wxCommandEvent &event) override
void OnFind(wxCommandEvent &aEvent) override
void OnCancel(wxCommandEvent &aEvent) override
void OnOptions(wxCommandEvent &event) override
void onShowSearchPanel(wxHyperlinkEvent &event) override
std::vector< wxWindow * > m_tabOrder
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition dialog_shim.h:82
A shim class between EDA_DRAW_FRAME and several derived classes: SYMBOL_EDIT_FRAME,...
Schematic editor (Eeschema) main window.
Handle actions specific to the schematic editor.
#define _(s)
#define SCH_EDIT_FRAME_NAME
@ FRAME_SCH_SYMBOL_EDITOR
Definition frame_type.h:35
@ FRAME_SCH
Definition frame_type.h:34
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Return the key name from the key code.
std::vector< FAB_LAYER_COLOR > dummy