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"
15 #include "qt_helpers.h"
19 #include <QCloseEvent>
27 /////////////////////////////////////////////////////////////////////
31 /////////////////////////////////////////////////////////////////////
34 static void uniqueInsert(QComboBox * box, QString const & text)
36 for (int i = 0; i < box->count(); ++i) {
37 if (box->itemText(i) == text)
45 GuiSearchDialog::GuiSearchDialog(GuiSearch * form)
50 connect(closePB, SIGNAL(clicked()), form_, SLOT(slotClose()));
51 connect(findPB, SIGNAL(clicked()), this, SLOT(findClicked()));
52 connect(replacePB, SIGNAL(clicked()), this, SLOT(replaceClicked()));
53 connect(replaceallPB, SIGNAL(clicked()), this, SLOT(replaceallClicked()));
54 connect(findCO, SIGNAL(editTextChanged(const QString &)),
55 this, SLOT(findChanged()));
57 setFocusProxy(findCO);
61 void GuiSearchDialog::show()
64 findCO->lineEdit()->setSelection(0, findCO->lineEdit()->text().length());
68 void GuiSearchDialog::closeEvent(QCloseEvent * e)
75 void GuiSearchDialog::findChanged()
77 if (findCO->currentText().isEmpty()) {
78 findPB->setEnabled(false);
79 replacePB->setEnabled(false);
80 replaceallPB->setEnabled(false);
82 findPB->setEnabled(true);
83 replacePB->setEnabled(!form_->readOnly());
84 replaceallPB->setEnabled(!form_->readOnly());
89 void GuiSearchDialog::findClicked()
91 docstring const find = qstring_to_ucs4(findCO->currentText());
95 backwardsCB->isChecked());
96 uniqueInsert(findCO, findCO->currentText());
97 findCO->lineEdit()->setSelection(0, findCO->lineEdit()->text().length());
101 void GuiSearchDialog::replaceClicked()
103 docstring const find = qstring_to_ucs4(findCO->currentText());
104 docstring const replace = qstring_to_ucs4(replaceCO->currentText());
105 form_->replace(find, replace,
107 wordsCB->isChecked(),
108 backwardsCB->isChecked(), false);
109 uniqueInsert(findCO, findCO->currentText());
110 uniqueInsert(replaceCO, replaceCO->currentText());
114 void GuiSearchDialog::replaceallClicked()
116 form_->replace(qstring_to_ucs4(findCO->currentText()),
117 qstring_to_ucs4(replaceCO->currentText()),
119 wordsCB->isChecked(),
121 uniqueInsert(findCO, findCO->currentText());
122 uniqueInsert(replaceCO, replaceCO->currentText());
126 /////////////////////////////////////////////////////////////////////
130 /////////////////////////////////////////////////////////////////////
133 GuiSearch::GuiSearch(Dialog & parent)
134 : GuiView<GuiSearchDialog>(parent, _("Find and Replace"))
139 void GuiSearch::build_dialog()
141 dialog_.reset(new GuiSearchDialog(this));
143 bcview().setCancel(dialog_->closePB);
144 bcview().addReadOnly(dialog_->replaceCO);
145 bcview().addReadOnly(dialog_->replacePB);
146 bcview().addReadOnly(dialog_->replaceallPB);
148 dialog_->replacePB->setEnabled(false);
149 dialog_->replaceallPB->setEnabled(false);
153 void GuiSearch::find(docstring const & str, bool casesens,
154 bool words, bool backwards)
156 controller().find(str, casesens, words, !backwards);
160 void GuiSearch::replace(docstring const & findstr, docstring const & replacestr,
161 bool casesens, bool words, bool backwards, bool all)
163 controller().replace(findstr, replacestr, casesens, words,
167 } // namespace frontend
171 #include "GuiSearch_moc.cpp"