]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiSearch.cpp
some remnaming
[lyx.git] / src / frontends / qt4 / GuiSearch.cpp
1 /**
2  * \file GuiSearch.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  * \author Edwin Leuven
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "GuiSearch.h"
15
16 #include "ControlSearch.h"
17 #include "qt_helpers.h"
18
19 #include <QLineEdit>
20 #include <QCloseEvent>
21
22 using std::string;
23
24
25 namespace lyx {
26 namespace frontend {
27
28 static void uniqueInsert(QComboBox * box, QString const & text)
29 {
30         for (int i = 0; i < box->count(); ++i) {
31                 if (box->itemText(i) == text)
32                         return;
33         }
34
35         box->addItem(text);
36 }
37
38
39 GuiSearchDialog::GuiSearchDialog(LyXView & lv)
40         : GuiDialog(lv, "findreplace") 
41 {
42         setupUi(this);
43         setController(new ControlSearch(*this));
44         setViewTitle(_("Find and Replace"));
45
46         connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
47         connect(findPB, SIGNAL(clicked()), this, SLOT(findClicked()));
48         connect(replacePB, SIGNAL(clicked()), this, SLOT(replaceClicked()));
49         connect(replaceallPB, SIGNAL(clicked()), this, SLOT(replaceallClicked()));
50         connect(findCO, SIGNAL(editTextChanged(const QString &)),
51                 this, SLOT(findChanged()));
52
53         setFocusProxy(findCO);
54
55         bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
56         bc().setCancel(closePB);
57         bc().addReadOnly(replaceCO);
58         bc().addReadOnly(replacePB);
59         bc().addReadOnly(replaceallPB);
60
61         replacePB->setEnabled(false);
62         replaceallPB->setEnabled(false);
63 }
64
65
66 ControlSearch & GuiSearchDialog::controller()
67 {
68         return static_cast<ControlSearch &>(GuiDialog::controller());
69 }
70
71
72 void GuiSearchDialog::showView()
73 {
74         findCO->lineEdit()->setSelection(0, findCO->lineEdit()->text().length());
75         GuiDialog::showView();
76 }
77
78
79 void GuiSearchDialog::closeEvent(QCloseEvent * e)
80 {
81         slotClose();
82         e->accept();
83 }
84
85
86 void GuiSearchDialog::findChanged()
87 {
88         if (findCO->currentText().isEmpty()) {
89                 findPB->setEnabled(false);
90                 replacePB->setEnabled(false);
91                 replaceallPB->setEnabled(false);
92         } else {
93                 findPB->setEnabled(true);
94                 replacePB->setEnabled(!controller().isBufferReadonly());
95                 replaceallPB->setEnabled(!controller().isBufferReadonly());
96         }
97 }
98
99
100 void GuiSearchDialog::findClicked()
101 {
102         docstring const needle = qstring_to_ucs4(findCO->currentText());
103         find(needle, caseCB->isChecked(), wordsCB->isChecked(),
104                 backwardsCB->isChecked());
105         uniqueInsert(findCO, findCO->currentText());
106         findCO->lineEdit()->setSelection(0, findCO->lineEdit()->text().length());
107 }
108
109
110 void GuiSearchDialog::replaceClicked()
111 {
112         docstring const needle = qstring_to_ucs4(findCO->currentText());
113         docstring const repl = qstring_to_ucs4(replaceCO->currentText());
114         replace(needle, repl, caseCB->isChecked(), wordsCB->isChecked(),
115                 backwardsCB->isChecked(), false);
116         uniqueInsert(findCO, findCO->currentText());
117         uniqueInsert(replaceCO, replaceCO->currentText());
118 }
119
120
121 void GuiSearchDialog::replaceallClicked()
122 {
123         replace(qstring_to_ucs4(findCO->currentText()),
124                 qstring_to_ucs4(replaceCO->currentText()),
125                 caseCB->isChecked(), wordsCB->isChecked(), false, true);
126         uniqueInsert(findCO, findCO->currentText());
127         uniqueInsert(replaceCO, replaceCO->currentText());
128 }
129
130
131 void GuiSearchDialog::find(docstring const & str, bool casesens,
132         bool words, bool backwards)
133 {
134         controller().find(str, casesens, words, !backwards);
135 }
136
137
138 void GuiSearchDialog::replace(docstring const & findstr,
139         docstring const & replacestr,
140         bool casesens, bool words, bool backwards, bool all)
141 {
142         controller().replace(findstr, replacestr, casesens, words,
143                              !backwards, all);
144 }
145
146 } // namespace frontend
147 } // namespace lyx
148
149
150 #include "GuiSearch_moc.cpp"