Mercurial > octave-nkf
comparison libgui/src/m-editor/find-dialog.cc @ 18211:775e7874b38d
maint: Periodic merge of gui-release to default.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 03 Jan 2014 17:33:46 -0500 |
parents | 36063e43c511 5f7f58866922 |
children | 75d7cde2dda4 |
comparison
equal
deleted
inserted
replaced
18207:bea06b5d4423 | 18211:775e7874b38d |
---|---|
155 setLayout (main_layout); | 155 setLayout (main_layout); |
156 | 156 |
157 _extension->hide (); | 157 _extension->hide (); |
158 _find_next_button->setDefault (true); | 158 _find_next_button->setDefault (true); |
159 _find_result_available = false; | 159 _find_result_available = false; |
160 _rep_all = 0; | |
160 | 161 |
161 // move dialog to side of the parent if there is room on the desktop to do so. | 162 // move dialog to side of the parent if there is room on the desktop to do so. |
162 QWidget * desktop = QApplication::desktop (); | 163 QWidget * desktop = QApplication::desktop (); |
163 int xp = p->x () + p->frameGeometry ().width (); | 164 int xp = p->x () + p->frameGeometry ().width (); |
164 int yp= p->y (); | 165 int yp= p->y (); |
211 find_dialog::find (bool forward) | 212 find_dialog::find (bool forward) |
212 { | 213 { |
213 int line, col; | 214 int line, col; |
214 line = col = -1; | 215 line = col = -1; |
215 bool do_wrap = _wrap_check_box->isChecked (); | 216 bool do_wrap = _wrap_check_box->isChecked (); |
216 bool do_forward = true; | 217 bool do_forward = forward; |
217 | 218 |
218 if (_find_result_available) | 219 if (!forward && _find_result_available) |
219 { | 220 { // we found a match last time, cursor is at the end of the match |
220 // we found a match last time, cursor is at the end of the match | 221 // backward: go to start of selection or we will find the same again |
221 if (!forward) | 222 int line_end, col_end; |
223 _edit_area->getSelection (&line,&col,&line_end,&col_end); | |
224 if (line > -1) | |
225 _edit_area->setCursorPosition (line,col); | |
226 } | |
227 | |
228 _find_result_available = false; | |
229 | |
230 if (_rep_all) | |
231 { | |
232 if (_rep_all == 1) | |
222 { | 233 { |
223 // backward: go back one position or we will find the same again | 234 line = 0; |
224 do_forward = false; | 235 col = 0; |
225 _edit_area->getCursorPosition (&line,&col); | |
226 if (col > 0) | |
227 _edit_area->setCursorPosition (line,--col); | |
228 } | 236 } |
229 } | 237 do_wrap = false; |
230 | 238 do_forward = true; |
231 _find_result_available = false; | 239 } |
232 | 240 else |
233 if (_from_start_check_box->isChecked ()) | 241 { |
234 { | 242 if (_from_start_check_box->isChecked ()) |
235 line = 0; | 243 { |
236 col = 0; | 244 line = 0; |
237 if (_backward_check_box->isChecked ()) | 245 col = 0; |
238 do_wrap = true; | 246 if (_backward_check_box->isChecked ()) |
247 do_wrap = true; | |
248 } | |
239 } | 249 } |
240 | 250 |
241 if (_edit_area) | 251 if (_edit_area) |
242 { | 252 { |
243 _find_result_available | 253 _find_result_available |
254 #endif | 264 #endif |
255 ); | 265 ); |
256 } | 266 } |
257 if (_find_result_available) | 267 if (_find_result_available) |
258 _from_start_check_box->setChecked (0); | 268 _from_start_check_box->setChecked (0); |
259 else | 269 else if (! _rep_all) |
260 no_matches_message (); | 270 no_matches_message (); |
261 } | 271 } |
262 | 272 |
263 | 273 |
264 void | 274 void |
265 find_dialog::replace () | 275 find_dialog::replace () |
266 { | 276 { |
267 if (_edit_area) | 277 if (_edit_area) |
268 { | 278 { |
269 _edit_area->replace (_replace_line_edit->text ()); | 279 if (_find_result_available && _edit_area->hasSelectedText ()) |
270 if (!_edit_area->findNext()) | 280 _edit_area->replace (_replace_line_edit->text ()); |
271 no_matches_message (); | 281 find_next (); |
272 } | 282 } |
273 } | 283 } |
274 | 284 |
275 void | 285 void |
276 find_dialog::replace_all () | 286 find_dialog::replace_all () |
277 { | 287 { |
278 int count = 0; | 288 int line, col; |
279 | 289 |
280 // check whether find & replace srings are different (avoid endless loop!) | 290 if (_edit_area) |
281 int strDiff; | 291 { |
282 Qt::CaseSensitivity cs; | 292 _edit_area->getCursorPosition (&line,&col); |
283 if (_case_check_box->isChecked()) | 293 |
284 { | 294 _rep_all = 1; |
285 cs = Qt::CaseSensitive; | 295 find_next (); // find first occurence (forward) |
286 } | |
287 else | |
288 { | |
289 cs = Qt::CaseInsensitive; | |
290 } | |
291 strDiff = QString::compare (_search_line_edit->text(), | |
292 _replace_line_edit->text(), cs); | |
293 | |
294 // replace all if strings are different | |
295 if (_edit_area && strDiff ) | |
296 { | |
297 find (!_backward_check_box->isChecked ()); // find first occurence | |
298 while (_find_result_available) // while search string is found | 296 while (_find_result_available) // while search string is found |
299 { | 297 { |
300 _edit_area->replace (_replace_line_edit->text ()); // replace | 298 _edit_area->replace (_replace_line_edit->text ()); // replace |
301 count++; // inc counter | 299 _rep_all++; // inc counter |
302 _find_result_available = _edit_area->findNext(); // and find next | 300 find_next (); // find next |
303 } | 301 } |
302 | |
304 QMessageBox msg_box (QMessageBox::Information, tr ("Replace Result"), | 303 QMessageBox msg_box (QMessageBox::Information, tr ("Replace Result"), |
305 tr ("%1 items replaced").arg(count), | 304 tr ("%1 items replaced").arg(_rep_all-1), |
306 QMessageBox::Ok, this); | 305 QMessageBox::Ok, this); |
307 msg_box.exec (); | 306 msg_box.exec (); |
308 } | 307 |
309 // TODO: Show number of replaced strings | 308 _rep_all = 0; |
309 _edit_area->setCursorPosition (line,col); | |
310 } | |
310 } | 311 } |
311 | 312 |
312 void | 313 void |
313 find_dialog::no_matches_message () | 314 find_dialog::no_matches_message () |
314 { | 315 { |