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
55 {
57
59 m_cbSearchPins->Hide();
60 m_cbSearchNetNames->Hide();
62
63 m_staticline1->Hide();
64 m_searchPanelLink->Hide();
65 }
66
68 m_checkWholeWord->SetValue( m_findReplaceData->matchMode == EDA_SEARCH_MATCH_MODE::WHOLEWORD );
69 m_checkRegexMatch->SetValue( m_findReplaceData->matchMode == EDA_SEARCH_MATCH_MODE::REGEX );
70
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
107
108void DIALOG_SCH_FIND::OnClose( wxCloseEvent& aEvent )
109{
110 // Notify the SCH_BASE_FRAME
112}
113
114
115void DIALOG_SCH_FIND::OnIdle( wxIdleEvent& aEvent )
116{
117 if( m_findDirty )
118 {
120 m_findDirty = false;
121 }
122}
123
124
125void DIALOG_SCH_FIND::OnCancel( wxCommandEvent& aEvent )
126{
127 wxCloseEvent dummy;
128 OnClose( dummy );
129}
130
131
132void DIALOG_SCH_FIND::onShowSearchPanel( wxHyperlinkEvent& event )
133{
134 wxCHECK2( m_frame->GetFrameType() == FRAME_SCH, /* void */ );
135
136 if( static_cast<SCH_EDIT_FRAME*>( m_frame )->IsSearchPaneShown() )
137 {
138 EndModal( wxID_CANCEL );
139
140 CallAfter(
141 []()
142 {
143 if( wxWindow* frame = wxWindow::FindWindowByName( SCH_EDIT_FRAME_NAME ) )
144 static_cast<SCH_EDIT_FRAME*>( frame )->FocusSearch();
145 } );
146 }
147 else
148 {
150 }
151}
152
153
154void DIALOG_SCH_FIND::OnUpdateReplaceUI( wxUpdateUIEvent& aEvent )
155{
156 aEvent.Enable( HasFlag( wxFR_REPLACEDIALOG ) && !m_comboFind->GetValue().empty()
158}
159
160
161void DIALOG_SCH_FIND::OnUpdateReplaceAllUI( wxUpdateUIEvent& aEvent )
162{
163 aEvent.Enable( HasFlag( wxFR_REPLACEDIALOG ) && !m_comboFind->GetValue().empty() );
164}
165
166
167void DIALOG_SCH_FIND::OnSearchForText( wxCommandEvent& aEvent )
168{
170 m_findDirty = true;
171}
172
173
174void DIALOG_SCH_FIND::OnSearchForSelect( wxCommandEvent& aEvent )
175{
177
178 // Move the search string to the top of the list if it isn't already there.
179 if( aEvent.GetSelection() != 0 )
180 {
181 wxString tmp = m_comboFind->GetValue();
182 m_comboFind->Delete( aEvent.GetSelection() );
183 m_comboFind->Insert( tmp, 0 );
184 m_comboFind->SetSelection( 0 );
185 }
186
188}
189
190
191void DIALOG_SCH_FIND::OnReplaceWithText( wxCommandEvent& aEvent )
192{
194}
195
196
197void DIALOG_SCH_FIND::OnReplaceWithSelect( wxCommandEvent& aEvent )
198{
200
201 // Move the replace string to the top of the list if it isn't already there.
202 if( aEvent.GetSelection() != 0 )
203 {
204 wxString tmp = m_comboReplace->GetValue();
205 m_comboReplace->Delete( aEvent.GetSelection() );
206 m_comboReplace->Insert( tmp, 0 );
207 m_comboReplace->SetSelection( 0 );
208 }
209}
210
211
212void DIALOG_SCH_FIND::OnSearchForEnter( wxCommandEvent& aEvent )
213{
214 OnFind( aEvent );
215}
216
217
218void DIALOG_SCH_FIND::OnReplaceWithEnter( wxCommandEvent& aEvent )
219{
220 OnFind( aEvent );
221}
222
223
224void DIALOG_SCH_FIND::OnOptions( wxCommandEvent& aEvent )
225{
226 updateFlags();
227 m_findDirty = true;
228}
229
231{
232 // Rebuild the search flags in m_findReplaceData from dialog settings
239
240 if( m_checkWholeWord->GetValue() )
241 m_findReplaceData->matchMode = EDA_SEARCH_MATCH_MODE::WHOLEWORD;
242 else if( m_checkRegexMatch->IsShown() && m_checkRegexMatch->GetValue() )
243 m_findReplaceData->matchMode = EDA_SEARCH_MATCH_MODE::REGEX;
244 else
245 m_findReplaceData->matchMode = EDA_SEARCH_MATCH_MODE::PLAIN;
246
247 if( m_cbSelectedOnly->GetValue() )
248 {
249 m_cbCurrentSheetOnly->SetValue( true );
250 m_cbCurrentSheetOnly->Enable( false );
252 }
253 else
254 {
255 m_cbCurrentSheetOnly->Enable( true );
257 }
258}
259
260
261void DIALOG_SCH_FIND::OnFind( wxCommandEvent& aEvent )
262{
263 updateFlags(); // Ensure search flags are up to date
264
265 int index = m_comboFind->FindString( m_comboFind->GetValue(), true );
266
267 if( index == wxNOT_FOUND )
268 {
269 m_comboFind->Insert( m_comboFind->GetValue(), 0 );
270 }
271 else if( index != 0 )
272 {
273 /* Move the search string to the top of the list if it isn't already there. */
274 wxString tmp = m_comboFind->GetValue();
275 m_comboFind->Delete( index );
276 m_comboFind->Insert( tmp, 0 );
277 m_comboFind->SetSelection( 0 );
278 }
279
281}
282
283
284void DIALOG_SCH_FIND::OnReplace( wxCommandEvent& aEvent )
285{
286 updateFlags(); // Ensure search flags are up to date
287
288 int index = m_comboReplace->FindString( m_comboReplace->GetValue(), true );
289
290 if( index == wxNOT_FOUND )
291 {
292 m_comboReplace->Insert( m_comboReplace->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_comboReplace->GetValue();
298 m_comboReplace->Delete( index );
299 m_comboReplace->Insert( tmp, 0 );
300 m_comboReplace->SetSelection( 0 );
301 }
302
303 if( aEvent.GetId() == wxID_REPLACE )
305 else if( aEvent.GetId() == wxID_REPLACE_ALL )
307}
308
309
311{
312 int index = m_comboFind->FindString( m_comboFind->GetValue(), true );
313
314 if( index == wxNOT_FOUND )
315 {
316 m_comboFind->Insert( m_comboFind->GetValue(), 0 );
317 }
318 else if( index != 0 )
319 {
320 /* Move the search string to the top of the list if it isn't already there. */
321 wxString tmp = m_comboFind->GetValue();
322 m_comboFind->Delete( index );
323 m_comboFind->Insert( tmp, 0 );
324 }
325
326 return m_comboFind->GetStrings();
327}
328
329
330void DIALOG_SCH_FIND::SetFindEntries( const wxArrayString& aEntries, const wxString& aFindString )
331{
332 m_comboFind->Append( aEntries );
333
334 while( m_comboFind->GetCount() > 10 )
335 {
336 m_frame->GetFindHistoryList().pop_back();
337 m_comboFind->Delete( 9 );
338 }
339
340 if( !aFindString.IsEmpty() )
341 {
342 m_comboFind->SetValue( aFindString );
343 m_comboFind->SelectAll();
344 }
345 else if( m_comboFind->GetCount() )
346 {
347 m_comboFind->SetSelection( 0 );
348 m_comboFind->SelectAll();
349 }
350}
351
352
353void DIALOG_SCH_FIND::SetReplaceEntries( const wxArrayString& aEntries )
354{
355 m_comboReplace->Append( aEntries );
356
357 while( m_comboReplace->GetCount() > 10 )
358 {
359 m_frame->GetFindHistoryList().pop_back();
360 m_comboReplace->Delete( 9 );
361 }
362
363 if( m_comboReplace->GetCount() )
364 {
365 m_comboReplace->SetSelection( 0 );
366 m_comboFind->SelectAll();
367 }
368}
static TOOL_ACTION replaceAll
Definition: actions.h:122
static TOOL_ACTION updateFind
Definition: actions.h:123
static TOOL_ACTION replaceAndFindNext
Definition: actions.h:121
static TOOL_ACTION findNext
Definition: actions.h:118
static TOOL_ACTION showSearch
Definition: actions.h:115
Class DIALOG_SCH_FIND_BASE.
wxCheckBox * m_cbReplaceReferences
wxStaticLine * m_staticline1
wxCheckBox * m_cbSearchHiddenFields
wxStaticText * m_staticReplace
wxHyperlinkCtrl * m_searchPanelLink
wxCheckBox * m_cbCurrentSheetOnly
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
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:75
FRAME_T GetFrameType() const
wxArrayString & GetFindHistoryList()
A shim class between EDA_DRAW_FRAME and several derived classes: SYMBOL_EDIT_FRAME,...
void OnFindDialogClose()
Notification that the Find dialog has closed.
Schematic editor (Eeschema) main window.
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)
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
Definition: tool_manager.h:150
#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
EDA_SEARCH_MATCH_MODE matchMode
wxString replaceString