]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QSearch.C
some small updates
[lyx.git] / src / frontends / qt2 / QSearch.C
1 /**
2  * \file QSearch.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 "QSearchDialog.h"
13 #include "QSearch.h"
14 #include "Dialogs.h"
15 #include "Liason.h"
16 #include "QtLyXView.h"
17 #include "buffer.h"
18 #include "lyxfind.h"
19 #include "support/lstrings.h"
20 #include "BufferView.h"
21
22 using Liason::setMinibuffer;
23
24 QSearch::QSearch(LyXView *v, Dialogs *d)
25         : dialog_(0), lv_(v), d_(d), h_(0), u_(0)
26 {
27         d->showSearch.connect(SigC::slot(this, &QSearch::show));
28         // perhaps in the future we'd like a
29         // "search again" button/keybinding
30         // d->searchAgain.connect(slot(this, &QSearch::FindNext));
31 }
32
33
34 QSearch::~QSearch()
35 {
36         delete dialog_;
37 }
38
39  
40 void QSearch::show()
41 {
42         if (!dialog_) {
43                 dialog_ = new QSearchDialog(this, 0, _("Find and Replace"), false);
44         }
45
46         if (!dialog_->isVisible()) {
47                 h_ = d_->hideBufferDependent.connect(SigC::slot(this, &QSearch::hide));
48                 u_ = d_->updateBufferDependent.connect(SigC::slot(this, &QSearch::update));
49         }
50         
51         dialog_->raise();
52         dialog_->setActiveWindow();
53         update();
54         dialog_->show();
55 }
56
57  
58 void QSearch::find(string const & searchstr, bool const & casesensitive,
59                                 bool const & matchword, bool const & searchback)
60 {
61         bool const found = LyXFind(lv_->view(), searchstr, searchback,
62                 casesensitive, matchword);
63         
64         if (!found)
65                 setMinibuffer(lv_, _("String not found!"));
66 }
67
68  
69 void QSearch::replace(string const & searchstr, string const & replacestr,
70                          bool const & casesensitive, bool const & matchword, 
71                          bool const & searchback, bool const & replaceall)
72 {
73         int replace_count = LyXReplace(lv_->view(), searchstr, replacestr,
74                                   searchback, casesensitive, matchword,
75                                   replaceall);
76                                   
77         if (replace_count == 0) {
78                 setMinibuffer(lv_, _("String not found!"));
79         } else {
80                 if (replace_count == 1) {
81                         setMinibuffer(lv_, _("String has been replaced."));
82                 } else {
83                         string str = tostr(replace_count);
84                         str += _(" strings have been replaced.");
85                         setMinibuffer(lv_, str.c_str());
86                 }
87         }
88 }
89
90
91 void QSearch::close()
92 {
93         h_.disconnect();
94         u_.disconnect();
95 }
96
97  
98 void QSearch::hide()
99 {
100         dialog_->hide();
101         close();
102 }
103
104  
105 void QSearch::update(bool)
106 {
107         if (!lv_->view()->available())
108                 return;
109
110         dialog_->setReadOnly(lv_->buffer()->isReadonly());
111 }