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