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