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