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.
15 #include "qt_helpers.h"
18 #include "controllers/ControlSearch.h"
21 #include <QCloseEvent>
29 /////////////////////////////////////////////////////////////////////
33 /////////////////////////////////////////////////////////////////////
36 static void uniqueInsert(QComboBox * box, QString const & text)
38 for (int i = 0; i < box->count(); ++i) {
39 if (box->itemText(i) == text)
47 QSearchDialog::QSearchDialog(QSearch * form)
52 connect(closePB, SIGNAL(clicked()), form_, SLOT(slotClose()));
53 connect(findPB, SIGNAL(clicked()), this, SLOT(findClicked()));
54 connect(replacePB, SIGNAL(clicked()), this, SLOT(replaceClicked()));
55 connect(replaceallPB, SIGNAL(clicked()), this, SLOT(replaceallClicked()));
56 connect(findCO, SIGNAL(editTextChanged(const QString &)),
57 this, SLOT(findChanged()));
59 setFocusProxy(findCO);
63 void QSearchDialog::show()
66 findCO->lineEdit()->setSelection(0, findCO->lineEdit()->text().length());
70 void QSearchDialog::closeEvent(QCloseEvent * e)
77 void QSearchDialog::findChanged()
79 if (findCO->currentText().isEmpty()) {
80 findPB->setEnabled(false);
81 replacePB->setEnabled(false);
82 replaceallPB->setEnabled(false);
84 findPB->setEnabled(true);
85 replacePB->setEnabled(!form_->readOnly());
86 replaceallPB->setEnabled(!form_->readOnly());
91 void QSearchDialog::findClicked()
93 docstring const find = qstring_to_ucs4(findCO->currentText());
97 backwardsCB->isChecked());
98 uniqueInsert(findCO, findCO->currentText());
102 void QSearchDialog::replaceClicked()
104 docstring const find = qstring_to_ucs4(findCO->currentText());
105 docstring const replace = qstring_to_ucs4(replaceCO->currentText());
106 form_->replace(find, replace,
108 wordsCB->isChecked(),
109 backwardsCB->isChecked(), false);
110 uniqueInsert(findCO, findCO->currentText());
111 uniqueInsert(replaceCO, replaceCO->currentText());
115 void QSearchDialog::replaceallClicked()
117 form_->replace(qstring_to_ucs4(findCO->currentText()),
118 qstring_to_ucs4(replaceCO->currentText()),
120 wordsCB->isChecked(),
122 uniqueInsert(findCO, findCO->currentText());
123 uniqueInsert(replaceCO, replaceCO->currentText());
127 /////////////////////////////////////////////////////////////////////
131 /////////////////////////////////////////////////////////////////////
134 typedef QController<ControlSearch, QView<QSearchDialog> > SearchBase;
137 QSearch::QSearch(Dialog & parent)
138 : SearchBase(parent, _("Find and Replace"))
143 void QSearch::build_dialog()
145 dialog_.reset(new QSearchDialog(this));
147 bcview().setCancel(dialog_->closePB);
148 bcview().addReadOnly(dialog_->replaceCO);
149 bcview().addReadOnly(dialog_->replacePB);
150 bcview().addReadOnly(dialog_->replaceallPB);
152 dialog_->replacePB->setEnabled(false);
153 dialog_->replaceallPB->setEnabled(false);
157 void QSearch::find(docstring const & str, bool casesens,
158 bool words, bool backwards)
160 controller().find(str, casesens, words, !backwards);
164 void QSearch::replace(docstring const & findstr, docstring const & replacestr,
165 bool casesens, bool words, bool backwards, bool all)
167 controller().replace(findstr, replacestr, casesens, words,
171 } // namespace frontend
175 #include "QSearch_moc.cpp"