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 "qt_helpers.h"
19 #include "FuncRequest.h"
30 static void uniqueInsert(QComboBox * box, QString const & text)
32 for (int i = box->count(); --i >= 0; )
33 if (box->itemText(i) == text)
40 GuiSearch::GuiSearch(GuiView & lv)
41 : GuiDialog(lv, "findreplace", qt_("Find and Replace"))
45 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
46 connect(findPB, SIGNAL(clicked()), this, SLOT(findClicked()));
47 connect(replacePB, SIGNAL(clicked()), this, SLOT(replaceClicked()));
48 connect(replaceallPB, SIGNAL(clicked()), this, SLOT(replaceallClicked()));
49 connect(findCO, SIGNAL(editTextChanged(QString)),
50 this, SLOT(findChanged()));
52 setFocusProxy(findCO);
54 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
55 bc().setCancel(closePB);
56 bc().addReadOnly(replaceCO);
57 bc().addReadOnly(replacePB);
58 bc().addReadOnly(replaceallPB);
60 replacePB->setEnabled(false);
61 replaceallPB->setEnabled(false);
65 void GuiSearch::showEvent(QShowEvent * e)
67 findCO->lineEdit()->selectAll();
68 GuiDialog::showEvent(e);
72 void GuiSearch::findChanged()
74 if (findCO->currentText().isEmpty()) {
75 findPB->setEnabled(false);
76 replacePB->setEnabled(false);
77 replaceallPB->setEnabled(false);
79 findPB->setEnabled(true);
80 replacePB->setEnabled(!isBufferReadonly());
81 replaceallPB->setEnabled(!isBufferReadonly());
86 void GuiSearch::findClicked()
88 docstring const needle = qstring_to_ucs4(findCO->currentText());
89 find(needle, caseCB->isChecked(), wordsCB->isChecked(),
90 !backwardsCB->isChecked());
91 uniqueInsert(findCO, findCO->currentText());
92 findCO->lineEdit()->selectAll();
96 void GuiSearch::replaceClicked()
98 docstring const needle = qstring_to_ucs4(findCO->currentText());
99 docstring const repl = qstring_to_ucs4(replaceCO->currentText());
100 replace(needle, repl, caseCB->isChecked(), wordsCB->isChecked(),
101 !backwardsCB->isChecked(), false);
102 uniqueInsert(findCO, findCO->currentText());
103 uniqueInsert(replaceCO, replaceCO->currentText());
107 void GuiSearch::replaceallClicked()
109 replace(qstring_to_ucs4(findCO->currentText()),
110 qstring_to_ucs4(replaceCO->currentText()),
111 caseCB->isChecked(), wordsCB->isChecked(), true, true);
112 uniqueInsert(findCO, findCO->currentText());
113 uniqueInsert(replaceCO, replaceCO->currentText());
117 void GuiSearch::find(docstring const & search, bool casesensitive,
118 bool matchword, bool forward)
120 docstring const data =
121 find2string(search, casesensitive, matchword, forward);
122 dispatch(FuncRequest(LFUN_WORD_FIND, data));
126 void GuiSearch::replace(docstring const & search, docstring const & replace,
127 bool casesensitive, bool matchword,
128 bool forward, bool all)
130 docstring const data =
131 replace2string(search, replace, casesensitive,
132 matchword, all, forward);
133 dispatch(FuncRequest(LFUN_WORD_REPLACE, data));
136 Dialog * createGuiSearch(GuiView & lv) { return new GuiSearch(lv); }
139 } // namespace frontend
143 #include "GuiSearch_moc.cpp"