3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
14 #include "GuiSearch.h"
16 #include "ControlSearch.h"
17 #include "qt_helpers.h"
20 #include <QCloseEvent>
28 static void uniqueInsert(QComboBox * box, QString const & text)
30 for (int i = 0; i < box->count(); ++i) {
31 if (box->itemText(i) == text)
39 GuiSearchDialog::GuiSearchDialog(LyXView & lv)
40 : GuiDialog(lv, "findreplace")
43 setController(new ControlSearch(*this));
44 setViewTitle(_("Find and Replace"));
46 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
47 connect(findPB, SIGNAL(clicked()), this, SLOT(findClicked()));
48 connect(replacePB, SIGNAL(clicked()), this, SLOT(replaceClicked()));
49 connect(replaceallPB, SIGNAL(clicked()), this, SLOT(replaceallClicked()));
50 connect(findCO, SIGNAL(editTextChanged(const QString &)),
51 this, SLOT(findChanged()));
53 setFocusProxy(findCO);
55 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
56 bc().setCancel(closePB);
57 bc().addReadOnly(replaceCO);
58 bc().addReadOnly(replacePB);
59 bc().addReadOnly(replaceallPB);
61 replacePB->setEnabled(false);
62 replaceallPB->setEnabled(false);
66 ControlSearch & GuiSearchDialog::controller() const
68 return static_cast<ControlSearch &>(GuiDialog::controller());
72 void GuiSearchDialog::showView()
74 findCO->lineEdit()->setSelection(0, findCO->lineEdit()->text().length());
75 GuiDialog::showView();
79 void GuiSearchDialog::closeEvent(QCloseEvent * e)
86 void GuiSearchDialog::findChanged()
88 if (findCO->currentText().isEmpty()) {
89 findPB->setEnabled(false);
90 replacePB->setEnabled(false);
91 replaceallPB->setEnabled(false);
93 findPB->setEnabled(true);
94 replacePB->setEnabled(!readOnly());
95 replaceallPB->setEnabled(!readOnly());
100 void GuiSearchDialog::findClicked()
102 docstring const needle = qstring_to_ucs4(findCO->currentText());
103 find(needle, caseCB->isChecked(), wordsCB->isChecked(),
104 backwardsCB->isChecked());
105 uniqueInsert(findCO, findCO->currentText());
106 findCO->lineEdit()->setSelection(0, findCO->lineEdit()->text().length());
110 void GuiSearchDialog::replaceClicked()
112 docstring const needle = qstring_to_ucs4(findCO->currentText());
113 docstring const repl = qstring_to_ucs4(replaceCO->currentText());
114 replace(needle, repl, caseCB->isChecked(), wordsCB->isChecked(),
115 backwardsCB->isChecked(), false);
116 uniqueInsert(findCO, findCO->currentText());
117 uniqueInsert(replaceCO, replaceCO->currentText());
121 void GuiSearchDialog::replaceallClicked()
123 replace(qstring_to_ucs4(findCO->currentText()),
124 qstring_to_ucs4(replaceCO->currentText()),
125 caseCB->isChecked(), wordsCB->isChecked(), false, true);
126 uniqueInsert(findCO, findCO->currentText());
127 uniqueInsert(replaceCO, replaceCO->currentText());
131 void GuiSearchDialog::find(docstring const & str, bool casesens,
132 bool words, bool backwards)
134 controller().find(str, casesens, words, !backwards);
138 void GuiSearchDialog::replace(docstring const & findstr,
139 docstring const & replacestr,
140 bool casesens, bool words, bool backwards, bool all)
142 controller().replace(findstr, replacestr, casesens, words,
146 } // namespace frontend
150 #include "GuiSearch_moc.cpp"