2 * \file QSearchDialog.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "QSearchDialog.h"
15 #include "qt_helpers.h"
17 #include <QCloseEvent>
19 #include "controllers/ControlSearch.h"
21 #include <qcheckbox.h>
22 #include <qlineedit.h>
23 #include <qpushbutton.h>
32 void uniqueInsert(QComboBox * box, QString const & text)
34 for (int i = 0; i < box->count(); ++i) {
35 if (box->text(i) == text)
39 box->insertItem(text);
45 QSearchDialog::QSearchDialog(QSearch * form)
50 connect(closePB, SIGNAL(clicked()),
51 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( textChanged(const QString&) ), this, SLOT( findChanged() ) );
60 void QSearchDialog::show()
64 findCO->lineEdit()->setSelection(0, findCO->lineEdit()->text().length());
68 void QSearchDialog::closeEvent(QCloseEvent * e)
75 void QSearchDialog::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 QSearchDialog::findClicked()
91 string const find(fromqstr(findCO->currentText()));
95 backwardsCB->isChecked());
96 uniqueInsert(findCO, findCO->currentText());
100 void QSearchDialog::replaceClicked()
102 string const find(fromqstr(findCO->currentText()));
103 string const replace(fromqstr(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 QSearchDialog::replaceallClicked()
115 form_->replace(fromqstr(findCO->currentText()),
116 fromqstr(replaceCO->currentText()),
118 wordsCB->isChecked(),
120 uniqueInsert(findCO, findCO->currentText());
121 uniqueInsert(replaceCO, replaceCO->currentText());
124 } // namespace frontend