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