]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlSearch.C
Fix semantics of Replace in Find & Replace dialog
[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         // If not replacing all instances of the word, then do not
62         // move on to the next instance once the present instance has been
63         // changed
64         bool const once = !all;
65         int const replace_count = LyXReplace(lv_.view(),
66                                              search, replace, true, casesensitive, 
67                                              matchword, all, once);
68                                   
69         if (replace_count == 0) {
70                 setMinibuffer(&lv_, _("String not found!"));
71         } else {
72                 if (replace_count == 1) {
73                         setMinibuffer(&lv_, _("String has been replaced."));
74                 } else {
75                         string str = tostr(replace_count);
76                         str += _(" strings have been replaced.");
77                         setMinibuffer(&lv_, str.c_str());
78                 }
79         }
80 }