KiCad PCB EDA Suite
dialog_schematic_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 (C) 2010-2019 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
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_editorControl( m_frame->GetToolManager()->GetTool<SCH_EDITOR_CONTROL>() ),
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_checkReplaceReferences->Show( true );
50 m_checkWildcardMatch->Show( false ); // Wildcard replace is not implemented.
51 }
52
57
62
63 m_buttonFind->SetDefault();
65
66 // Adjust the height of the dialog to prevent controls from being hidden when
67 // switching between the find and find/replace modes of the dialog. This ignores
68 // the users preferred height if any of the controls would be hidden.
69 GetSizer()->SetSizeHints( this );
70 wxSize size = aSize;
71
72 if( aSize != wxDefaultSize )
73 {
74 wxSize bestSize = GetBestSize();
75
76 if( size.GetHeight() != bestSize.GetHeight() )
77 size.SetHeight( bestSize.GetHeight() );
78 }
79
80 SetSize( size );
81
82 GetSizer()->Fit( this ); // Needed on Ubuntu/Unity to display the dialog
83
84 Connect( wxEVT_CHAR, wxKeyEventHandler( DIALOG_SCH_FIND::OnChar ), nullptr, this );
85}
86
87
88void DIALOG_SCH_FIND::OnClose( wxCloseEvent& aEvent )
89{
90 // Notify the SCH_EDIT_FRAME
92}
93
94
95void DIALOG_SCH_FIND::OnIdle( wxIdleEvent& aEvent )
96{
97 if( m_findDirty )
98 {
100 m_findDirty = false;
101 }
102}
103
104
105void DIALOG_SCH_FIND::OnCancel( wxCommandEvent& aEvent )
106{
107 wxCloseEvent dummy;
108 OnClose( dummy );
109}
110
111
112void DIALOG_SCH_FIND::OnUpdateReplaceUI( wxUpdateUIEvent& aEvent )
113{
114 aEvent.Enable( HasFlag( wxFR_REPLACEDIALOG ) && !m_comboFind->GetValue().empty() &&
116}
117
118
119void DIALOG_SCH_FIND::OnUpdateReplaceAllUI( wxUpdateUIEvent& aEvent )
120{
121 aEvent.Enable( HasFlag( wxFR_REPLACEDIALOG ) && !m_comboFind->GetValue().empty() );
122}
123
124
125void DIALOG_SCH_FIND::OnChar( wxKeyEvent& aEvent )
126{
127 if( aEvent.GetKeyCode() == WXK_RETURN )
128 {
129 wxCommandEvent dummyCommand;
130 OnFind( dummyCommand );
131 }
132}
133
134
135void DIALOG_SCH_FIND::OnSearchForText( wxCommandEvent& aEvent )
136{
138 m_findDirty = true;
139}
140
141
142void DIALOG_SCH_FIND::OnSearchForSelect( wxCommandEvent& aEvent )
143{
145
146 // Move the search string to the top of the list if it isn't already there.
147 if( aEvent.GetSelection() != 0 )
148 {
149 wxString tmp = m_comboFind->GetValue();
150 m_comboFind->Delete( aEvent.GetSelection() );
151 m_comboFind->Insert( tmp, 0 );
152 m_comboFind->SetSelection( 0 );
153 }
154
156}
157
158
159void DIALOG_SCH_FIND::OnReplaceWithText( wxCommandEvent& aEvent )
160{
162}
163
164
165void DIALOG_SCH_FIND::OnReplaceWithSelect( wxCommandEvent& aEvent )
166{
168
169 // Move the replace string to the top of the list if it isn't already there.
170 if( aEvent.GetSelection() != 0 )
171 {
172 wxString tmp = m_comboReplace->GetValue();
173 m_comboReplace->Delete( aEvent.GetSelection() );
174 m_comboReplace->Insert( tmp, 0 );
175 m_comboReplace->SetSelection( 0 );
176 }
177}
178
179
180void DIALOG_SCH_FIND::OnSearchForEnter( wxCommandEvent& aEvent )
181{
182 OnFind( aEvent );
183}
184
185
186void DIALOG_SCH_FIND::OnReplaceWithEnter( wxCommandEvent& aEvent )
187{
188 OnFind( aEvent );
189}
190
191
192void DIALOG_SCH_FIND::OnOptions( wxCommandEvent& aEvent )
193{
194 updateFlags();
195 m_findDirty = true;
196}
197
199{
200 // Rebuild the search flags in m_findReplaceData from dialog settings
201
202 if( m_checkMatchCase->GetValue() )
204 else
206
207 if( m_checkWholeWord->GetValue() )
209 else if( m_checkWildcardMatch->IsShown() && m_checkWildcardMatch->GetValue() )
211 else
213
214 if( m_checkAllFields->GetValue() )
216 else
218
219 if( m_checkAllPins->GetValue() )
221 else
223
224 if( m_checkCurrentSheetOnly->GetValue() )
226 else
228
229 if( m_checkReplaceReferences->GetValue() )
231 else
233}
234
235
236void DIALOG_SCH_FIND::OnFind( wxCommandEvent& aEvent )
237{
238 updateFlags(); // Ensure search flags are up to date
239
240 int index = m_comboFind->FindString( m_comboFind->GetValue(), true );
241
242 if( index == wxNOT_FOUND )
243 {
244 m_comboFind->Insert( m_comboFind->GetValue(), 0 );
245 }
246 else if( index != 0 )
247 {
248 /* Move the search string to the top of the list if it isn't already there. */
249 wxString tmp = m_comboFind->GetValue();
250 m_comboFind->Delete( index );
251 m_comboFind->Insert( tmp, 0 );
252 m_comboFind->SetSelection( 0 );
253 }
254
256}
257
258
259void DIALOG_SCH_FIND::OnReplace( wxCommandEvent& aEvent )
260{
261 updateFlags(); // Ensure search flags are up to date
262
263 int index = m_comboReplace->FindString( m_comboReplace->GetValue(), true );
264
265 if( index == wxNOT_FOUND )
266 {
267 m_comboReplace->Insert( m_comboReplace->GetValue(), 0 );
268 }
269 else if( index != 0 )
270 {
271 /* Move the search string to the top of the list if it isn't already there. */
272 wxString tmp = m_comboReplace->GetValue();
273 m_comboReplace->Delete( index );
274 m_comboReplace->Insert( tmp, 0 );
275 m_comboReplace->SetSelection( 0 );
276 }
277
278 if( aEvent.GetId() == wxID_REPLACE )
280 else if( aEvent.GetId() == wxID_REPLACE_ALL )
282}
283
284
286{
287 int index = m_comboFind->FindString( m_comboFind->GetValue(), true );
288
289 if( index == wxNOT_FOUND )
290 {
291 m_comboFind->Insert( m_comboFind->GetValue(), 0 );
292 }
293 else if( index != 0 )
294 {
295 /* Move the search string to the top of the list if it isn't already there. */
296 wxString tmp = m_comboFind->GetValue();
297 m_comboFind->Delete( index );
298 m_comboFind->Insert( tmp, 0 );
299 }
300
301 return m_comboFind->GetStrings();
302}
303
304
305void DIALOG_SCH_FIND::SetFindEntries( const wxArrayString& aEntries, const wxString& aFindString )
306{
307 m_comboFind->Append( aEntries );
308
309 while( m_comboFind->GetCount() > 10 )
310 {
311 m_frame->GetFindHistoryList().pop_back();
312 m_comboFind->Delete( 9 );
313 }
314
315 if( !aFindString.IsEmpty() )
316 {
317 m_comboFind->SetValue( aFindString );
318 m_comboFind->SelectAll();
319 }
320 else if( m_comboFind->GetCount() )
321 {
322 m_comboFind->SetSelection( 0 );
323 m_comboFind->SelectAll();
324 }
325}
326
327
328void DIALOG_SCH_FIND::SetReplaceEntries( const wxArrayString& aEntries )
329{
330 m_comboReplace->Append( aEntries );
331
332 while( m_comboReplace->GetCount() > 10 )
333 {
334 m_frame->GetFindHistoryList().pop_back();
335 m_comboReplace->Delete( 9 );
336 }
337
338 if( m_comboReplace->GetCount() )
339 {
340 m_comboReplace->SetSelection( 0 );
341 m_comboFind->SelectAll();
342 }
343}
static TOOL_ACTION replaceAll
Definition: actions.h:83
static TOOL_ACTION updateFind
Definition: actions.h:84
static TOOL_ACTION replaceAndFindNext
Definition: actions.h:82
static TOOL_ACTION findNext
Definition: actions.h:80
Class DIALOG_SCH_FIND_BASE.
void OnSearchForSelect(wxCommandEvent &aEvent) override
SCH_EDIT_FRAME * m_frame
DIALOG_SCH_FIND(SCH_EDIT_FRAME *aParent, SCH_SEARCH_DATA *aData, const wxPoint &aPosition=wxDefaultPosition, const wxSize &aSize=wxDefaultSize, int aStyle=0)
void OnReplaceWithEnter(wxCommandEvent &event) override
wxArrayString GetFindEntries() const
void OnIdle(wxIdleEvent &event) override
SCH_SEARCH_DATA * m_findReplaceData
void OnUpdateReplaceUI(wxUpdateUIEvent &aEvent) override
void SetReplaceEntries(const wxArrayString &aEntries)
void SetFindEntries(const wxArrayString &aEntries, const wxString &aFindString)
void OnChar(wxKeyEvent &aEvent)
void OnReplaceWithText(wxCommandEvent &aEvent) override
SCH_EDITOR_CONTROL * m_editorControl
void OnReplaceWithSelect(wxCommandEvent &aEvent) override
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 SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:97
wxArrayString & GetFindHistoryList()
Handle actions specific to the schematic editor.
int ReplaceAll(const TOOL_EVENT &aEvent)
int ReplaceAndFindNext(const TOOL_EVENT &aEvent)
int UpdateFind(const TOOL_EVENT &aEvent)
Notifies pcbnew about the selected item.
int FindNext(const TOOL_EVENT &aEvent)
Schematic editor (Eeschema) main window.
void OnFindDialogClose()
Notification that the Find dialog has closed.
Subclass of DIALOG_SCH_FIND_BASE, which is generated by wxFormBuilder.
#define _(s)
std::vector< FAB_LAYER_COLOR > dummy
EDA_SEARCH_MATCH_MODE matchMode
wxString replaceString