]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QSearchDialog.C
some tabular fixes for the problems reported by Helge
[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 #include "QSearchDialog.h"
14 #include "QSearch.h"
15 #include "qt_helpers.h"
16
17 #include "controllers/ControlSearch.h"
18
19 #include <qcheckbox.h>
20 #include <qcombobox.h>
21 #include <qlineedit.h>
22 #include <qpushbutton.h>
23
24 using std::string;
25
26 namespace lyx {
27 namespace frontend {
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                 backwardsCB->isChecked(), 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                 false, true);
113         uniqueInsert(findCO, findCO->currentText());
114         uniqueInsert(replaceCO, replaceCO->currentText());
115 }
116
117 } // namespace frontend
118 } // namespace lyx