X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FInsetCitation.cpp;h=8f697993b143c94d43d011c2a6fbd50bdf5bfa80;hb=9c55af4a223ce4db29d643251109e245665344bd;hp=fdd6e0ba1bace0ad0e69761939cd58610033ea45;hpb=1e947e3a18f3676c527684affa96cd41aa61345c;p=lyx.git diff --git a/src/insets/InsetCitation.cpp b/src/insets/InsetCitation.cpp index fdd6e0ba1b..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; @@ -44,7 +45,16 @@ ParamInfo InsetCitation::param_info_; InsetCitation::InsetCitation(Buffer * buf, InsetCommandParams const & p) : InsetCommand(buf, p) -{} +{ + buffer().removeBiblioTempFiles(); +} + + +InsetCitation::~InsetCitation() +{ + if (isBufferLoaded()) + buffer().removeBiblioTempFiles(); +} ParamInfo const & InsetCitation::findInfo(string const & /* cmdName */) @@ -105,12 +115,40 @@ bool InsetCitation::isCompatibleCommand(string const & cmd) void InsetCitation::doDispatch(Cursor & cur, FuncRequest & cmd) { - if (cmd.action() == LFUN_INSET_MODIFY) + if (cmd.action() == LFUN_INSET_MODIFY) { + buffer().removeBiblioTempFiles(); cache.recalculate = true; + } InsetCommand::doDispatch(cur, 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(); @@ -184,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) + ""; } @@ -236,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; } @@ -293,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(); } @@ -354,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(); } @@ -377,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;