]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlSearch.C
More header file include dependency work
[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 "ViewBase.h"
21 #include "ButtonControllerBase.h"
22 #include "ControlSearch.h"
23 #include "Dialogs.h"
24 #include "Liason.h"
25 #include "LyXView.h"
26 #include "buffer.h"
27 #include "lyxfind.h"
28 #include "debug.h"
29 #include "gettext.h"
30 #include "BufferView.h"
31 #include "support/lstrings.h"
32
33 using Liason::setMinibuffer;
34 using SigC::slot;
35
36 ControlSearch::ControlSearch(LyXView & lv, Dialogs & d)
37         : ControlDialog<ControlConnectBD>(lv, d)
38 {
39         d_.showSearch.connect(SigC::slot(this, &ControlSearch::show));
40
41         // perhaps in the future we'd like a
42         // "search again" button/keybinding
43         // d_.searchAgain.connect(SigC::slot(this, &ControlSearch::FindNext));
44 }
45
46
47 void ControlSearch::find(string const & search,
48                          bool casesensitive, bool matchword, bool forward) const
49 {
50         bool const found = LyXFind(lv_.view(), search,
51                                    forward, false, casesensitive, matchword);
52    
53         if (!found)
54                 setMinibuffer(&lv_, _("String not found!"));
55 }
56
57
58 void ControlSearch::replace(string const & search, string const & replace,
59                             bool casesensitive, bool matchword, bool all) const
60 {
61         int const replace_count = LyXReplace(lv_.view(),
62                                              search, replace, true, casesensitive, 
63                                              matchword, all);
64                                   
65         if (replace_count == 0) {
66                 setMinibuffer(&lv_, _("String not found!"));
67         } else {
68                 if (replace_count == 1) {
69                         setMinibuffer(&lv_, _("String has been replaced."));
70                 } else {
71                         string str = tostr(replace_count);
72                         str += _(" strings have been replaced.");
73                         setMinibuffer(&lv_, str.c_str());
74                 }
75         }
76 }