X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FInsetCitation.cpp;h=8f697993b143c94d43d011c2a6fbd50bdf5bfa80;hb=9c55af4a223ce4db29d643251109e245665344bd;hp=2778e199a06bc21c56501f69f1e7ed08a28a5f58;hpb=2ffd130d2bc4b594ab64327479ace742f119b5ae;p=lyx.git diff --git a/src/insets/InsetCitation.cpp b/src/insets/InsetCitation.cpp index 2778e199a0..8f697993b1 100644 --- a/src/insets/InsetCitation.cpp +++ b/src/insets/InsetCitation.cpp @@ -33,6 +33,7 @@ #include "support/lstrings.h" #include +#include using namespace std; using namespace lyx::support; @@ -122,6 +123,32 @@ void InsetCitation::doDispatch(Cursor & cur, FuncRequest & cmd) } +bool InsetCitation::addKey(string const & key) +{ + docstring const ukey = from_utf8(key); + docstring const & curkeys = getParam("key"); + if (curkeys.empty()) { + setParam("key", ukey); + cache.recalculate = true; + return true; + } + + vector keys = getVectorFromString(curkeys); + vector::const_iterator it = keys.begin(); + vector::const_iterator en = keys.end(); + for (; it != en; ++it) { + if (*it == ukey) { + LYXERR0("Key " << key << " already present."); + return false; + } + } + keys.push_back(ukey); + setParam("key", getStringFromVector(keys)); + cache.recalculate = true; + return true; +} + + docstring InsetCitation::toolTip(BufferView const & bv, int, int) const { Buffer const & buf = bv.buffer(); @@ -195,7 +222,7 @@ inline docstring wrapCitation(docstring const & key, return content; // we have to do the escaping here, because we will ultimately // write this as a raw string, so as not to escape the tags. - return "" + + return "" + html::htmlize(content, XHTMLStream::ESCAPE_ALL) + ""; } @@ -247,8 +274,8 @@ docstring InsetCitation::complexLabel(bool for_xhtml) const buffer().params().documentClass().addCiteMacro("!textafter", to_utf8(after)); */ docstring label; - vector const keys = getVectorFromString(key); - label = biblist.getLabel(keys, buffer(), cite_type, for_xhtml, before, after); + vector keys = getVectorFromString(key); + label = biblist.getLabel(keys, buffer(), cite_type, for_xhtml, UINT_MAX, before, after); return label; } @@ -304,22 +331,29 @@ void InsetCitation::updateBuffer(ParIterator const &, UpdateType) } -void InsetCitation::addToToc(DocIterator const & cpit) const +void InsetCitation::addToToc(DocIterator const & cpit, bool output_active) const { // NOTE - // XHTML output uses the TOC to collect the citations - // from the document. So if this gets changed, then we - // will need to change how the citations are collected. + // BiblioInfo::collectCitedEntries() uses the TOC to collect the citations + // from the document. It is used indirectly, via BiblioInfo::makeCitationLables, + // by both XHTML and plaintext output. So, if we change what goes into the TOC, + // then we will also need to change that routine. docstring const tocitem = getParam("key"); Toc & toc = buffer().tocBackend().toc("citation"); - toc.push_back(TocItem(cpit, 0, tocitem)); + toc.push_back(TocItem(cpit, 0, tocitem, output_active)); } -int InsetCitation::plaintext(odocstream & os, OutputParams const &) const +int InsetCitation::plaintext(odocstringstream & os, + OutputParams const &, size_t) const { - os << cache.generated_label; - return cache.generated_label.size(); + string const & cmd = getCmdName(); + if (cmd == "nocite") + return 0; + + docstring const label = generateLabel(false); + os << label; + return label.size(); } @@ -365,11 +399,13 @@ docstring InsetCitation::xhtml(XHTMLStream & xs, OutputParams const &) const void InsetCitation::toString(odocstream & os) const { - plaintext(os, OutputParams(0)); + odocstringstream ods; + plaintext(ods, OutputParams(0)); + os << ods.str(); } -void InsetCitation::forToc(docstring & os, size_t) const +void InsetCitation::forOutliner(docstring & os, size_t) const { os += screenLabel(); } @@ -388,7 +424,7 @@ void InsetCitation::latex(otexstream & os, OutputParams const & runparams) const // FIXME UNICODE docstring const cite_str = from_utf8(citationStyleToString(cs)); - if (runparams.inulemcmd) + if (runparams.inulemcmd > 0) os << "\\mbox{"; os << "\\" << cite_str;