]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlCitation.C
Wrap most of the frontend code up inside namespace lyx::frontend.
[lyx.git] / src / frontends / controllers / ControlCitation.C
1 /**
2  * \file ControlCitation.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "ControlCitation.h"
14
15 #include "buffer.h"
16 #include "bufferparams.h"
17
18
19 using std::string;
20 using std::vector;
21 using std::pair;
22
23 namespace lyx {
24 namespace frontend {
25
26 vector<biblio::CiteStyle> ControlCitation::citeStyles_;
27
28
29 ControlCitation::ControlCitation(Dialog & d)
30         : ControlCommand(d, "citation")
31 {}
32
33
34 bool ControlCitation::initialiseParams(string const & data)
35 {
36         ControlCommand::initialiseParams(data);
37
38         vector<pair<string, string> > blist;
39         kernel().buffer().fillWithBibKeys(blist);
40
41         biblio::CiteEngine const engine = biblio::getEngine(kernel().buffer());
42                 
43         bool use_styles = engine != biblio::ENGINE_BASIC;
44
45         typedef std::map<string, string>::value_type InfoMapValue;
46
47         for (vector<pair<string,string> >::size_type i = 0;
48              i < blist.size(); ++i) {
49                 bibkeysInfo_.insert(InfoMapValue(blist[i].first,
50                                                  blist[i].second));
51         }
52
53         if (citeStyles_.empty())
54                 citeStyles_ = biblio::getCiteStyles(engine);
55         else {
56                 if ((use_styles && citeStyles_.size() == 1) ||
57                     (!use_styles && citeStyles_.size() != 1))
58                         citeStyles_ = biblio::getCiteStyles(engine);
59         }
60
61         return true;
62 }
63
64
65
66 void ControlCitation::clearParams()
67 {
68         ControlCommand::clearParams();
69         bibkeysInfo_.clear();
70 }
71
72
73 biblio::InfoMap const & ControlCitation::bibkeysInfo() const
74 {
75         return bibkeysInfo_;
76 }
77
78
79 biblio::CiteEngine_enum ControlCitation::getEngine() const
80 {
81         return biblio::getEngine(kernel().buffer());
82 }
83
84
85 vector<string> const ControlCitation::getCiteStrings(string const & key) const
86 {
87         vector<string> styles;
88
89         biblio::CiteEngine const engine = biblio::getEngine(kernel().buffer());
90         vector<biblio::CiteStyle> const cs = biblio::getCiteStyles(engine);
91
92         if (engine == biblio::ENGINE_NATBIB_NUMERICAL)
93                 styles = biblio::getNumericalStrings(key, bibkeysInfo_, cs);
94         else
95                 styles = biblio::getAuthorYearStrings(key, bibkeysInfo_, cs);
96
97         return styles;
98 }
99
100 } // namespace frontend
101 } // namespace lyx