]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlSearch.C
Overhaul the branches code.
[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 #include "ControlSearch.h"
14
15 #include "gettext.h"
16 #include "lyxfind.h"
17
18 #include "frontends/LyXView.h"
19
20 #include "support/tostr.h"
21
22
23 using std::string;
24
25
26 ControlSearch::ControlSearch(LyXView & lv, Dialogs & d)
27         : ControlDialogBD(lv, d)
28 {}
29
30
31 void ControlSearch::find(string const & search,
32                          bool casesensitive, bool matchword, bool forward)
33 {
34         bool const found = lyx::find::find(bufferview(), search,
35                                            casesensitive, matchword,
36                                            forward);
37
38         if (!found)
39                 lv_.message(_("String not found!"));
40 }
41
42
43 void ControlSearch::replace(string const & search, string const & replace,
44                             bool casesensitive, bool matchword,
45                             bool forward, bool all)
46 {
47         // If not replacing all instances of the word, then do not
48         // move on to the next instance once the present instance has been
49         // changed
50         int const replace_count = all ?
51                 lyx::find::replaceAll(bufferview(), search, replace,
52                                       casesensitive, matchword)
53                 : lyx::find::replace(bufferview(), search, replace,
54                                      casesensitive, matchword, forward);
55
56         if (replace_count == 0) {
57                 lv_.message(_("String not found!"));
58         } else {
59                 if (replace_count == 1) {
60                         lv_.message(_("String has been replaced."));
61                 } else {
62                         string str = tostr(replace_count);
63                         str += _(" strings have been replaced.");
64                         lv_.message(str);
65                 }
66         }
67 }