3 * Copyright 2001 The LyX Team.
4 * See the file COPYING.
12 #include "searchdlgimpl.h"
13 #include "FormSearch.h"
16 #include "QtLyXView.h"
18 //#include "lyxtext.h"
20 //#include "language.h"
21 #include "support/lstrings.h"
22 #include "BufferView.h"
24 using Liason::setMinibuffer;
26 FormSearch::FormSearch(LyXView *v, Dialogs *d)
27 : dialog_(0), lv_(v), d_(d), h_(0), u_(0)
29 // let the dialog 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(SigC::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(SigC::slot(this, &FormSearch::hide));
52 u_ = d_->updateBufferDependent.connect(SigC::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, searchback,
65 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 searchback, casesensitive, matchword,
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());
93 void FormSearch::close()
99 void FormSearch::hide()
105 void FormSearch::update(bool)
107 if (!lv_->view()->available())
110 dialog_->setReadOnly(lv_->buffer()->isReadonly());