26
26
#include "FBReader.h"
27
27
#include "FBReaderActions.h"
29
SearchAction::SearchAction(FBReader &fbreader) : FBAction(fbreader) {
28
#include "../options/FBOptions.h"
32
static const std::string SEARCH = "Search";
33
static const std::string PATTERN = "Pattern";
35
class SearchPatternEntry : public ZLComboOptionEntry {
38
SearchPatternEntry(SearchAction &action);
40
const std::string &initialValue() const;
41
const std::vector<std::string> &values() const;
42
void onAccept(const std::string &value);
45
SearchAction &myAction;
46
mutable std::vector<std::string> myValues;
49
SearchPatternEntry::SearchPatternEntry(SearchAction &action) : ZLComboOptionEntry(true), myAction(action) {
52
const std::string &SearchPatternEntry::initialValue() const {
56
const std::vector<std::string> &SearchPatternEntry::values() const {
57
if (myValues.empty()) {
59
myValues.push_back(myAction.SearchPatternOption.value());
60
for (int i = 1; i < 6; ++i) {
61
std::string pattern = PATTERN;
62
ZLStringUtil::appendNumber(pattern, i);
63
std::string value = ZLStringOption(FBCategoryKey::SEARCH, SEARCH, pattern, "").value();
65
myValues.push_back(value);
72
void SearchPatternEntry::onAccept(const std::string &value) {
73
std::string v = value;
74
ZLStringUtil::stripWhiteSpaces(v);
75
if (!v.empty() && (v != values()[0])) {
76
myAction.SearchPatternOption.setValue(v);
78
for (std::vector<std::string>::const_iterator it = myValues.begin(); (index < 6) && (it != myValues.end()); ++it) {
80
std::string pattern = PATTERN;
81
ZLStringUtil::appendNumber(pattern, index++);
82
ZLStringOption(FBCategoryKey::SEARCH, SEARCH, pattern, "").setValue(*it);
88
SearchAction::SearchAction(FBReader &fbreader) : FBAction(fbreader),
89
SearchBackwardOption(FBCategoryKey::SEARCH, SEARCH, "Backward", false),
90
SearchIgnoreCaseOption(FBCategoryKey::SEARCH, SEARCH, "IgnoreCase", true),
91
SearchInWholeTextOption(FBCategoryKey::SEARCH, SEARCH, "WholeText", false),
92
SearchThisSectionOnlyOption(FBCategoryKey::SEARCH, SEARCH, "ThisSectionOnly", false),
93
SearchPatternOption(FBCategoryKey::SEARCH, SEARCH, PATTERN, "") {
32
96
bool SearchAction::isVisible() {
39
103
shared_ptr<ZLDialog> searchDialog = ZLDialogManager::instance().createDialog(ZLResourceKey("textSearchDialog"));
41
searchDialog->addOption(ZLResourceKey("text"), fbreader().SearchPatternOption);
42
searchDialog->addOption(ZLResourceKey("ignoreCase"), fbreader().SearchIgnoreCaseOption);
43
searchDialog->addOption(ZLResourceKey("wholeText"), fbreader().SearchInWholeTextOption);
44
searchDialog->addOption(ZLResourceKey("backward"), fbreader().SearchBackwardOption);
105
searchDialog->addOption(ZLResourceKey("text"), new SearchPatternEntry(*this));
106
searchDialog->addOption(ZLResourceKey("ignoreCase"), SearchIgnoreCaseOption);
107
searchDialog->addOption(ZLResourceKey("wholeText"), SearchInWholeTextOption);
108
searchDialog->addOption(ZLResourceKey("backward"), SearchBackwardOption);
45
109
if (textView.hasMultiSectionModel()) {
46
searchDialog->addOption(ZLResourceKey("currentSection"), fbreader().SearchThisSectionOnlyOption);
110
searchDialog->addOption(ZLResourceKey("currentSection"), SearchThisSectionOnlyOption);
48
112
searchDialog->addButton(ZLResourceKey("go"), true);
49
113
searchDialog->addButton(ZLDialogManager::CANCEL_BUTTON, false);
51
115
if (searchDialog->run()) {
52
116
searchDialog->acceptValues();
53
std::string pattern = fbreader().SearchPatternOption.value();
54
ZLStringUtil::stripWhiteSpaces(pattern);
55
fbreader().SearchPatternOption.setValue(pattern);
58
fbreader().SearchIgnoreCaseOption.value(),
59
fbreader().SearchInWholeTextOption.value(),
60
fbreader().SearchBackwardOption.value(),
61
fbreader().SearchThisSectionOnlyOption.value()
118
SearchPatternOption.value(),
119
SearchIgnoreCaseOption.value(),
120
SearchInWholeTextOption.value(),
121
SearchBackwardOption.value(),
122
SearchThisSectionOnlyOption.value()