From 6456c2262e348f6bc81c4e59c68e35c045dfa2cb Mon Sep 17 00:00:00 2001 From: Julien Rioux Date: Fri, 1 Feb 2013 16:18:37 +0100 Subject: [PATCH] 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. --- src/BiblioInfo.cpp | 22 +++++++++++++++++++++ src/insets/InsetBibtex.cpp | 40 ++------------------------------------ 2 files changed, 24 insertions(+), 38 deletions(-) diff --git a/src/BiblioInfo.cpp b/src/BiblioInfo.cpp index bf718c753b..38883e86fb 100644 --- a/src/BiblioInfo.cpp +++ b/src/BiblioInfo.cpp @@ -1004,6 +1004,28 @@ void BiblioInfo::makeCitationLabels(Buffer const & buf) last = biit; } } + // Set the labels + it = cited_entries_.begin(); + for (; it != en; ++it) { + map::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()); + } + } } diff --git a/src/insets/InsetBibtex.cpp b/src/insets/InsetBibtex.cpp index 8a5e9fd3e0..9c51355a21 100644 --- a/src/insets/InsetBibtex.cpp +++ b/src/insets/InsetBibtex.cpp @@ -933,8 +933,6 @@ int InsetBibtex::plaintext(odocstream & os, OutputParams const &) const BiblioInfo bibinfo = buffer().masterBibInfo(); bibinfo.makeCitationLabels(buffer()); vector const & cites = bibinfo.citedEntries(); - CiteEngineType const engine_type = buffer().params().citeEngineType(); - bool const numbers = (engine_type == ENGINE_TYPE_NUMERICAL); docstring refoutput; docstring const reflabel = buffer().B_("References"); @@ -949,23 +947,7 @@ int InsetBibtex::plaintext(odocstream & os, OutputParams const &) const if (biit == bibinfo.end()) continue; BibTeXInfo const & entry = biit->second; - 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(); - } - refoutput += "[" + citekey + "] "; + refoutput += "[" + entry.label() + "] "; // 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. @@ -983,8 +965,6 @@ docstring InsetBibtex::xhtml(XHTMLStream & xs, OutputParams const &) const { BiblioInfo const & bibinfo = buffer().masterBibInfo(); vector 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"); @@ -1007,24 +987,8 @@ docstring InsetBibtex::xhtml(XHTMLStream & xs, OutputParams const &) const string const attr = "id='LyXCite-" + to_utf8(html::cleanAttr(entry.key())) + "'"; 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'") - << citekey + << entry.label() << html::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 -- 2.39.2