10#include <QButtonGroup>
13#include <QCoreApplication>
29 : MantidDialog(editor), m_editor(editor), m_findInProgress(false) {
31 setSizeGripEnabled(
true);
38 auto *gb1 =
new QGroupBox();
41 m_topLayout->addWidget(
new QLabel(tr(
"Find")), 0, 0);
44 boxFind->setDuplicatesEnabled(
false);
45 boxFind->setInsertPolicy(QComboBox::InsertAtTop);
47 boxFind->setMaxVisibleItems(10);
49 boxFind->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
56 auto *gb2 =
new QGroupBox();
57 auto *bottomLayout =
new QGridLayout(gb2);
58 auto *find_options =
new QButtonGroup(
this);
59 find_options->setExclusive(
false);
71 boxRegex =
new QCheckBox(tr(
"&Regular expression"));
73 bottomLayout->addWidget(
boxRegex, 2, 0);
85 connect(find_options, SIGNAL(buttonClicked(
int)),
this, SLOT(
resetSearchFlags()));
87 auto *vb1 =
new QVBoxLayout();
91 m_vb2 =
new QVBoxLayout();
104 connect(
buttonCancel, SIGNAL(clicked()),
this, SLOT(reject()));
106 auto *hb =
new QHBoxLayout(
this);
108 hb->addLayout(
m_vb2);
113 setWindowTitle(QCoreApplication::applicationName() +
" - Find and Replace");
114 m_topLayout->addWidget(
new QLabel(tr(
"Replace with")), 1, 0);
118 boxReplace->setInsertPolicy(QComboBox::InsertAtTop);
121 boxReplace->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
147 QString searchString =
boxFind->currentText();
148 if (searchString.isEmpty()) {
149 QMessageBox::warning(
this, tr(
"Empty Search Field"),
150 tr(
"The search field is empty. Please enter some text and try again."));
155 if (
boxFind->findText(searchString) == -1) {
156 boxFind->addItem(searchString);
175 QString searchString =
boxFind->currentText();
176 if (searchString.isEmpty()) {
177 QMessageBox::warning(
this, tr(
"Empty Search Field"),
178 tr(
"The search field is empty. Please enter some text and try again."));
183 if (!
m_editor->hasSelectedText() ||
m_editor->selectedText() != searchString) {
188 QString replaceString =
boxReplace->currentText();
192 if (
boxReplace->findText(replaceString) == -1) {
201 QString searchString =
boxFind->currentText();
202 if (searchString.isEmpty()) {
203 QMessageBox::warning(
this, tr(
"Empty Search Field"),
204 tr(
"The search field is empty. Please enter some text and try again."));
209 if (
boxFind->findText(searchString) == -1) {
210 boxFind->addItem(searchString);
213 QString replaceString =
boxReplace->currentText();
214 if (
boxReplace->findText(replaceString) == -1) {
257 QString text =
m_editor->selectedText();
void resetSearchFlags()
Reset the search flags due to changes.
QCheckBox * boxCaseSensitive
Case-sensitive check box.
QComboBox * boxFind
Find box.
bool find(bool backwards=false)
Find.
void clearEditorSelection()
Clear the editor selection.
void showEvent(QShowEvent *event) override
Called when the widget is shown.
QCheckBox * boxWholeWords
Whole words check box.
QCheckBox * boxWrapAround
Wrap around.
void findClicked()
A slot for the findClicked button.
QComboBox * boxReplace
Replace box.
QPushButton * buttonReplace
Replace text button.
void addReplaceButtons()
Add the replace buttons.
FindReplaceDialog(ScriptEditor *editor)
Constructor.
void initLayout()
Create the layout.
QPushButton * buttonReplaceAll
Replace all text button.
void findNotInProgress()
Set the flag about whether we are currently finding.
QGridLayout * m_topLayout
void replace()
Replace slot.
QCheckBox * boxSearchBackwards
Search backwards.
QCheckBox * boxRegex
Treat as regular expressions.
bool m_findInProgress
If a find is in progress.
void replaceAll()
Replace all slot.
QPushButton * buttonNext
Find next match button.
ScriptEditor * m_editor
The text editor we are working on.
QPushButton * buttonCancel
Cancel dialog button.
void addReplaceBox()
Add replace box.
This class provides an area to write scripts.
void replaceAll(const QString &search, const QString &replace, bool regex, bool caseSensitive, bool matchWords, bool wrap, bool forward=true)
Replace all occurences of a string.