]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/FormSearch.C
Fixed connections. There is still a bug somewhere.
[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 "searchdlgimpl.h"
12 #include "FormSearch.h"
13 #include "Dialogs.h"
14 #include "Liason.h"
15 #include "QtLyXView.h"
16 #include "buffer.h"
17 //#include "lyxtext.h"
18 #include "lyxfind.h"
19 //#include "language.h"
20 #include "support/lstrings.h"
21
22 using Liason::setMinibuffer;
23
24 FormSearch::FormSearch(LyXView *v, Dialogs *d)
25         : dialog_(0), lv_(v), d_(d), h_(0), u_(0)
26 {
27    // let the popup be shown
28    // This is a permanent connection so we won't bother
29    // storing a copy because we won't be disconnecting.
30    d->showSearch.connect(SigC::slot(this, &FormSearch::show));
31    // perhaps in the future we'd like a
32    // "search again" button/keybinding
33 //    d->searchAgain.connect(slot(this, &FormSearch::FindNext));
34 }
35
36
37 FormSearch::~FormSearch()
38 {
39    delete dialog_;
40 }
41
42 void FormSearch::show()
43 {
44    if (!dialog_) {
45       dialog_ = new SearchDlgImpl(this, 0, _("Find and Replace"), false);
46    }
47
48    if (!dialog_->isVisible()) {
49       h_ = d_->hideBufferDependent.connect(SigC::slot(this, &FormSearch::hide));
50       u_ = d_->updateBufferDependent.connect(SigC::slot(this, &FormSearch::update));
51    }
52    
53    dialog_->raise();
54    dialog_->setActiveWindow();
55    update();
56    dialog_->show();
57 }
58
59 void FormSearch::find(string const & searchstr, bool const & casesensitive,
60                       bool const & matchword, bool const & searchback)
61 {
62    bool found = LyXFind(lv_->view(), searchstr, casesensitive, matchword,
63                         searchback);
64    
65    if (!found)
66      setMinibuffer(lv_, _("String not found!"));
67    
68 }
69 void FormSearch::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                                   casesensitive, matchword, searchback,
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 FormSearch::close()
92 {
93    h_.disconnect();
94    u_.disconnect();
95 }
96
97 void FormSearch::hide()
98 {
99    dialog_->hide();
100    close();
101 }
102
103 void FormSearch::update(bool)
104 {
105    if (!lv_->view()->available())
106      return;
107
108    dialog_->setReadOnly(lv_->buffer()->isReadonly());
109 }