]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/FormSearch.C
Qt2 compilation + LColor cleanup from John
[lyx.git] / src / frontends / qt2 / FormSearch.C
1 /**
2  * \file FormSearch.C
3  * Copyright 2001 The LyX Team.
4  * See the file COPYING.
5  *
6  * \author Edwin Leuven
7  */
8
9 #include <config.h>
10
11 #include "gettext.h"
12 #include "searchdlgimpl.h"
13 #include "FormSearch.h"
14 #include "Dialogs.h"
15 #include "Liason.h"
16 #include "QtLyXView.h"
17 #include "buffer.h"
18 //#include "lyxtext.h"
19 #include "lyxfind.h"
20 //#include "language.h"
21 #include "support/lstrings.h"
22
23 using Liason::setMinibuffer;
24
25 FormSearch::FormSearch(LyXView *v, Dialogs *d)
26         : dialog_(0), lv_(v), d_(d), h_(0), u_(0)
27 {
28         // let the dialog be shown
29         // This is a permanent connection so we won't bother
30         // storing a copy because we won't be disconnecting.
31         d->showSearch.connect(SigC::slot(this, &FormSearch::show));
32         // perhaps in the future we'd like a
33         // "search again" button/keybinding
34         // d->searchAgain.connect(slot(this, &FormSearch::FindNext));
35 }
36
37
38 FormSearch::~FormSearch()
39 {
40         delete dialog_;
41 }
42
43 void FormSearch::show()
44 {
45         if (!dialog_) {
46                 dialog_ = new SearchDlgImpl(this, 0, _("Find and Replace"), false);
47         }
48
49         if (!dialog_->isVisible()) {
50                 h_ = d_->hideBufferDependent.connect(SigC::slot(this, &FormSearch::hide));
51                 u_ = d_->updateBufferDependent.connect(SigC::slot(this, &FormSearch::update));
52         }
53         
54         dialog_->raise();
55         dialog_->setActiveWindow();
56         update();
57         dialog_->show();
58 }
59
60 void FormSearch::find(string const & searchstr, bool const & casesensitive,
61                                 bool const & matchword, bool const & searchback)
62 {
63         bool found = LyXFind(lv_->view(), searchstr,    casesensitive, matchword,
64                         searchback);
65         
66         if (!found)
67                 setMinibuffer(lv_, _("String not found!"));
68         
69 }
70 void FormSearch::replace(string const & searchstr, string const & replacestr,
71                          bool const & casesensitive, bool const & matchword, 
72                          bool const & searchback, bool const & replaceall)
73 {
74         int replace_count = LyXReplace(lv_->view(), searchstr, replacestr,
75                                   casesensitive, matchword, searchback,
76                                   replaceall);
77                                   
78         if (replace_count == 0) {
79                 setMinibuffer(lv_, _("String not found!"));
80         } else {
81                 if (replace_count == 1) {
82                         setMinibuffer(lv_, _("String has been replaced."));
83                 } else {
84                         string str = tostr(replace_count);
85                         str += _(" strings have been replaced.");
86                         setMinibuffer(lv_, str.c_str());
87                 }
88         }
89 }
90
91
92 void FormSearch::close()
93 {
94         h_.disconnect();
95         u_.disconnect();
96 }
97
98 void FormSearch::hide()
99 {
100         dialog_->hide();
101         close();
102 }
103
104 void FormSearch::update(bool)
105 {
106         if (!lv_->view()->available())
107                 return;
108
109         dialog_->setReadOnly(lv_->buffer()->isReadonly());
110 }