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