]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlThesaurus.C
- Applied the thesaurus patch.
[lyx.git] / src / frontends / controllers / ControlThesaurus.C
1 /**
2  * \file ControlThesaurus.C
3  * Copyright 2001 the LyX Team
4  * Read the file COPYING
5  *
6  * \author John Levon
7  */
8
9 #include <config.h>
10
11 #ifdef __GNUG__
12 #pragma implementation
13 #endif
14
15 #include "ViewBase.h"
16 #include "ButtonControllerBase.h"
17 #include "ControlThesaurus.h"
18 #include "Dialogs.h"
19 #include "Liason.h"
20 #include "LyXView.h"
21 #include "lyxfind.h"
22 #include "buffer.h"
23 #include "debug.h"
24 #include "gettext.h"
25 #include "BufferView.h"
26
27 using Liason::setMinibuffer;
28 using SigC::slot;
29
30 ControlThesaurus::ControlThesaurus(LyXView & lv, Dialogs & d)
31         : ControlDialog<ControlConnectBD>(lv, d)
32 {
33         d_.showThesaurus.connect(SigC::slot(this, &ControlThesaurus::showEntry));
34 }
35
36
37 void ControlThesaurus::showEntry(string const & entry)
38 {
39         oldstr_ = entry;
40         show();
41 }
42
43
44 void ControlThesaurus::replace(string const & newstr)
45 {
46         /* FIXME: this is not suitable ! We need to have a "lock"
47          * on a particular charpos in a paragraph that is broken on
48          * deletion/change !
49          */
50         int const replace_count = LyXReplace(lv_.view(), oldstr_, newstr,
51                                         true, true, true, false, true);
52
53         oldstr_ = newstr;
54
55         if (replace_count == 0)
56                 setMinibuffer(&lv_, _("String not found!"));
57         else
58                 setMinibuffer(&lv_, _("String has been replaced."));
59 }
60
61
62 std::vector<string> ControlThesaurus::getEntries(string const & str, Thesaurus::POS pos)
63 {
64         if (str != laststr_)
65                 entries_ = thesaurus.lookup(str);
66
67         laststr_ = str;
68
69         std::vector<string> strs;
70
71         for (std::vector<Thesaurus::ThesaurusEntry>::const_iterator it = entries_.begin();
72                 it != entries_.end(); ++it) {
73                 if (it->pos & pos)
74                         strs.push_back(it->entry);
75         }
76
77         return strs;
78 }