10#include <QButtonGroup>
28 : MantidDialog(editor), m_editor(editor), m_findInProgress(false) {
30 setSizeGripEnabled(
true);
37 auto *gb1 =
new QGroupBox();
40 m_topLayout->addWidget(
new QLabel(tr(
"Find")), 0, 0);
43 boxFind->setDuplicatesEnabled(
false);
44 boxFind->setInsertPolicy(QComboBox::InsertAtTop);
46 boxFind->setMaxVisibleItems(10);
48 boxFind->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
55 auto *gb2 =
new QGroupBox();
56 auto *bottomLayout =
new QGridLayout(gb2);
57 auto *find_options =
new QButtonGroup(
this);
58 find_options->setExclusive(
false);
70 boxRegex =
new QCheckBox(tr(
"&Regular expression"));
72 bottomLayout->addWidget(
boxRegex, 2, 0);
84 connect(find_options, SIGNAL(buttonClicked(
int)),
this, SLOT(
resetSearchFlags()));
86 auto *vb1 =
new QVBoxLayout();
90 m_vb2 =
new QVBoxLayout();
103 connect(
buttonCancel, SIGNAL(clicked()),
this, SLOT(reject()));
105 auto *hb =
new QHBoxLayout(
this);
107 hb->addLayout(
m_vb2);
112 setWindowTitle(tr(
"MantidPlot") +
" - " + tr(
"Find and Replace"));
113 m_topLayout->addWidget(
new QLabel(tr(
"Replace with")), 1, 0);
117 boxReplace->setInsertPolicy(QComboBox::InsertAtTop);
120 boxReplace->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
146 QString searchString =
boxFind->currentText();
147 if (searchString.isEmpty()) {
148 QMessageBox::warning(
this, tr(
"Empty Search Field"),
149 tr(
"The search field is empty. Please enter some text and try again."));
154 if (
boxFind->findText(searchString) == -1) {
155 boxFind->addItem(searchString);
174 QString searchString =
boxFind->currentText();
175 if (searchString.isEmpty()) {
176 QMessageBox::warning(
this, tr(
"Empty Search Field"),
177 tr(
"The search field is empty. Please enter some text and try again."));
182 if (!
m_editor->hasSelectedText() ||
m_editor->selectedText() != searchString) {
187 QString replaceString =
boxReplace->currentText();
191 if (
boxReplace->findText(replaceString) == -1) {
200 QString searchString =
boxFind->currentText();
201 if (searchString.isEmpty()) {
202 QMessageBox::warning(
this, tr(
"Empty Search Field"),
203 tr(
"The search field is empty. Please enter some text and try again."));
208 if (
boxFind->findText(searchString) == -1) {
209 boxFind->addItem(searchString);
212 QString replaceString =
boxReplace->currentText();
213 if (
boxReplace->findText(replaceString) == -1) {
256 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.