]> git.lyx.org Git - features.git/blob - src/frontends/qt2/FormSearch.C
outstanding changes
[features.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 #include "BufferView.h"
23
24 using Liason::setMinibuffer;
25
26 FormSearch::FormSearch(LyXView *v, Dialogs *d)
27         : dialog_(0), lv_(v), d_(d), h_(0), u_(0)
28 {
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));
36 }
37
38
39 FormSearch::~FormSearch()
40 {
41         delete dialog_;
42 }
43
44 void FormSearch::show()
45 {
46         if (!dialog_) {
47                 dialog_ = new SearchDlgImpl(this, 0, _("Find and Replace"), false);
48         }
49
50         if (!dialog_->isVisible()) {
51                 h_ = d_->hideBufferDependent.connect(SigC::slot(this, &FormSearch::hide));
52                 u_ = d_->updateBufferDependent.connect(SigC::slot(this, &FormSearch::update));
53         }
54         
55         dialog_->raise();
56         dialog_->setActiveWindow();
57         update();
58         dialog_->show();
59 }
60
61 void FormSearch::find(string const & searchstr, bool const & casesensitive,
62                                 bool const & matchword, bool const & searchback)
63 {
64         bool found = LyXFind(lv_->view(), searchstr, searchback,
65                                                  casesensitive, matchword);
66         
67         if (!found)
68                 setMinibuffer(lv_, _("String not found!"));
69         
70 }
71 void FormSearch::replace(string const & searchstr, string const & replacestr,
72                          bool const & casesensitive, bool const & matchword, 
73                          bool const & searchback, bool const & replaceall)
74 {
75         int replace_count = LyXReplace(lv_->view(), searchstr, replacestr,
76                                   searchback, casesensitive, matchword,
77                                   replaceall);
78                                   
79         if (replace_count == 0) {
80                 setMinibuffer(lv_, _("String not found!"));
81         } else {
82                 if (replace_count == 1) {
83                         setMinibuffer(lv_, _("String has been replaced."));
84                 } else {
85                         string str = tostr(replace_count);
86                         str += _(" strings have been replaced.");
87                         setMinibuffer(lv_, str.c_str());
88                 }
89         }
90 }
91
92
93 void FormSearch::close()
94 {
95         h_.disconnect();
96         u_.disconnect();
97 }
98
99 void FormSearch::hide()
100 {
101         dialog_->hide();
102         close();
103 }
104
105 void FormSearch::update(bool)
106 {
107         if (!lv_->view()->available())
108                 return;
109
110         dialog_->setReadOnly(lv_->buffer()->isReadonly());
111 }