3 * Copyright 2001 The LyX Team.
4 * See the file COPYING.
11 #include "searchdlgimpl.h"
12 #include "FormSearch.h"
15 #include "QtLyXView.h"
17 //#include "lyxtext.h"
19 //#include "language.h"
20 #include "support/lstrings.h"
22 #ifdef CXX_WORKING_NAMESPACES
23 using Liason::setMinibuffer;
26 FormSearch::FormSearch(LyXView *v, Dialogs *d)
27 : dialog_(0), lv_(v), d_(d), h_(0), u_(0)
29 // let the popup be shown
30 // This is a permanent connection so we won't bother
31 // storing a copy because we won't be disconnecting.
32 d->showSearch.connect(slot(this, &FormSearch::show));
33 // perhaps in the future we'd like a
34 // "search again" button/keybinding
35 // d->searchAgain.connect(slot(this, &FormSearch::FindNext));
39 FormSearch::~FormSearch()
44 void FormSearch::show()
47 dialog_ = new SearchDlgImpl(this, 0, _("Find and Replace"), false);
50 if (!dialog_->isVisible()) {
51 h_ = d_->hideBufferDependent.connect(slot(this, &FormSearch::hide));
52 u_ = d_->updateBufferDependent.connect(slot(this, &FormSearch::update));
56 dialog_->setActiveWindow();
61 void FormSearch::find(string const & searchstr, bool const & casesensitive,
62 bool const & matchword, bool const & searchback)
64 bool found = LyXFind(lv_->view(), searchstr, casesensitive, matchword,
68 setMinibuffer(lv_, _("String not found!"));
71 void FormSearch::replace(string const & searchstr, string const & replacestr,
72 bool const & casesensitive, bool const & matchword,
73 bool const & searchback, bool const & replaceall)
75 int replace_count = LyXReplace(lv_->view(), searchstr, replacestr,
76 casesensitive, matchword, searchback,
79 if (replace_count == 0) {
80 setMinibuffer(lv_, _("String not found!"));
82 if (replace_count == 1) {
83 setMinibuffer(lv_, _("String has been replaced."));
85 string str = tostr(replace_count);
86 str += _(" strings have been replaced.");
87 setMinibuffer(lv_, str.c_str());
91 void FormSearch::close()
97 void FormSearch::hide()
103 void FormSearch::update(bool)
105 if (!lv_->view()->available())
108 dialog_->setReadOnly(lv_->buffer()->isReadonly());