-
Notifications
You must be signed in to change notification settings - Fork 0
/
searchbar.cpp
109 lines (82 loc) · 3.37 KB
/
searchbar.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*===========================================================================
CLIPSEditor, editor for CLIPS (C Language Integrated Production System)
Copyright (C) 2012-2017 Novikov Artem Gennadievich
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
===========================================================================*/
#include "searchbar.h"
SearchBar::SearchBar(Config* config)
: config(config)
{
setupUi(this);
QRegExp rx("^[^\\n]+&"); // толкько одну строку
QRegExpValidator* v = new QRegExpValidator(rx, this);
cmbFind->setMaxCount(config->maxHistory);
cmbFind->addItems(config->findHistory);
cmbFind->setCurrentIndex(-1);
cmbFind->setValidator(v);
cmbReplace->setMaxCount(config->maxHistory);
cmbReplace->addItems(config->replaceHistory);
cmbReplace->setCurrentIndex(-1);
cmbReplace->setValidator(v);
chbCase->setChecked(config->matchCase);
chbRegExp->setChecked(config->regExp);
chbAllFiles->setChecked(config->allFiles);
setFixedHeight(minimumHeight());
connect(btnFindNext, SIGNAL(clicked()), SLOT(clicked()));
connect(btnFindPrev, SIGNAL(clicked()), SLOT(clicked()));
connect(btnReplaceNext, SIGNAL(clicked()), SLOT(clicked()));
connect(btnReplacePrev, SIGNAL(clicked()), SLOT(clicked()));
connect(btnReplaceAll, SIGNAL(clicked()), SLOT(clicked()));
}
void SearchBar::clicked()
{
if (cmbFind->currentText().isEmpty())
return;
update(cmbFind);
int flags = 0;
if (chbCase->isChecked())
flags |= MatchCase;
if (chbRegExp->isChecked())
flags |= RegExp;
if (chbAllFiles->isChecked())
flags |= AllFiles;
if (sender() == btnReplaceAll)
flags |= ReplaceAll;
if (sender() == btnFindPrev || sender() == btnReplacePrev)
flags |= Backward;
if (sender() == btnFindNext || sender() == btnFindPrev)
emit searchReplace(cmbFind->currentText(), 0, flags);
else if (cmbFind->currentText() != cmbReplace->currentText()) {
update(cmbReplace);
emit searchReplace(cmbFind->currentText(), cmbReplace->currentText(), flags);
}
}
void SearchBar::update(QComboBox* combo)
{
int index = combo->findText(combo->currentText());
if (index == -1)
combo->insertItem(0, combo->currentText());
else
combo->setCurrentIndex(index);
}
SearchBar::~SearchBar()
{
config->matchCase = chbCase->isChecked();
config->regExp = chbRegExp->isChecked();
config->allFiles = chbAllFiles->isChecked();
config->findHistory.clear();
for (int i = 0; i < cmbFind->count(); i++)
config->findHistory << cmbFind->itemText(i);
config->replaceHistory.clear();
for (int i = 0; i < cmbReplace->count(); i++)
config->replaceHistory << cmbReplace->itemText(i);
}