2 * \file ControlBibtex.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Angus Leeming
10 * Full author contact details are available in file CREDITS.
15 #include "ControlBibtex.h"
19 #include "bufferparams.h"
22 #include "helper_funcs.h"
23 #include "tex_helpers.h"
26 #include "support/filefilterlist.h"
27 #include "support/filetools.h"
28 #include "support/lstrings.h"
37 using support::contains;
38 using support::FileFilterList;
39 using support::onlyFilename;
40 using support::prefixIs;
46 ControlBibtex::ControlBibtex(Dialog & d)
47 : ControlCommand(d, "bibtex", "bibtex")
51 docstring const ControlBibtex::browseBib(docstring const & in_name) const
54 pair<docstring, docstring> dir1(_("Documents|#o#O"),
55 lyx::from_utf8(lyxrc.document_path));
56 FileFilterList const filter(_("BibTeX Databases (*.bib)"));
57 return browseRelFile(in_name, lyx::from_utf8(kernel().bufferFilepath()),
58 _("Select a BibTeX database to add"),
63 docstring const ControlBibtex::browseBst(docstring const & in_name) const
66 pair<docstring, docstring> dir1(_("Documents|#o#O"),
67 lyx::from_utf8(lyxrc.document_path));
68 FileFilterList const filter(_("BibTeX Styles (*.bst)"));
69 return browseRelFile(in_name, lyx::from_utf8(kernel().bufferFilepath()),
70 _("Select a BibTeX style"), filter, false, dir1);
74 void ControlBibtex::getBibStyles(vector<string> & data) const
78 getTexFileList("bstFiles.lst", data);
79 // test, if we have a valid list, otherwise run rescan
82 getTexFileList("bstFiles.lst", data);
84 vector<string>::iterator it = data.begin();
85 vector<string>::iterator end = data.end();
86 for (; it != end; ++it) {
87 *it = onlyFilename(*it);
89 // sort on filename only (no path)
90 std::sort(data.begin(), data.end());
94 void ControlBibtex::getBibFiles(vector<string> & data) const
98 getTexFileList("bibFiles.lst", data);
99 // test, if we have a valid list, otherwise run rescan
102 getTexFileList("bibFiles.lst", data);
104 vector<string>::iterator it = data.begin();
105 vector<string>::iterator end = data.end();
106 for (; it != end; ++it) {
107 *it = onlyFilename(*it);
109 // sort on filename only (no path)
110 std::sort(data.begin(), data.end());
114 void ControlBibtex::rescanBibStyles() const
120 bool ControlBibtex::usingBibtopic() const
122 return kernel().buffer().params().use_bibtopic;
126 bool ControlBibtex::bibtotoc() const
128 return prefixIs(lyx::to_utf8(params()["options"]), "bibtotoc");
132 string const ControlBibtex::getStylefile() const
134 // the different bibtex packages have (and need) their
135 // own "plain" stylefiles
136 biblio::CiteEngine_enum const & engine =
137 biblio::getEngine(kernel().buffer());
138 docstring defaultstyle;
140 case biblio::ENGINE_BASIC:
141 defaultstyle = lyx::from_ascii("plain");
143 case biblio::ENGINE_NATBIB_AUTHORYEAR:
144 defaultstyle = lyx::from_ascii("plainnat");
146 case biblio::ENGINE_NATBIB_NUMERICAL:
147 defaultstyle = lyx::from_ascii("plainnat");
149 case biblio::ENGINE_JURABIB:
150 defaultstyle = lyx::from_ascii("jurabib");
154 docstring bst = params()["btprint"];
157 if (contains(bst, ',')) {
158 docstring bibtotoc = lyx::from_ascii("bibtotoc");
159 bst = split(bst, bibtotoc, ',');
164 // propose default style file for new insets
165 // existing insets might have (legally) no bst files
166 // (if the class already provides a style)
167 if (bst.empty() && params()["bibfiles"].empty())
171 return lyx::to_utf8(bst);
174 } // namespace frontend