]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetCitation.cpp
InsetTabular.cpp: fix #6585 also for wrapped floats - thanks Vincent
[lyx.git] / src / insets / InsetCitation.cpp
index 7c4caa742ef535829fa6e3c69e710e17c3bb8d9f..26e0fe49046ef535bfec6853069769a0d012cdeb 100644 (file)
@@ -18,7 +18,6 @@
 #include "BufferParams.h"
 #include "BufferView.h"
 #include "DispatchResult.h"
-#include "FuncRequest.h"
 #include "LaTeXFeatures.h"
 #include "output_xhtml.h"
 #include "ParIterator.h"
@@ -41,7 +40,7 @@ ParamInfo InsetCitation::param_info_;
 
 
 InsetCitation::InsetCitation(Buffer * buf, InsetCommandParams const & p)
-       : InsetCommand(buf, p, "citation")
+       : InsetCommand(buf, p)
 {}
 
 
@@ -119,7 +118,7 @@ docstring InsetCitation::toolTip(BufferView const & bv, int, int) const
        vector<docstring>::const_iterator en = keys.end();
        docstring tip;
        for (; it != en; ++it) {
-               docstring const key_info = bi.getInfo(*it);
+               docstring const key_info = bi.getInfo(*it, buffer());
                if (key_info.empty())
                        continue;
                if (!tip.empty())
@@ -432,17 +431,16 @@ docstring InsetCitation::basicLabel(bool for_xhtml) const
        docstring keys = getParam("key");
        docstring label;
 
-       if (contains(keys, ',')) {
-               // Final comma allows while loop to cover all keys
-               keys = ltrim(split(keys, label, ',')) + ',';
-               while (contains(keys, ',')) {
-                       docstring key;
-                       keys = ltrim(split(keys, key, ','));
-                       label += ", " + wrapCitation(key, key, for_xhtml);
-               }
-       } else {
-               label = wrapCitation(keys, keys, for_xhtml);
-       }
+       docstring key;
+       do {
+               // if there is no comma, then everything goes into key
+               // and keys will be empty.
+               keys = trim(split(keys, key, ','));
+               key = trim(key);
+               if (!label.empty())
+                       label += ", ";
+               label += wrapCitation(key, key, for_xhtml);
+       } while (!keys.empty());
 
        docstring const & after = getParam("after");
        if (!after.empty())
@@ -457,7 +455,7 @@ docstring InsetCitation::screenLabel() const
 }
 
 
-void InsetCitation::updateLabels(ParIterator const &, bool)
+void InsetCitation::updateBuffer(ParIterator const &, UpdateType)
 {
        CiteEngine const engine = buffer().params().citeEngine();
        if (cache.params == params() && cache.engine == engine)
@@ -470,7 +468,7 @@ void InsetCitation::updateLabels(ParIterator const &, bool)
 
        docstring label = glabel;
        if (label.size() > maxLabelChars) {
-               label.erase(maxLabelChars-3);
+               label.erase(maxLabelChars - 3);
                label += "...";
        }
 
@@ -483,8 +481,13 @@ void InsetCitation::updateLabels(ParIterator const &, bool)
 
 void InsetCitation::addToToc(DocIterator const & cpit)
 {
+       // 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.
+       docstring const tocitem = getParam("key");
        Toc & toc = buffer().tocBackend().toc("citation");
-       toc.push_back(TocItem(cpit, 0, getParam("key")));
+       toc.push_back(TocItem(cpit, 0, tocitem));
 }
 
 
@@ -548,6 +551,7 @@ void InsetCitation::tocString(odocstream & os) const
 int InsetCitation::latex(odocstream & os, OutputParams const & runparams) const
 {
        CiteEngine cite_engine = buffer().params().citeEngine();
+       BiblioInfo const & bi = buffer().masterBibInfo();
        // FIXME UNICODE
        docstring const cite_str = from_utf8(
                asValidLatexCommand(getCmdName(), cite_engine));
@@ -564,7 +568,11 @@ int InsetCitation::latex(odocstream & os, OutputParams const & runparams) const
        else if (!after.empty())
                os << '[' << after << ']';
 
-       os << '{' << cleanupWhitespace(getParam("key")) << '}';
+       if (!bi.isBibtex(getParam("key")))
+               // escape chars with bibitems
+               os << '{' << escape(cleanupWhitespace(getParam("key"))) << '}';
+       else
+               os << '{' << cleanupWhitespace(getParam("key")) << '}';
 
        if (runparams.inulemcmd)
                os << "}";