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