]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlSearch.C
prefs/tabular MVC work
[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/LyXView.h"
23
24 #include "support/lstrings.h"
25
26
27 ControlSearch::ControlSearch(LyXView & lv, Dialogs & d)
28         : ControlDialogBD(lv, d)
29 {}
30
31
32 void ControlSearch::find(string const & search,
33                          bool casesensitive, bool matchword, bool forward)
34 {
35         bool const found = lyxfind::LyXFind(bufferview(), search,
36                                             forward, casesensitive,
37                                             matchword);
38
39         if (!found)
40                 lv_.message(_("String not found!"));
41 }
42
43
44 void ControlSearch::replace(string const & search, string const & replace,
45                             bool casesensitive, bool matchword, 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         bool const once = !all;
51         int const replace_count =
52                 lyxfind::LyXReplace(bufferview(),
53                                     search, replace, true, casesensitive,
54                                     matchword, all, once);
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 }