Mercurial > hg > octave-nkf
changeset 18183:5f7f58866922 gui-release
fix search and replace all in find dialog (bug #41051)
* find-dialog.cc (contructor): init flag for replace all with 0 (false);
(find): fix cursor position when searching backwards, handle case when
searching and replacing all;
(replace): only replace when there is selected text and a find result;
(replace_all): search and replace all only from the beginning to the end
* find-dialog.h: new flag _rep_all
author | Torsten <ttl@justmail.de> |
---|---|
date | Wed, 01 Jan 2014 18:18:34 +0100 |
parents | 7eeaecac9b5b |
children | d03a6d272fee |
files | libgui/src/m-editor/find-dialog.cc libgui/src/m-editor/find-dialog.h |
diffstat | 2 files changed, 44 insertions(+), 42 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/m-editor/find-dialog.cc +++ b/libgui/src/m-editor/find-dialog.cc @@ -157,6 +157,7 @@ _extension->hide (); _find_next_button->setDefault (true); _find_result_available = false; + _rep_all = 0; // move dialog to side of the parent if there is room on the desktop to do so. QWidget * desktop = QApplication::desktop (); @@ -212,29 +213,38 @@ { int line = -1, col = -1; bool do_wrap = _wrap_check_box->isChecked (); - bool do_forward = true; + bool do_forward = forward; - if (_find_result_available) - { - // we found a match last time, cursor is at the end of the match - if (!forward) - { - // backward: go back one position or we will find the same again - do_forward = false; - _edit_area->getCursorPosition (&line,&col); - if (col > 0) - _edit_area->setCursorPosition (line,--col); - } + if (!forward && _find_result_available) + { // we found a match last time, cursor is at the end of the match + // backward: go to start of selection or we will find the same again + int line_end, col_end; + _edit_area->getSelection (&line,&col,&line_end,&col_end); + if (line > -1) + _edit_area->setCursorPosition (line,col); } _find_result_available = false; - if (_from_start_check_box->isChecked ()) + if (_rep_all) { - line = 0; - col = 0; - if (_backward_check_box->isChecked ()) - do_wrap = true; + if (_rep_all == 1) + { + line = 0; + col = 0; + } + do_wrap = false; + do_forward = true; + } + else + { + if (_from_start_check_box->isChecked ()) + { + line = 0; + col = 0; + if (_backward_check_box->isChecked ()) + do_wrap = true; + } } if (_edit_area) @@ -255,7 +265,7 @@ } if (_find_result_available) _from_start_check_box->setChecked (0); - else + else if (! _rep_all) no_matches_message (); } @@ -265,47 +275,38 @@ { if (_edit_area) { - _edit_area->replace (_replace_line_edit->text ()); - if (!_edit_area->findNext()) - no_matches_message (); + if (_find_result_available && _edit_area->hasSelectedText ()) + _edit_area->replace (_replace_line_edit->text ()); + find_next (); } } void find_dialog::replace_all () { - int count = 0; + int line, col; - // check whether find & replace srings are different (avoid endless loop!) - int strDiff; - Qt::CaseSensitivity cs; - if (_case_check_box->isChecked()) + if (_edit_area) { - cs = Qt::CaseSensitive; - } - else - { - cs = Qt::CaseInsensitive; - } - strDiff = QString::compare (_search_line_edit->text(), - _replace_line_edit->text(), cs); + _edit_area->getCursorPosition (&line,&col); - // replace all if strings are different - if (_edit_area && strDiff ) - { - find (!_backward_check_box->isChecked ()); // find first occurence + _rep_all = 1; + find_next (); // find first occurence (forward) while (_find_result_available) // while search string is found { _edit_area->replace (_replace_line_edit->text ()); // replace - count++; // inc counter - _find_result_available = _edit_area->findNext(); // and find next + _rep_all++; // inc counter + find_next (); // find next } + QMessageBox msg_box (QMessageBox::Information, tr ("Replace Result"), - tr ("%1 items replaced").arg(count), + tr ("%1 items replaced").arg(_rep_all-1), QMessageBox::Ok, this); msg_box.exec (); + + _rep_all = 0; + _edit_area->setCursorPosition (line,col); } - // TODO: Show number of replaced strings } void