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"
18 #include <QCloseEvent>
26 /////////////////////////////////////////////////////////////////////
30 /////////////////////////////////////////////////////////////////////
33 static void uniqueInsert(QComboBox * box, QString const & text)
35 for (int i = 0; i < box->count(); ++i) {
36 if (box->itemText(i) == text)
44 GuiSearchDialog::GuiSearchDialog(GuiSearch * form)
49 connect(closePB, SIGNAL(clicked()), form_, 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);
60 void GuiSearchDialog::show()
63 findCO->lineEdit()->setSelection(0, findCO->lineEdit()->text().length());
67 void GuiSearchDialog::closeEvent(QCloseEvent * e)
74 void GuiSearchDialog::findChanged()
76 if (findCO->currentText().isEmpty()) {
77 findPB->setEnabled(false);
78 replacePB->setEnabled(false);
79 replaceallPB->setEnabled(false);
81 findPB->setEnabled(true);
82 replacePB->setEnabled(!form_->readOnly());
83 replaceallPB->setEnabled(!form_->readOnly());
88 void GuiSearchDialog::findClicked()
90 docstring const find = qstring_to_ucs4(findCO->currentText());
94 backwardsCB->isChecked());
95 uniqueInsert(findCO, findCO->currentText());
96 findCO->lineEdit()->setSelection(0, findCO->lineEdit()->text().length());
100 void GuiSearchDialog::replaceClicked()
102 docstring const find = qstring_to_ucs4(findCO->currentText());
103 docstring const replace = qstring_to_ucs4(replaceCO->currentText());
104 form_->replace(find, replace,
106 wordsCB->isChecked(),
107 backwardsCB->isChecked(), false);
108 uniqueInsert(findCO, findCO->currentText());
109 uniqueInsert(replaceCO, replaceCO->currentText());
113 void GuiSearchDialog::replaceallClicked()
115 form_->replace(qstring_to_ucs4(findCO->currentText()),
116 qstring_to_ucs4(replaceCO->currentText()),
118 wordsCB->isChecked(),
120 uniqueInsert(findCO, findCO->currentText());
121 uniqueInsert(replaceCO, replaceCO->currentText());
125 /////////////////////////////////////////////////////////////////////
129 /////////////////////////////////////////////////////////////////////
132 GuiSearch::GuiSearch(GuiDialog & parent)
133 : GuiView<GuiSearchDialog>(parent, _("Find and Replace"))
138 void GuiSearch::build_dialog()
140 dialog_.reset(new GuiSearchDialog(this));
142 bc().setCancel(dialog_->closePB);
143 bc().addReadOnly(dialog_->replaceCO);
144 bc().addReadOnly(dialog_->replacePB);
145 bc().addReadOnly(dialog_->replaceallPB);
147 dialog_->replacePB->setEnabled(false);
148 dialog_->replaceallPB->setEnabled(false);
152 void GuiSearch::find(docstring const & str, bool casesens,
153 bool words, bool backwards)
155 controller().find(str, casesens, words, !backwards);
159 void GuiSearch::replace(docstring const & findstr, docstring const & replacestr,
160 bool casesens, bool words, bool backwards, bool all)
162 controller().replace(findstr, replacestr, casesens, words,
166 } // namespace frontend
170 #include "GuiSearch_moc.cpp"