Move label generation from InsetBibtex to BiblioInfo.

This only move the code, but does not change the displayed labels.
Thus for numerical citation, the label is set to the cite number;
for author-year citation, the abbreviated list of authors is used
i.e. "Smith et al. 2001".

Eventually, we might want to make the label customizable, or get
it from BibTeX.
This commit is contained in:
Julien Rioux 2013-02-01 16:18:37 +01:00
parent f51636b547
commit 6456c2262e
2 changed files with 24 additions and 38 deletions

View File

@ -1004,6 +1004,28 @@ void BiblioInfo::makeCitationLabels(Buffer const & buf)
last = biit; last = biit;
} }
} }
// Set the labels
it = cited_entries_.begin();
for (; it != en; ++it) {
map<docstring, BibTeXInfo>::iterator const biit = bimap_.find(*it);
// this shouldn't happen, but...
if (biit == bimap_.end())
// ...fail gracefully, anyway.
continue;
BibTeXInfo & entry = biit->second;
if (numbers) {
entry.label(entry.citeNumber());
} else {
docstring const auth = entry.getAbbreviatedAuthor(buf, false);
// we do it this way so as to access the xref, if necessary
// note that this also gives us the modifier
docstring const year = getYear(*it, buf, true);
if (!auth.empty() && !year.empty())
entry.label(auth + ' ' + year);
else
entry.label(entry.key());
}
}
} }

View File

@ -933,8 +933,6 @@ int InsetBibtex::plaintext(odocstream & os, OutputParams const &) const
BiblioInfo bibinfo = buffer().masterBibInfo(); BiblioInfo bibinfo = buffer().masterBibInfo();
bibinfo.makeCitationLabels(buffer()); bibinfo.makeCitationLabels(buffer());
vector<docstring> const & cites = bibinfo.citedEntries(); vector<docstring> const & cites = bibinfo.citedEntries();
CiteEngineType const engine_type = buffer().params().citeEngineType();
bool const numbers = (engine_type == ENGINE_TYPE_NUMERICAL);
docstring refoutput; docstring refoutput;
docstring const reflabel = buffer().B_("References"); docstring const reflabel = buffer().B_("References");
@ -949,23 +947,7 @@ int InsetBibtex::plaintext(odocstream & os, OutputParams const &) const
if (biit == bibinfo.end()) if (biit == bibinfo.end())
continue; continue;
BibTeXInfo const & entry = biit->second; BibTeXInfo const & entry = biit->second;
docstring citekey; refoutput += "[" + entry.label() + "] ";
if (numbers)
citekey = entry.citeNumber();
else {
docstring const auth = entry.getAbbreviatedAuthor(buffer(), false);
// we do it this way so as to access the xref, if necessary
// note that this also gives us the modifier
docstring const year = bibinfo.getYear(*vit, buffer(), true);
if (!auth.empty() && !year.empty())
citekey = auth + ' ' + year;
}
if (citekey.empty()) {
citekey = entry.label();
if (citekey.empty())
citekey = entry.key();
}
refoutput += "[" + citekey + "] ";
// FIXME Right now, we are calling BibInfo::getInfo on the key, // FIXME Right now, we are calling BibInfo::getInfo on the key,
// which will give us all the cross-referenced info. But for every // which will give us all the cross-referenced info. But for every
// entry, so there's a lot of repitition. This should be fixed. // entry, so there's a lot of repitition. This should be fixed.
@ -983,8 +965,6 @@ docstring InsetBibtex::xhtml(XHTMLStream & xs, OutputParams const &) const
{ {
BiblioInfo const & bibinfo = buffer().masterBibInfo(); BiblioInfo const & bibinfo = buffer().masterBibInfo();
vector<docstring> const & cites = bibinfo.citedEntries(); vector<docstring> const & cites = bibinfo.citedEntries();
CiteEngineType const engine_type = buffer().params().citeEngineType();
bool const numbers = (engine_type == ENGINE_TYPE_NUMERICAL);
docstring const reflabel = buffer().B_("References"); docstring const reflabel = buffer().B_("References");
@ -1007,24 +987,8 @@ docstring InsetBibtex::xhtml(XHTMLStream & xs, OutputParams const &) const
string const attr = string const attr =
"id='LyXCite-" + to_utf8(html::cleanAttr(entry.key())) + "'"; "id='LyXCite-" + to_utf8(html::cleanAttr(entry.key())) + "'";
xs << html::CompTag("a", attr); xs << html::CompTag("a", attr);
docstring citekey;
if (numbers)
citekey = entry.citeNumber();
else {
docstring const auth = entry.getAbbreviatedAuthor(buffer(), false);
// we do it this way so as to access the xref, if necessary
// note that this also gives us the modifier
docstring const year = bibinfo.getYear(*vit, buffer(), true);
if (!auth.empty() && !year.empty())
citekey = auth + ' ' + year;
}
if (citekey.empty()) {
citekey = entry.label();
if (citekey.empty())
citekey = entry.key();
}
xs << html::StartTag("span", "class='bibtexlabel'") xs << html::StartTag("span", "class='bibtexlabel'")
<< citekey << entry.label()
<< html::EndTag("span"); << html::EndTag("span");
// FIXME Right now, we are calling BibInfo::getInfo on the key, // FIXME Right now, we are calling BibInfo::getInfo on the key,
// which will give us all the cross-referenced info. But for every // which will give us all the cross-referenced info. But for every