]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/FormSearch.C
John's FormExternal patch, Edwin's Qt2 patch and Baruch's gnome patch.
[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 #ifdef CXX_WORKING_NAMESPACES
23 using Liason::setMinibuffer;
24 #endif
25
26 FormSearch::FormSearch(LyXView *v, Dialogs *d)
27         : dialog_(0), lv_(v), d_(d), h_(0), u_(0)
28 {
29    // let the popup 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(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(slot(this, &FormSearch::hide));
52       u_ = d_->updateBufferDependent.connect(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, casesensitive, matchword,
65                         searchback);
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                                   casesensitive, matchword, searchback,
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 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 }