]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetCitation.cpp
Prettify the tooltip for footnotes.
[lyx.git] / src / insets / InsetCitation.cpp
index d5c43535b101a79a706b559e066b25b8de12f90e..c0e61798a8fecda40ed999b9d0091ff0020f4841 100644 (file)
@@ -44,7 +44,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 +114,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<docstring> keys = getVectorFromString(curkeys);
+       vector<docstring>::const_iterator it = keys.begin();
+       vector<docstring>::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 +221,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 "<a href='#LyXCite-" + key + "'>" +
+       return "<a href='#LyXCite-" + html::cleanAttr(key) + "'>" +
                        html::htmlize(content, XHTMLStream::ESCAPE_ALL) + "</a>";
 }
 
@@ -293,7 +330,7 @@ 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
@@ -301,14 +338,20 @@ void InsetCitation::addToToc(DocIterator const & cpit) const
        // 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, 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,7 +397,9 @@ 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();
 }