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