#include "FuncStatus.h"
#include "LaTeXFeatures.h"
#include "MetricsInfo.h"
+#include "output_xhtml.h"
#include "OutputParams.h"
#include "TextClass.h"
namespace os = support::os;
-InsetBibtex::InsetBibtex(InsetCommandParams const & p)
- : InsetCommand(p, "bibtex")
-{}
+InsetBibtex::InsetBibtex(Buffer * buf, InsetCommandParams const & p)
+ : InsetCommand(buf, p, "bibtex")
+{
+ buffer_->invalidateBibinfoCache();
+}
+
+
+InsetBibtex::~InsetBibtex()
+{
+ if (isBufferValid())
+ buffer_->invalidateBibinfoCache();
+}
ParamInfo const & InsetBibtex::findInfo(string const & /* cmdName */)
{
switch (cmd.action) {
case LFUN_INSET_EDIT:
- flag.enabled(true);
+ flag.setEnabled(true);
return true;
default:
docstring InsetBibtex::toolTip(BufferView const & /*bv*/, int /*x*/, int /*y*/) const
{
docstring item = from_ascii("* ");
- docstring tip = _("Databases:\n");
+ docstring tip = _("Databases:") + "\n";
vector<docstring> bibfilelist = getVectorFromString(getParam("bibfiles"));
if (bibfilelist.empty()) {
style = split(style, bibtotoc, char_type(','));
}
- tip += _("Style File:\n");
+ tip += _("Style File:") +"\n";
tip += item;
if (!style.empty())
tip += style;
else
tip += _("none");
- tip += _("\nLists: ");
+ tip += "\n" + _("Lists:") + " ";
docstring btprint = getParam("btprint");
if (btprint == "btPrintAll")
tip += _("all references");
OutputParams const & runparams, string const & name, string const & ext)
{
string const fname = makeAbsPath(name, buffer.filePath()).absFilename();
- if (FileName(name).isAbsolute() || !FileName(fname + ext).isReadableFile())
+ if (FileName::isAbsolute(name) || !FileName(fname + ext).isReadableFile())
return name;
if (!runparams.nice)
return fname;
if (!runparams.inComment && !runparams.dryrun && !runparams.nice &&
not_from_texmf) {
-
// mangledFilename() needs the extension
DocFileName const in_file = DocFileName(try_in_file);
database = removeExtension(in_file.mangledFilename());
if (!warned_about_spaces &&
runparams.nice && db_out.find(' ') != docstring::npos) {
warned_about_spaces = true;
-
Alert::warning(_("Export Warning!"),
_("There are spaces in the paths to your BibTeX databases.\n"
"BibTeX will be unable to find them."));
style = split(style, bibtotoc, ',');
}
-
// line count
int nlines = 0;
vector<docstring>::const_iterator it = bibfilelist.begin();
vector<docstring>::const_iterator en = bibfilelist.end();
for (; it != en; ++it) {
- FileName const file =
- findtexfile(changeExtension(to_utf8(*it), "bib"), "bib");
-
- // If we didn't find a matching file name just fail silently
+ FileName const file = getBibTeXPath(*it, buffer());
+
if (!file.empty())
vec.push_back(file);
+ else
+ LYXERR0("Couldn't find " + to_utf8(*it) + " in InsetBibtex::getBibFiles()!");
}
return vec;
/// and further whitespace characters from the stream.
/// @return true if a comma was found, false otherwise
///
- bool removeWSAndComma(idocfstream & ifs) {
+ bool removeWSAndComma(ifdocstream & ifs) {
char_type ch;
if (!ifs)
///
/// @return true if a string of length > 0 could be read.
///
- bool readTypeOrKey(docstring & val, idocfstream & ifs,
+ bool readTypeOrKey(docstring & val, ifdocstream & ifs,
docstring const & delimChars, docstring const &illegalChars,
charCase chCase) {
/// the variable strings.
/// @return true if reading was successfull (all single parts were delimited
/// correctly)
- bool readValue(docstring & val, idocfstream & ifs, const VarMap & strings) {
+ bool readValue(docstring & val, ifdocstream & ifs, const VarMap & strings) {
char_type ch;
support::FileNameList::const_iterator it = files.begin();
support::FileNameList::const_iterator en = files.end();
for (; it != en; ++ it) {
- idocfstream ifs(it->toFilesystemEncoding().c_str(),
+ ifdocstream ifs(it->toFilesystemEncoding().c_str(),
ios_base::in, buffer().params().encoding().iconvName());
char_type ch;
while (ifs) {
ifs.get(ch);
- if (!ifs) {
- lyxerr << "InsetBibtex::fillWithBibKeys: Unexpected end of file." << std::endl;
+ if (!ifs)
break;
- }
if (ch != '@')
continue;
docstring entryType;
- if (!ifs) {
- lyxerr << "InsetBibtex::fillWithBibKeys: Unexpected end of file." << std::endl;
+ if (!readTypeOrKey(entryType, ifs, from_ascii("{("), docstring(), makeLowerCase)) {
+ lyxerr << "InsetBibtex::fillWithBibKeys: Error reading entry type." << std::endl;
continue;
}
- if (!readTypeOrKey(entryType, ifs, from_ascii("{("), docstring(), makeLowerCase)) {
- lyxerr << "InsetBibtex::fillWithBibKeys: Error reading entry type." << std::endl;
+ if (!ifs) {
+ lyxerr << "InsetBibtex::fillWithBibKeys: Unexpected end of file." << std::endl;
continue;
}
docstring name;
docstring value;
- if (!ifs) {
- lyxerr << "InsetBibtex::fillWithBibKeys: Unexpected end of file." << std::endl;
+ if (!readTypeOrKey(name, ifs, from_ascii("="), from_ascii("#{}(),"), makeLowerCase)) {
+ lyxerr << "InsetBibtex::fillWithBibKeys: Error reading string name." << std::endl;
continue;
}
- if (!readTypeOrKey(name, ifs, from_ascii("="), from_ascii("#{}(),"), makeLowerCase)) {
- lyxerr << "InsetBibtex::fillWithBibKeys: Error reading string name." << std::endl;
+ if (!ifs) {
+ lyxerr << "InsetBibtex::fillWithBibKeys: Unexpected end of file." << std::endl;
continue;
}
// Citation entry. Try to read the key.
docstring key;
- if (!ifs) {
- lyxerr << "InsetBibtex::fillWithBibKeys: Unexpected end of file." << std::endl;
- continue;
- }
-
if (!readTypeOrKey(key, ifs, from_ascii(","), from_ascii("}"), keepCase)) {
lyxerr << "InsetBibtex::fillWithBibKeys: Unable to read key for entry type:" <<
entryType << "." << std::endl;
continue;
}
+ if (!ifs) {
+ lyxerr << "InsetBibtex::fillWithBibKeys: Unexpected end of file." << std::endl;
+ continue;
+ }
+
/////////////////////////////////////////////
// now we have a key, so we will add an entry
// (even if it's empty, as bibtex does)
{
if (features.bufferParams().use_bibtopic)
features.require("bibtopic");
+ // FIXME XHTML
+ // It'd be better to be able to get this from an InsetLayout, but at present
+ // InsetLayouts do not seem really to work for things that aren't InsetTexts.
+ if (features.runparams().flavor == OutputParams::HTML)
+ features.addPreambleSnippet("<style type=\"text/css\">\n"
+ "div.bibtexentry { margin-left: 2em; text-indent: -2em; }\n"
+ "span.bibtexlabel:before{ content: \"[\"; }\n"
+ "span.bibtexlabel:after{ content: \"] \"; }\n"
+ "</style>");
+}
+
+
+docstring InsetBibtex::xhtml(XHTMLStream & xs, OutputParams const &) const
+{
+ BiblioInfo const & bibinfo = buffer().masterBibInfo();
+ vector<docstring> const & cites = bibinfo.citedEntries();
+ xs << StartTag("h2", "class='bibtex'")
+ << _("References")
+ << EndTag("h2")
+ << StartTag("div", "class='bibtex'");
+
+ // Now we loop over the entries
+ vector<docstring>::const_iterator vit = cites.begin();
+ vector<docstring>::const_iterator const ven = cites.end();
+ for (; vit != ven; ++vit) {
+ BiblioInfo::const_iterator const biit = bibinfo.find(*vit);
+ if (biit == bibinfo.end())
+ continue;
+ BibTeXInfo const & entry = biit->second;
+ xs << StartTag("div", "class='bibtexentry'");
+ // FIXME XHTML
+ // The same name/id problem we have elsewhere.
+ string const attr = "id='" + to_utf8(entry.key()) + "'";
+ xs << CompTag("a", attr);
+ docstring label = entry.label();
+ if (label.empty())
+ label = entry.key();
+ xs << StartTag("span", "class='bibtexlabel'")
+ << label
+ << EndTag("span");
+ // FIXME Right now, we are calling BibInfo::getInfo on the key,
+ // which will give us all the cross-referenced info. But for every
+ // entry, so there's a lot of repitition. This should be fixed.
+ xs << StartTag("span", "class='bibtexinfo'")
+ << bibinfo.getInfo(entry.key())
+ << EndTag("span")
+ << EndTag("div");
+ }
+ xs << EndTag("div");
+ return docstring();
}