]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlSearch.C
LyXView::view() now returns boost::shared_ptr<BufferView> const &.
[lyx.git] / src / frontends / controllers / ControlSearch.C
1 /* This file is part of
2  * ======================================================
3  *
4  *           LyX, The Document Processor
5  *
6  *           Copyright 2001 The LyX Team.
7  *
8  * ======================================================
9  *
10  * \file ControlSearch.C
11  * \author Angus Leeming <a.leeming@ic.ac.uk>
12  */
13
14 #include <config.h>
15
16 #ifdef __GNUG__
17 #pragma implementation
18 #endif
19
20 #include "ControlSearch.h"
21 #include "Liason.h"
22 #include "buffer.h"
23 #include "lyxfind.h"
24 #include "gettext.h"
25 #include "BufferView.h"
26
27 #include "frontends/LyXView.h"
28
29 #include "support/lstrings.h"
30
31 using Liason::setMinibuffer;
32
33
34 ControlSearch::ControlSearch(LyXView & lv, Dialogs & d)
35         : ControlDialogBD(lv, d)
36 {}
37
38
39 void ControlSearch::find(string const & search,
40                          bool casesensitive, bool matchword, bool forward) const
41 {
42         bool const found = lyxfind::LyXFind(lv_.view().get(), search,
43                                             forward, casesensitive,
44                                             matchword);
45
46         if (!found)
47                 setMinibuffer(&lv_, _("String not found!"));
48 }
49
50
51 void ControlSearch::replace(string const & search, string const & replace,
52                             bool casesensitive, bool matchword, bool all) const
53 {
54         // If not replacing all instances of the word, then do not
55         // move on to the next instance once the present instance has been
56         // changed
57         bool const once = !all;
58         int const replace_count =
59                 lyxfind::LyXReplace(lv_.view().get(),
60                                     search, replace, true, casesensitive,
61                                     matchword, all, once);
62
63         if (replace_count == 0) {
64                 setMinibuffer(&lv_, _("String not found!"));
65         } else {
66                 if (replace_count == 1) {
67                         setMinibuffer(&lv_, _("String has been replaced."));
68                 } else {
69                         string str = tostr(replace_count);
70                         str += _(" strings have been replaced.");
71                         setMinibuffer(&lv_, str.c_str());
72                 }
73         }
74 }