2 * \file ControlBibtex.cpp
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"
16 #include "frontend_helpers.h"
19 #include "BufferParams.h"
24 #include "support/FileFilterList.h"
25 #include "support/filetools.h"
26 #include "support/lstrings.h"
35 using support::contains;
36 using support::FileFilterList;
37 using support::onlyFilename;
38 using support::prefixIs;
44 ControlBibtex::ControlBibtex(Dialog & d)
45 : ControlCommand(d, "bibtex", "bibtex")
49 docstring const ControlBibtex::browseBib(docstring const & in_name) const
52 pair<docstring, docstring> dir1(_("Documents|#o#O"),
53 lyx::from_utf8(lyxrc.document_path));
54 FileFilterList const filter(_("BibTeX Databases (*.bib)"));
55 return browseRelFile(in_name, lyx::from_utf8(kernel().bufferFilepath()),
56 _("Select a BibTeX database to add"),
61 docstring const ControlBibtex::browseBst(docstring const & in_name) const
64 pair<docstring, docstring> dir1(_("Documents|#o#O"),
65 lyx::from_utf8(lyxrc.document_path));
66 FileFilterList const filter(_("BibTeX Styles (*.bst)"));
67 return browseRelFile(in_name, lyx::from_utf8(kernel().bufferFilepath()),
68 _("Select a BibTeX style"), filter, false, dir1);
72 void ControlBibtex::getBibStyles(vector<string> & data) const
76 getTexFileList("bstFiles.lst", data);
77 // test, if we have a valid list, otherwise run rescan
80 getTexFileList("bstFiles.lst", data);
82 vector<string>::iterator it = data.begin();
83 vector<string>::iterator end = data.end();
84 for (; it != end; ++it) {
85 *it = onlyFilename(*it);
87 // sort on filename only (no path)
88 std::sort(data.begin(), data.end());
92 void ControlBibtex::getBibFiles(vector<string> & data) const
96 getTexFileList("bibFiles.lst", data);
97 // test, if we have a valid list, otherwise run rescan
100 getTexFileList("bibFiles.lst", data);
102 vector<string>::iterator it = data.begin();
103 vector<string>::iterator end = data.end();
104 for (; it != end; ++it) {
105 *it = onlyFilename(*it);
107 // sort on filename only (no path)
108 std::sort(data.begin(), data.end());
112 void ControlBibtex::rescanBibStyles() const
118 bool ControlBibtex::usingBibtopic() const
120 return kernel().buffer().params().use_bibtopic;
124 bool ControlBibtex::bibtotoc() const
126 return prefixIs(lyx::to_utf8(params()["options"]), "bibtotoc");
130 string const ControlBibtex::getStylefile() const
132 // the different bibtex packages have (and need) their
133 // own "plain" stylefiles
134 biblio::CiteEngine const engine =
135 kernel().buffer().params().getEngine();
136 docstring defaultstyle;
138 case biblio::ENGINE_BASIC:
139 defaultstyle = lyx::from_ascii("plain");
141 case biblio::ENGINE_NATBIB_AUTHORYEAR:
142 defaultstyle = lyx::from_ascii("plainnat");
144 case biblio::ENGINE_NATBIB_NUMERICAL:
145 defaultstyle = lyx::from_ascii("plainnat");
147 case biblio::ENGINE_JURABIB:
148 defaultstyle = lyx::from_ascii("jurabib");
152 docstring bst = params()["options"];
155 if (contains(bst, ',')) {
156 docstring bibtotoc = lyx::from_ascii("bibtotoc");
157 bst = split(bst, bibtotoc, ',');
162 // propose default style file for new insets
163 // existing insets might have (legally) no bst files
164 // (if the class already provides a style)
165 if (bst.empty() && params()["bibfiles"].empty())
169 return lyx::to_utf8(bst);
172 } // namespace frontend