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