]> git.lyx.org Git - features.git/blobdiff - src/insets/InsetCitation.cpp
Make the generation of children's tocs more robust
[features.git] / src / insets / InsetCitation.cpp
index 3972394ce23aaeffb611657021e8cffa30aabf1e..0a5da5b1192f63a04d4210e7f1489e64e35c461c 100644 (file)
@@ -123,7 +123,7 @@ void InsetCitation::doDispatch(Cursor & cur, FuncRequest & cmd)
                if (cmd.getArg(0) == "toggleparam") {
                        string cmdname = getCmdName();
                        string const alias =
-                               buffer().params().getCiteAlias(cmdname);
+                               buffer().masterParams().getCiteAlias(cmdname);
                        if (!alias.empty())
                                cmdname = alias;
                        string const par = cmd.getArg(1);
@@ -157,7 +157,7 @@ bool InsetCitation::getStatus(Cursor & cur, FuncRequest const & cmd,
                if (cmd.getArg(0) == "changetype") {
                        string cmdname = getCmdName();
                        string const alias =
-                               buffer().params().getCiteAlias(cmdname);
+                               buffer().masterParams().getCiteAlias(cmdname);
                        if (!alias.empty())
                                cmdname = alias;
                        if (suffixIs(cmdname, "*"))
@@ -169,12 +169,12 @@ bool InsetCitation::getStatus(Cursor & cur, FuncRequest const & cmd,
                if (cmd.getArg(0) == "toggleparam") {
                        string cmdname = getCmdName();
                        string const alias =
-                               buffer().params().getCiteAlias(cmdname);
+                               buffer().masterParams().getCiteAlias(cmdname);
                        if (!alias.empty())
                                cmdname = alias;
                        vector<CitationStyle> citation_styles =
-                               buffer().params().citeStyles();
-                       CitationStyle cs = getCitationStyle(buffer().params(),
+                               buffer().masterParams().citeStyles();
+                       CitationStyle cs = getCitationStyle(buffer().masterParams(),
                                                            cmdname, citation_styles);
                        if (cmd.getArg(1) == "star") {
                                status.setEnabled(cs.hasStarredVersion);
@@ -241,11 +241,21 @@ docstring InsetCitation::toolTip(BufferView const & bv, int, int) const
 
        docstring tip;
        tip += "<ol>";
+       int count = 0;
        for (docstring const & key : keys) {
                docstring const key_info = bi.getInfo(key, buffer(), ci);
+               // limit to reasonable size.
+               if (count > 9 && keys.size() > 11) {
+                       tip.push_back(0x2026);// HORIZONTAL ELLIPSIS
+                       tip += "<p>"
+                               + bformat(_("+ %1$d more entries."), int(keys.size() - count))
+                               + "</p>";
+                       break;
+               }
                if (key_info.empty())
                        continue;
                tip += "<li>" + key_info + "</li>";
+               ++count;
        }
        tip += "</ol>";
        return tip;
@@ -339,7 +349,7 @@ docstring InsetCitation::complexLabel(bool for_xhtml) const
                cite_type = cite_type.substr(0, cite_type.size() - 1);
 
        // handle alias
-       string const alias = buf.params().getCiteAlias(cite_type);
+       string const alias = buf.masterParams().getCiteAlias(cite_type);
        if (!alias.empty())
                cite_type = alias;
 
@@ -410,7 +420,7 @@ void InsetCitation::updateBuffer(ParIterator const &, UpdateType)
 
 
 void InsetCitation::addToToc(DocIterator const & cpit, bool output_active,
-                                                        UpdateType) const
+                                                        UpdateType, TocBackend & backend) const
 {
        // NOTE
        // BiblioInfo::collectCitedEntries() uses the TOC to collect the citations 
@@ -418,8 +428,9 @@ void InsetCitation::addToToc(DocIterator const & cpit, bool output_active,
        // 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");
-       shared_ptr<Toc> toc = buffer().tocBackend().toc("citation");
-       toc->push_back(TocItem(cpit, 0, tocitem, output_active));
+       TocBuilder & b = backend.builder("citation");
+       b.pushItem(cpit, tocitem, output_active);
+       b.pop();
 }
 
 
@@ -497,9 +508,19 @@ void InsetCitation::forOutliner(docstring & os, size_t const, bool const) const
 // engine, e.g. \cite[]{} for the basic engine.
 void InsetCitation::latex(otexstream & os, OutputParams const & runparams) const
 {
-       vector<CitationStyle> citation_styles = buffer().params().citeStyles();
-       CitationStyle cs = asValidLatexCommand(buffer().params(), getCmdName(), citation_styles);
        BiblioInfo const & bi = buffer().masterBibInfo();
+       if (getCmdName() == "keyonly") {
+               // Special command to only return the key
+               if (!bi.isBibtex(getParam("key")))
+                       // escape chars with bibitems
+                       os << escape(cleanupWhitespace(getParam("key")));
+               else
+                       os << cleanupWhitespace(getParam("key"));
+               return;
+       }
+       vector<CitationStyle> citation_styles = buffer().masterParams().citeStyles();
+       CitationStyle cs = asValidLatexCommand(buffer().masterParams(),
+                                              getCmdName(), citation_styles);
        // FIXME UNICODE
        docstring const cite_str = from_utf8(citationStyleToString(cs, true));