]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QSearchDialog.C
reverse last change
[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 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "ControlSearch.h"
18 #include "QSearchDialog.h"
19 #include "QSearch.h"
20 #include "debug.h"
21 #include "qt_helpers.h"
22
23 #include <qpushbutton.h>
24 #include <qcombobox.h>
25 #include <qcheckbox.h>
26 #include <qlineedit.h>
27 #include <qlabel.h>
28
29 namespace {
30
31 void uniqueInsert(QComboBox * box, QString const & text)
32 {
33         for (int i = 0; i < box->count(); ++i) {
34                 if (box->text(i) == text)
35                         return;
36         }
37
38         box->insertItem(text);
39 }
40  
41 };
42  
43
44 QSearchDialog::QSearchDialog(QSearch * form)
45         : QSearchDialogBase(0, 0, false, 0),
46         form_(form)
47 {
48         connect(closePB, SIGNAL(clicked()),
49                 form_, SLOT(slotClose()));
50 }
51
52
53 void QSearchDialog::show()
54 {
55         QSearchDialogBase::show();
56         findCO->setFocus();
57         findCO->lineEdit()->setSelection(0, findCO->lineEdit()->text().length());
58 }
59
60
61 void QSearchDialog::closeEvent(QCloseEvent * e)
62 {
63         form_->slotWMHide();
64         e->accept();
65 }
66
67
68 void QSearchDialog::findChanged()
69 {
70         if (findCO->currentText().isEmpty()) {
71                 findPB->setEnabled(false);
72                 replacePB->setEnabled(false);
73                 replaceallPB->setEnabled(false);
74         } else {
75                 findPB->setEnabled(true);
76                 replacePB->setEnabled(!form_->readOnly());
77                 replaceallPB->setEnabled(!form_->readOnly());
78         }
79 }
80
81
82 void QSearchDialog::findClicked()
83 {
84         string const find(fromqstr(findCO->currentText()));
85         form_->find(find,
86                 caseCB->isChecked(),
87                 wordsCB->isChecked(),
88                 backwardsCB->isChecked());
89         uniqueInsert(findCO, findCO->currentText());
90 }
91
92
93 void QSearchDialog::replaceClicked()
94 {
95         string const find(fromqstr(findCO->currentText()));
96         string const replace(fromqstr(replaceCO->currentText()));
97         form_->replace(find, replace,
98                 caseCB->isChecked(),
99                 wordsCB->isChecked(),
100                 false);
101         uniqueInsert(findCO, findCO->currentText());
102         uniqueInsert(replaceCO, replaceCO->currentText());
103 }
104
105
106 void QSearchDialog::replaceallClicked()
107 {
108         form_->replace(fromqstr(findCO->currentText()),
109                 fromqstr(replaceCO->currentText()),
110                 caseCB->isChecked(),
111                 wordsCB->isChecked(),
112                 true);
113         uniqueInsert(findCO, findCO->currentText());
114         uniqueInsert(replaceCO, replaceCO->currentText());
115 }