]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QSearchDialog.C
Minipage is no more (long live the box inset)
[lyx.git] / src / frontends / qt2 / QSearchDialog.C
1 /**
2  * \file QSearchDialog.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Edwin Leuven
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13
14 #include "ControlSearch.h"
15 #include "QSearchDialog.h"
16 #include "QSearch.h"
17 #include "qt_helpers.h"
18
19 #include <qpushbutton.h>
20 #include <qcombobox.h>
21 #include <qcheckbox.h>
22 #include <qlineedit.h>
23
24 using std::string;
25
26 namespace {
27
28 void uniqueInsert(QComboBox * box, QString const & text)
29 {
30         for (int i = 0; i < box->count(); ++i) {
31                 if (box->text(i) == text)
32                         return;
33         }
34
35         box->insertItem(text);
36 }
37
38 };
39
40
41 QSearchDialog::QSearchDialog(QSearch * form)
42         : QSearchDialogBase(0, 0, false, 0),
43         form_(form)
44 {
45         connect(closePB, SIGNAL(clicked()),
46                 form_, SLOT(slotClose()));
47 }
48
49
50 void QSearchDialog::show()
51 {
52         QSearchDialogBase::show();
53         findCO->setFocus();
54         findCO->lineEdit()->setSelection(0, findCO->lineEdit()->text().length());
55 }
56
57
58 void QSearchDialog::closeEvent(QCloseEvent * e)
59 {
60         form_->slotWMHide();
61         e->accept();
62 }
63
64
65 void QSearchDialog::findChanged()
66 {
67         if (findCO->currentText().isEmpty()) {
68                 findPB->setEnabled(false);
69                 replacePB->setEnabled(false);
70                 replaceallPB->setEnabled(false);
71         } else {
72                 findPB->setEnabled(true);
73                 replacePB->setEnabled(!form_->readOnly());
74                 replaceallPB->setEnabled(!form_->readOnly());
75         }
76 }
77
78
79 void QSearchDialog::findClicked()
80 {
81         string const find(fromqstr(findCO->currentText()));
82         form_->find(find,
83                 caseCB->isChecked(),
84                 wordsCB->isChecked(),
85                 backwardsCB->isChecked());
86         uniqueInsert(findCO, findCO->currentText());
87 }
88
89
90 void QSearchDialog::replaceClicked()
91 {
92         string const find(fromqstr(findCO->currentText()));
93         string const replace(fromqstr(replaceCO->currentText()));
94         form_->replace(find, replace,
95                 caseCB->isChecked(),
96                 wordsCB->isChecked(),
97                 backwardsCB->isChecked(), false);
98         uniqueInsert(findCO, findCO->currentText());
99         uniqueInsert(replaceCO, replaceCO->currentText());
100 }
101
102
103 void QSearchDialog::replaceallClicked()
104 {
105         form_->replace(fromqstr(findCO->currentText()),
106                 fromqstr(replaceCO->currentText()),
107                 caseCB->isChecked(),
108                 wordsCB->isChecked(),
109                 false, true);
110         uniqueInsert(findCO, findCO->currentText());
111         uniqueInsert(replaceCO, replaceCO->currentText());
112 }