3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * \author Angus Leeming
10 * Full author contact details are available in file CREDITS.
15 #include "GuiSearch.h"
17 #include "FuncRequest.h"
20 #include "qt_helpers.h"
23 #include <QCloseEvent>
31 static void uniqueInsert(QComboBox * box, QString const & text)
33 for (int i = 0; i < box->count(); ++i) {
34 if (box->itemText(i) == text)
42 GuiSearch::GuiSearch(LyXView & lv)
43 : GuiDialog(lv, "findreplace"), Controller(this)
46 setController(this, false);
47 setViewTitle(_("Find and Replace"));
49 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
50 connect(findPB, SIGNAL(clicked()), this, SLOT(findClicked()));
51 connect(replacePB, SIGNAL(clicked()), this, SLOT(replaceClicked()));
52 connect(replaceallPB, SIGNAL(clicked()), this, SLOT(replaceallClicked()));
53 connect(findCO, SIGNAL(editTextChanged(const QString &)),
54 this, SLOT(findChanged()));
56 setFocusProxy(findCO);
58 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
59 bc().setCancel(closePB);
60 bc().addReadOnly(replaceCO);
61 bc().addReadOnly(replacePB);
62 bc().addReadOnly(replaceallPB);
64 replacePB->setEnabled(false);
65 replaceallPB->setEnabled(false);
69 void GuiSearch::showView()
71 findCO->lineEdit()->setSelection(0, findCO->lineEdit()->text().length());
72 GuiDialog::showView();
76 void GuiSearch::closeEvent(QCloseEvent * e)
79 GuiDialog::closeEvent(e);
83 void GuiSearch::findChanged()
85 if (findCO->currentText().isEmpty()) {
86 findPB->setEnabled(false);
87 replacePB->setEnabled(false);
88 replaceallPB->setEnabled(false);
90 findPB->setEnabled(true);
91 replacePB->setEnabled(!controller().isBufferReadonly());
92 replaceallPB->setEnabled(!controller().isBufferReadonly());
97 void GuiSearch::findClicked()
99 docstring const needle = qstring_to_ucs4(findCO->currentText());
100 find(needle, caseCB->isChecked(), wordsCB->isChecked(),
101 !backwardsCB->isChecked());
102 uniqueInsert(findCO, findCO->currentText());
103 findCO->lineEdit()->setSelection(0, findCO->lineEdit()->text().length());
107 void GuiSearch::replaceClicked()
109 docstring const needle = qstring_to_ucs4(findCO->currentText());
110 docstring const repl = qstring_to_ucs4(replaceCO->currentText());
111 replace(needle, repl, caseCB->isChecked(), wordsCB->isChecked(),
112 !backwardsCB->isChecked(), false);
113 uniqueInsert(findCO, findCO->currentText());
114 uniqueInsert(replaceCO, replaceCO->currentText());
118 void GuiSearch::replaceallClicked()
120 replace(qstring_to_ucs4(findCO->currentText()),
121 qstring_to_ucs4(replaceCO->currentText()),
122 caseCB->isChecked(), wordsCB->isChecked(), true, true);
123 uniqueInsert(findCO, findCO->currentText());
124 uniqueInsert(replaceCO, replaceCO->currentText());
128 void GuiSearch::find(docstring const & search, bool casesensitive,
129 bool matchword, bool forward)
131 docstring const data = find2string(search, casesensitive,
133 dispatch(FuncRequest(LFUN_WORD_FIND, data));
137 void GuiSearch::replace(docstring const & search, docstring const & replace,
138 bool casesensitive, bool matchword,
139 bool forward, bool all)
141 docstring const data =
142 replace2string(search, replace, casesensitive,
143 matchword, all, forward);
144 dispatch(FuncRequest(LFUN_WORD_REPLACE, data));
147 Dialog * createGuiSearch(LyXView & lv) { return new GuiSearch(lv); }
150 } // namespace frontend
154 #include "GuiSearch_moc.cpp"