2
* Copyright (C) 2004-2008 Geometer Plus <contact@geometerplus.com>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20
#include <ZLDialogManager.h>
22
#include <ZLStringUtil.h>
24
#include <ZLTextView.h>
27
#include "FBReaderActions.h"
29
SearchAction::SearchAction(FBReader &fbreader) : FBAction(fbreader) {
32
bool SearchAction::isVisible() {
33
return !fbreader().currentView().isNull();
36
void SearchAction::run() {
37
ZLTextView &textView = (ZLTextView&)*fbreader().currentView();
39
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);
45
if (textView.hasMultiSectionModel()) {
46
searchDialog->addOption(ZLResourceKey("currentSection"), fbreader().SearchThisSectionOnlyOption);
48
searchDialog->addButton(ZLResourceKey("go"), true);
49
searchDialog->addButton(ZLDialogManager::CANCEL_BUTTON, false);
51
if (searchDialog->run()) {
52
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()
66
FindNextAction::FindNextAction(FBReader &fbreader) : FBAction(fbreader) {
69
bool FindNextAction::isEnabled() {
70
shared_ptr<ZLView> view = fbreader().currentView();
71
return (!view.isNull()) && ((ZLTextView&)*view).canFindNext();
74
void FindNextAction::run() {
75
((ZLTextView&)*fbreader().currentView()).findNext();
78
FindPreviousAction::FindPreviousAction(FBReader &fbreader) : FBAction(fbreader) {
81
bool FindPreviousAction::isEnabled() {
82
shared_ptr<ZLView> view = fbreader().currentView();
83
return (!view.isNull()) && ((ZLTextView&)*view).canFindPrevious();
86
void FindPreviousAction::run() {
87
((ZLTextView&)*fbreader().currentView()).findPrevious();