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 <stambaughw@verizon.net>
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 
25 #include <dialog_schematic_find.h>
26 #include <tool/actions.h>
27 #include <sch_edit_frame.h>
29 
30 
31 DIALOG_SCH_FIND::DIALOG_SCH_FIND( SCH_EDIT_FRAME* aParent, wxFindReplaceData* aData,
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 {
39  wxASSERT_MSG( m_findReplaceData, wxT( "can't create find dialog without data" ) );
40 
41  if( aStyle & wxFR_REPLACEDIALOG )
42  {
43  SetTitle( _( "Find and Replace" ) );
44  m_buttonReplace->Show( true );
45  m_buttonReplaceAll->Show( true );
46  m_staticReplace->Show( true );
47  m_comboReplace->Show( true );
48  m_checkReplaceReferences->Show( true );
49  m_checkWildcardMatch->Show( false ); // Wildcard replace is not implemented.
50  }
51 
52  int flags = m_findReplaceData->GetFlags();
53  m_radioForward->SetValue( flags & wxFR_DOWN );
54  m_radioBackward->SetValue( ( flags & wxFR_DOWN ) == 0 );
55  m_checkMatchCase->SetValue( flags & wxFR_MATCHCASE );
56  m_checkWholeWord->SetValue( flags & wxFR_WHOLEWORD );
57 
58  /* Whole word and wild card searches are mutually exclusive. */
59  if( !( flags & wxFR_WHOLEWORD ) )
60  m_checkWildcardMatch->SetValue( flags & FR_MATCH_WILDCARD );
61 
62  m_checkAllFields->SetValue( flags & FR_SEARCH_ALL_FIELDS );
64  m_checkAllPins->SetValue( flags & FR_SEARCH_ALL_PINS );
66 
67  m_buttonFind->SetDefault();
69 
70  SetPosition( aPosition );
71 
72  // Adjust the height of the dialog to prevent controls from being hidden when
73  // switching between the find and find/replace modes of the dialog. This ignores
74  // the users preferred height if any of the controls would be hidden.
75  GetSizer()->SetSizeHints( this );
76  wxSize size = aSize;
77 
78  if( aSize != wxDefaultSize )
79  {
80  wxSize bestSize = GetBestSize();
81 
82  if( size.GetHeight() != bestSize.GetHeight() )
83  size.SetHeight( bestSize.GetHeight() );
84  }
85 
86  SetSize( size );
87 
88  GetSizer()->Fit( this ); // Needed on Ubuntu/Unity to display the dialog
89 
90  Connect( wxEVT_CHAR, wxKeyEventHandler( DIALOG_SCH_FIND::OnChar ), nullptr, this );
91 }
92 
93 
94 void DIALOG_SCH_FIND::OnClose( wxCloseEvent& aEvent )
95 {
96  // Notify the SCH_EDIT_FRAME
98  // Notify the controller
100 }
101 
102 
103 void DIALOG_SCH_FIND::OnCancel( wxCommandEvent& aEvent )
104 {
105  wxCloseEvent dummy;
106  OnClose( dummy );
107 }
108 
109 
110 void DIALOG_SCH_FIND::OnUpdateReplaceUI( wxUpdateUIEvent& aEvent )
111 {
112  aEvent.Enable( HasFlag( wxFR_REPLACEDIALOG ) && !m_comboFind->GetValue().empty() &&
114 }
115 
116 
117 void DIALOG_SCH_FIND::OnUpdateReplaceAllUI( wxUpdateUIEvent& aEvent )
118 {
119  aEvent.Enable( HasFlag( wxFR_REPLACEDIALOG ) && !m_comboFind->GetValue().empty() );
120 }
121 
122 
123 void DIALOG_SCH_FIND::OnChar( wxKeyEvent& aEvent )
124 {
125  if( aEvent.GetKeyCode() == WXK_RETURN )
126  {
127  wxCommandEvent dummyCommand;
128  OnFind( dummyCommand );
129  }
130 }
131 
132 
133 void DIALOG_SCH_FIND::OnSearchForText( wxCommandEvent& aEvent )
134 {
135  m_findReplaceData->SetFindString( m_comboFind->GetValue() );
137 }
138 
139 
140 void DIALOG_SCH_FIND::OnTextEnter( wxCommandEvent& aEvent )
141 {
142  OnFind( aEvent );
143 }
144 
145 
146 void DIALOG_SCH_FIND::OnOptions( wxCommandEvent& aEvent )
147 {
148  int flags = 0;
149 
150  if( m_radioForward->GetValue() )
151  flags |= wxFR_DOWN;
152 
153  if( m_checkMatchCase->GetValue() )
154  flags |= wxFR_MATCHCASE;
155 
156  if( m_checkWholeWord->GetValue() )
157  flags |= wxFR_WHOLEWORD;
158 
159  if( m_checkWildcardMatch->IsShown() && m_checkWildcardMatch->GetValue() )
160  flags |= FR_MATCH_WILDCARD;
161 
162  if( m_checkAllFields->GetValue() )
163  flags |= FR_SEARCH_ALL_FIELDS;
164 
165  if( m_checkAllPins->GetValue() )
166  flags |= FR_SEARCH_ALL_PINS;
167 
168  if( m_checkCurrentSheetOnly->GetValue() )
169  flags |= FR_CURRENT_SHEET_ONLY;
170 
171  if( m_checkReplaceReferences->GetValue() )
172  flags |= FR_REPLACE_REFERENCES;
173 
174  m_findReplaceData->SetFlags( flags );
176 }
177 
178 
179 void DIALOG_SCH_FIND::OnFind( wxCommandEvent& aEvent )
180 {
181  int index = m_comboFind->FindString( m_comboFind->GetValue(), true );
182 
183  if( index == wxNOT_FOUND )
184  {
185  m_comboFind->Insert( m_comboFind->GetValue(), 0 );
186  }
187  else if( index != 0 )
188  {
189  /* Move the search string to the top of the list if it isn't already there. */
190  wxString tmp = m_comboFind->GetValue();
191  m_comboFind->Delete( index );
192  m_comboFind->Insert( tmp, 0 );
193  m_comboFind->SetSelection( 0 );
194  }
195 
197 }
198 
199 
200 void DIALOG_SCH_FIND::OnReplace( wxCommandEvent& aEvent )
201 {
202  int index = m_comboReplace->FindString( m_comboReplace->GetValue(), true );
203 
204  if( index == wxNOT_FOUND )
205  {
206  m_comboReplace->Insert( m_comboReplace->GetValue(), 0 );
207  }
208  else if( index != 0 )
209  {
210  /* Move the search string to the top of the list if it isn't already there. */
211  wxString tmp = m_comboReplace->GetValue();
212  m_comboReplace->Delete( index );
213  m_comboReplace->Insert( tmp, 0 );
214  m_comboReplace->SetSelection( 0 );
215  }
216 
217  if( aEvent.GetId() == wxID_REPLACE )
219  else if( aEvent.GetId() == wxID_REPLACE_ALL )
221 }
222 
223 
224 wxArrayString DIALOG_SCH_FIND::GetFindEntries() const
225 {
226  return m_comboFind->GetStrings();
227 }
228 
229 
230 void DIALOG_SCH_FIND::SetFindEntries( const wxArrayString& aEntries )
231 {
232  m_comboFind->Append( aEntries );
233 
234  if( m_comboFind->GetCount() )
235  {
236  m_comboFind->SetSelection( 0 );
237  m_comboFind->SelectAll();
238  }
239 }
240 
241 
242 void DIALOG_SCH_FIND::SetReplaceEntries( const wxArrayString& aEntries )
243 {
244  m_comboReplace->Append( aEntries );
245 
246  if( m_comboReplace->GetCount() )
247  {
248  m_comboReplace->SetSelection( 0 );
249  m_comboFind->SelectAll();
250  }
251 }
void OnUpdateReplaceAllUI(wxUpdateUIEvent &aEvent) override
wxArrayString GetFindEntries() const
void SetPosition(wxString aStr, const wxString &aDefaultMeasurementUnit, int *aX, int *aY, const wxString &aActualConversion)
void OnChar(wxKeyEvent &aEvent)
Class DIALOG_SCH_FIND_BASE.
void OnSearchForText(wxCommandEvent &aEvent) override
static TOOL_ACTION replaceAll
Definition: actions.h:83
Schematic editor (Eeschema) main window.
int FindNext(const TOOL_EVENT &aEvent)
void OnReplace(wxCommandEvent &aEvent) override
void OnFindDialogClose()
Notification that the Find dialog has closed.
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:118
static TOOL_ACTION updateFind
Definition: actions.h:84
Class SCH_EDITOR_CONTROL.
wxFindReplaceData * m_findReplaceData
DIALOG_SCH_FIND(SCH_EDIT_FRAME *aParent, wxFindReplaceData *aData, const wxPoint &aPosition=wxDefaultPosition, const wxSize &aSize=wxDefaultSize, int aStyle=0)
SCH_EDITOR_CONTROL * m_editorControl
Subclass of DIALOG_SCH_FIND_BASE, which is generated by wxFormBuilder.
int UpdateFind(const TOOL_EVENT &aEvent)
void OnClose(wxCloseEvent &aEvent) override
void OnUpdateReplaceUI(wxUpdateUIEvent &aEvent) override
static TOOL_ACTION replaceAndFindNext
Definition: actions.h:82
void SetReplaceEntries(const wxArrayString &aEntries)
void OnOptions(wxCommandEvent &event) override
void OnTextEnter(wxCommandEvent &event) override
#define _(s)
void SetFindEntries(const wxArrayString &aEntries)
void OnFind(wxCommandEvent &aEvent) override
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
TOOL_EVENT MakeEvent() const
Function MakeEvent() Returns the event associated with the action (i.e.
Definition: tool_action.h:107
SCH_EDIT_FRAME * m_frame
void OnCancel(wxCommandEvent &aEvent) override
static TOOL_ACTION findNext
Definition: actions.h:80