X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FGuiSearch.cpp;h=a8f10e7c63cf59b1169b0c5b59911e2cb495c9d8;hb=425d092204118ea6c24c28e85fdf03fcf2bb51a4;hp=819d97baac23b07b310b9ba8d2f4d05e34f4b0d1;hpb=a9f4ddae2d99d49e496eb968ab9d6b87ed44e83b;p=lyx.git diff --git a/src/frontends/qt4/GuiSearch.cpp b/src/frontends/qt4/GuiSearch.cpp index 819d97baac..a8f10e7c63 100644 --- a/src/frontends/qt4/GuiSearch.cpp +++ b/src/frontends/qt4/GuiSearch.cpp @@ -5,6 +5,7 @@ * * \author John Levon * \author Edwin Leuven + * \author Angus Leeming * * Full author contact details are available in file CREDITS. */ @@ -13,41 +14,39 @@ #include "GuiSearch.h" -#include "ControlSearch.h" #include "qt_helpers.h" -#include -#include +#include "FuncRequest.h" +#include "lyxfind.h" -using std::string; +#include +#include +using namespace std; namespace lyx { namespace frontend { static void uniqueInsert(QComboBox * box, QString const & text) { - for (int i = 0; i < box->count(); ++i) { + for (int i = box->count(); --i >= 0; ) if (box->itemText(i) == text) return; - } - box->addItem(text); + box->insertItem(0, text); } -GuiSearchDialog::GuiSearchDialog(LyXView & lv) - : GuiDialog(lv, "findreplace") +GuiSearch::GuiSearch(GuiView & lv) + : GuiDialog(lv, "findreplace", qt_("Find and Replace")) { setupUi(this); - setController(new ControlSearch(*this)); - setViewTitle(_("Find and Replace")); connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); connect(findPB, SIGNAL(clicked()), this, SLOT(findClicked())); connect(replacePB, SIGNAL(clicked()), this, SLOT(replaceClicked())); connect(replaceallPB, SIGNAL(clicked()), this, SLOT(replaceallClicked())); - connect(findCO, SIGNAL(editTextChanged(const QString &)), + connect(findCO, SIGNAL(editTextChanged(QString)), this, SLOT(findChanged())); setFocusProxy(findCO); @@ -63,27 +62,15 @@ GuiSearchDialog::GuiSearchDialog(LyXView & lv) } -ControlSearch & GuiSearchDialog::controller() -{ - return static_cast(GuiDialog::controller()); -} - - -void GuiSearchDialog::showView() +void GuiSearch::showEvent(QShowEvent * e) { - findCO->lineEdit()->setSelection(0, findCO->lineEdit()->text().length()); - GuiDialog::showView(); + findPB->setFocus(); + findCO->lineEdit()->selectAll(); + GuiDialog::showEvent(e); } -void GuiSearchDialog::closeEvent(QCloseEvent * e) -{ - slotClose(); - GuiDialog::closeEvent(e); -} - - -void GuiSearchDialog::findChanged() +void GuiSearch::findChanged() { if (findCO->currentText().isEmpty()) { findPB->setEnabled(false); @@ -91,60 +78,67 @@ void GuiSearchDialog::findChanged() replaceallPB->setEnabled(false); } else { findPB->setEnabled(true); - replacePB->setEnabled(!controller().isBufferReadonly()); - replaceallPB->setEnabled(!controller().isBufferReadonly()); + replacePB->setEnabled(!isBufferReadonly()); + replaceallPB->setEnabled(!isBufferReadonly()); } } -void GuiSearchDialog::findClicked() +void GuiSearch::findClicked() { docstring const needle = qstring_to_ucs4(findCO->currentText()); find(needle, caseCB->isChecked(), wordsCB->isChecked(), - backwardsCB->isChecked()); + !backwardsCB->isChecked()); uniqueInsert(findCO, findCO->currentText()); - findCO->lineEdit()->setSelection(0, findCO->lineEdit()->text().length()); + findCO->lineEdit()->selectAll(); } -void GuiSearchDialog::replaceClicked() +void GuiSearch::replaceClicked() { docstring const needle = qstring_to_ucs4(findCO->currentText()); docstring const repl = qstring_to_ucs4(replaceCO->currentText()); replace(needle, repl, caseCB->isChecked(), wordsCB->isChecked(), - backwardsCB->isChecked(), false); + !backwardsCB->isChecked(), false); uniqueInsert(findCO, findCO->currentText()); uniqueInsert(replaceCO, replaceCO->currentText()); } -void GuiSearchDialog::replaceallClicked() +void GuiSearch::replaceallClicked() { replace(qstring_to_ucs4(findCO->currentText()), qstring_to_ucs4(replaceCO->currentText()), - caseCB->isChecked(), wordsCB->isChecked(), false, true); + caseCB->isChecked(), wordsCB->isChecked(), true, true); uniqueInsert(findCO, findCO->currentText()); uniqueInsert(replaceCO, replaceCO->currentText()); } -void GuiSearchDialog::find(docstring const & str, bool casesens, - bool words, bool backwards) +void GuiSearch::find(docstring const & search, bool casesensitive, + bool matchword, bool forward) { - controller().find(str, casesens, words, !backwards); + docstring const data = + find2string(search, casesensitive, matchword, forward); + dispatch(FuncRequest(LFUN_WORD_FIND, data)); } -void GuiSearchDialog::replace(docstring const & findstr, - docstring const & replacestr, - bool casesens, bool words, bool backwards, bool all) +void GuiSearch::replace(docstring const & search, docstring const & replace, + bool casesensitive, bool matchword, + bool forward, bool all) { - controller().replace(findstr, replacestr, casesens, words, - !backwards, all); + docstring const data = + replace2string(replace, search, casesensitive, + matchword, all, forward); + dispatch(FuncRequest(LFUN_WORD_REPLACE, data)); } +Dialog * createGuiSearch(GuiView & lv) { return new GuiSearch(lv); } + + } // namespace frontend } // namespace lyx -#include "GuiSearch_moc.cpp" +#include "moc_GuiSearch.cpp"