3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * \author Angus Leeming
10 * Full author contact details are available in file CREDITS.
16 #include "qt_helpers.h"
17 #include "FuncRequest.h"
18 #include "BufferView.h"
21 #include "GuiSearch.h"
24 #include "support/gettext.h"
25 #include "frontends/alert.h"
35 static void uniqueInsert(QComboBox * box, QString const & text)
37 for (int i = box->count(); --i >= 0; )
38 if (box->itemText(i) == text)
41 box->insertItem(0, text);
45 GuiSearch::GuiSearch(GuiView & lv)
46 : GuiDialog(lv, "findreplace", qt_("Find and Replace"))
50 connect(buttonBox, SIGNAL(clicked(QAbstractButton *)),
51 this, SLOT(slotButtonBox(QAbstractButton *)));
52 connect(findPB, SIGNAL(clicked()), this, SLOT(findClicked()));
53 connect(replacePB, SIGNAL(clicked()), this, SLOT(replaceClicked()));
54 connect(replaceallPB, SIGNAL(clicked()), this, SLOT(replaceallClicked()));
55 connect(findCO, SIGNAL(editTextChanged(QString)),
56 this, SLOT(findChanged()));
58 setFocusProxy(findCO);
60 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
61 bc().setCancel(buttonBox->button(QDialogButtonBox::Close));
62 bc().addReadOnly(replaceCO);
63 bc().addReadOnly(replacePB);
64 bc().addReadOnly(replaceallPB);
66 replacePB->setEnabled(false);
67 replaceallPB->setEnabled(false);
71 void GuiSearch::showEvent(QShowEvent * e)
74 findCO->lineEdit()->selectAll();
75 GuiDialog::showEvent(e);
79 void GuiSearch::findChanged()
81 if (findCO->currentText().isEmpty()) {
82 findPB->setEnabled(false);
83 replacePB->setEnabled(false);
84 replaceallPB->setEnabled(false);
86 findPB->setEnabled(true);
87 replacePB->setEnabled(!isBufferReadonly());
88 replaceallPB->setEnabled(!isBufferReadonly());
93 void GuiSearch::findClicked()
95 docstring const needle = qstring_to_ucs4(findCO->currentText());
96 find(needle, caseCB->isChecked(), wordsCB->isChecked(),
97 !backwardsCB->isChecked());
98 uniqueInsert(findCO, findCO->currentText());
99 findCO->lineEdit()->selectAll();
103 void GuiSearch::replaceClicked()
105 docstring const needle = qstring_to_ucs4(findCO->currentText());
106 docstring const repl = qstring_to_ucs4(replaceCO->currentText());
107 replace(needle, repl, caseCB->isChecked(), wordsCB->isChecked(),
108 !backwardsCB->isChecked(), false);
109 uniqueInsert(findCO, findCO->currentText());
110 uniqueInsert(replaceCO, replaceCO->currentText());
114 void GuiSearch::replaceallClicked()
116 replace(qstring_to_ucs4(findCO->currentText()),
117 qstring_to_ucs4(replaceCO->currentText()),
118 caseCB->isChecked(), wordsCB->isChecked(), true, true);
119 uniqueInsert(findCO, findCO->currentText());
120 uniqueInsert(replaceCO, replaceCO->currentText());
124 void GuiSearch::find(docstring const & search, bool casesensitive,
125 bool matchword, bool forward)
127 docstring const sdata =
128 find2string(search, casesensitive, matchword, forward);
129 dispatch(FuncRequest(LFUN_WORD_FIND, sdata));
133 void GuiSearch::replace(docstring const & search, docstring const & replace,
134 bool casesensitive, bool matchword,
135 bool forward, bool all)
137 docstring const sdata =
138 replace2string(replace, search, casesensitive,
139 matchword, all, forward);
140 dispatch(FuncRequest(LFUN_WORD_REPLACE, sdata));
144 Dialog * createGuiSearch(GuiView & lv) { return new GuiSearch(lv); }
147 } // namespace frontend
151 #include "moc_GuiSearch.cpp"