Menu

[r135]: / src / findreplacepanel.cpp  Maximize  Restore  History

Download this file

285 lines (237 with data), 8.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
/*
* Copyright 2005-2007 Gerald Schmidt.
*
* This file is part of Xml Copy Editor.
*
* Xml Copy Editor is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* Xml Copy Editor is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Xml Copy Editor; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <wx/fdrepdlg.h>
#include "findreplacepanel.h"
#include "nocasecompare.h"
#include "xmlcopyeditor.h"
BEGIN_EVENT_TABLE ( FindReplacePanel, wxPanel )
EVT_BUTTON ( ID_FINDREPLACE_FIND_NEXT, FindReplacePanel::OnFindNext )
EVT_BUTTON ( ID_FINDREPLACE_REPLACE, FindReplacePanel::OnReplace )
EVT_BUTTON ( ID_FINDREPLACE_REPLACE_ALL, FindReplacePanel::OnReplaceAll )
EVT_IDLE ( FindReplacePanel::OnIdle )
END_EVENT_TABLE()
FindReplacePanel::FindReplacePanel (
wxWindow *parentParameter,
int id,
wxFindReplaceData *findDataParameter,
bool isReplacePanel,
bool isRegexParameter ) : wxPanel ( parentParameter, id )
{
parent = parentParameter;
findData = findDataParameter;
incrementalFind = notFoundSet = false;
isRegex = isRegexParameter;
matchCaseMemory = ( findData->GetFlags() ) & wxFR_MATCHCASE;
regexMemory = isRegex;
label1 = new wxStaticText ( this, wxID_ANY, _ ( "Find:" ) );
spacer1 = new wxStaticText ( this, wxID_ANY, _ ( " " ) );
spacer2 = new wxStaticText ( this, wxID_ANY, _ ( " " ) );
int editWidth = 140;
findEdit = new wxTextCtrl (
this,
ID_FINDREPLACE_FIND_NEXT,
_T ( "" ),
wxDefaultPosition,
wxSize ( editWidth, -1 )
);
findEdit->SetValue ( findData->GetFindString() );
label2 = new wxStaticText ( this, wxID_ANY, _ ( "Replace with:" ) );
replaceEdit = new wxTextCtrl (
this,
ID_FINDREPLACE_REPLACE,
_T ( "" ),
wxDefaultPosition,
wxSize ( editWidth, -1 ) );
replaceEdit->SetValue ( findData->GetReplaceString() );
findNextButton = new wxButton (
this,
ID_FINDREPLACE_FIND_NEXT,
_ ( "Find &Next" ),
wxDefaultPosition,
wxDefaultSize,
wxBU_EXACTFIT | wxNO_BORDER );
replaceButton = new wxButton (
this,
ID_FINDREPLACE_REPLACE,
_ ( "&Replace" ),
wxDefaultPosition,
wxDefaultSize,
wxBU_EXACTFIT | wxNO_BORDER );
replaceAllButton = new wxButton (
this,
ID_FINDREPLACE_REPLACE_ALL,
_ ( "Replace &All" ),
wxDefaultPosition,
wxDefaultSize,
wxBU_EXACTFIT | wxNO_BORDER );
matchCaseBox = new wxCheckBox (
this,
ID_FINDREPLACE_MATCH_CASE,
_ ( "&Match case" ) );
size_t flags = findData->GetFlags();
matchCaseBox->SetValue ( flags & wxFR_MATCHCASE );
regexBox = new wxCheckBox (
this,
ID_FINDREPLACE_REGEX,
_ ( "Re&gex" ) );
int sizerOffset = 2;
sizer = new wxBoxSizer ( wxHORIZONTAL );
sizer->Add ( label1, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, sizerOffset );
sizer->Add ( findEdit, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, sizerOffset );
sizer->Add ( label2, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, sizerOffset );
sizer->Add ( replaceEdit, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, sizerOffset );
sizer->Add ( spacer1, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, sizerOffset );
sizer->Add ( findNextButton, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, sizerOffset );
sizer->Add ( replaceButton, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, sizerOffset );
sizer->Add ( replaceAllButton, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, sizerOffset );
sizer->Add ( spacer2, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, sizerOffset );
sizer->Add ( matchCaseBox, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, sizerOffset );
sizer->Add ( regexBox, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, sizerOffset );
sizer->Layout();
this->SetSizer ( sizer );
this->SetSize ( -1, findNextButton->GetSize().GetHeight() + 10 );
findEditLength = findEdit->GetValue().Length();
if ( !isReplacePanel )
{
label2->Hide();
replaceEdit->Hide();
replaceButton->Hide();
replaceAllButton->Hide();
}
refresh();
}
FindReplacePanel::~FindReplacePanel()
{}
void FindReplacePanel::OnFindNext ( wxCommandEvent& event )
{
findData->SetFindString ( findEdit->GetValue() );
findData->SetReplaceString ( replaceEdit->GetValue() );
incrementalFind = false;
size_t flags = 0;
flags |= wxFR_DOWN;
if ( matchCaseBox->GetValue() )
flags |= wxFR_MATCHCASE;
sendFindEvent ( flags );
}
void FindReplacePanel::OnReplace ( wxCommandEvent& event )
{
wxFindDialogEvent replaceEvent ( wxEVT_COMMAND_FIND_REPLACE, 0 );
replaceEvent.SetFlags ( wxFR_DOWN );
replaceEvent.SetFindString ( findEdit->GetValue() );
replaceEvent.SetReplaceString ( replaceEdit->GetValue() );
parent->ProcessEvent ( replaceEvent );
}
void FindReplacePanel::OnReplaceAll ( wxCommandEvent& event )
{
wxFindDialogEvent replaceAllEvent ( wxEVT_COMMAND_FIND_REPLACE_ALL, 0 );
replaceAllEvent.SetFlags ( wxFR_DOWN );
replaceAllEvent.SetFindString ( findEdit->GetValue() );
replaceAllEvent.SetReplaceString ( replaceEdit->GetValue() );
parent->ProcessEvent ( replaceAllEvent );
}
void FindReplacePanel::focusOnFind()
{
findEdit->SelectAll();
findEdit->SetFocus();
}
void FindReplacePanel::OnIdle ( wxIdleEvent& event )
{
size_t newLength = findEdit->GetValue().Length();
enableButtons ( ( !newLength ) ? false : true );
bool settingsChanged = false;
if ( matchCaseMemory != matchCaseBox->GetValue() ||
regexMemory != regexBox->GetValue() )
{
settingsChanged = true;
matchCaseMemory = matchCaseBox->GetValue();
regexMemory = regexBox->GetValue();
}
if ( newLength != findEditLength || settingsChanged )
{
incrementalFind = true;
size_t flags = 0;
flags |= wxFR_DOWN;
if ( matchCaseBox->GetValue() )
flags |= wxFR_MATCHCASE;
sendFindEvent ( flags );
findEditLength = newLength;
findData->SetFlags ( flags );
}
}
void FindReplacePanel::sendFindEvent ( size_t flags )
{
wxFindDialogEvent findEvent ( wxEVT_COMMAND_FIND_NEXT, 0 );
findEvent.SetFlags ( flags );
findEvent.SetFindString ( findEdit->GetValue() );
MyFrame *frame = ( MyFrame * ) parent;
frame->setStrictScrolling ( true );
frame->ProcessEvent ( findEvent ); // was parent->
frame->setStrictScrolling ( false );
findData->SetFindString ( findEdit->GetValue() );
findData->SetReplaceString ( replaceEdit->GetValue() );
}
bool FindReplacePanel::getIncrementalFind()
{
return incrementalFind;
}
void FindReplacePanel::refresh()
{
incrementalFind = false;
findEdit->SetValue ( findData->GetFindString() );
replaceEdit->SetValue ( findData->GetReplaceString() );
size_t flags = findData->GetFlags();
bool matchCase;
matchCase = flags & wxFR_MATCHCASE;
matchCaseBox->SetValue ( matchCase );
matchCaseMemory = matchCase;
regexBox->SetValue ( isRegex );
regexMemory = isRegex;
}
void FindReplacePanel::setReplaceVisible ( bool b )
{
label2->Show ( b );
replaceEdit->Show ( b );
replaceButton->Show ( b );
replaceAllButton->Show ( b );
sizer->Layout();
}
void FindReplacePanel::flagNotFound ( bool b )
{
if ( ( notFoundSet && b ) || ( !notFoundSet && !b ) )
return;
notFoundSet = b;
}
bool FindReplacePanel::getRegex()
{
return regexBox->GetValue();
}
void FindReplacePanel::setMatchCase ( bool b )
{
matchCaseBox->SetValue ( b );
}
void FindReplacePanel::setRegex ( bool b )
{
regexBox->SetValue ( b );
}
void FindReplacePanel::enableButtons ( bool b )
{
findNextButton->Enable ( b );
replaceButton->Enable ( b );
replaceAllButton->Enable ( b );
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.