]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetCitation.cpp
Add a document-wide default bibliography style \biblio_style.
[lyx.git] / src / insets / InsetCitation.cpp
index e6495e72abe2cefa7711559367c52d1af04b6291..a53ed549bbccd20ea8230ccc54a2aee07a2242bd 100644 (file)
@@ -19,6 +19,8 @@
 #include "BufferParams.h"
 #include "BufferView.h"
 #include "DispatchResult.h"
+#include "FuncCode.h"
+#include "FuncRequest.h"
 #include "LaTeXFeatures.h"
 #include "output_xhtml.h"
 #include "ParIterator.h"
@@ -99,6 +101,14 @@ bool InsetCitation::isCompatibleCommand(string const & cmd)
 }
 
 
+void InsetCitation::doDispatch(Cursor & cur, FuncRequest & cmd)
+{
+       if (cmd.action() == LFUN_INSET_MODIFY)
+               cache.recalculate = true;
+       InsetCommand::doDispatch(cur, cmd);
+}
+
+
 docstring InsetCitation::toolTip(BufferView const & bv, int, int) const
 {
        Buffer const & buf = bv.buffer();
@@ -131,7 +141,7 @@ docstring InsetCitation::toolTip(BufferView const & bv, int, int) const
 
 
 namespace {
-       
+
 // FIXME See the header for the issue.
 string defaultCiteCommand(CiteEngine engine)
 {
@@ -153,7 +163,7 @@ string defaultCiteCommand(CiteEngine engine)
        return str;
 }
 
-       
+
 string asValidLatexCommand(string const & input, CiteEngine const engine)
 {
        string const default_str = defaultCiteCommand(engine);
@@ -200,14 +210,15 @@ string asValidLatexCommand(string const & input, CiteEngine const engine)
 }
 
 
-inline docstring wrapCitation(docstring const & key, 
+inline docstring wrapCitation(docstring const & key,
                docstring const & content, bool for_xhtml)
 {
        if (!for_xhtml)
                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='#" + key + "'>" + html::htmlize(content) + "</a>";
+       return "<a href='#" + key + "'>" +
+                       html::htmlize(content, XHTMLStream::ESCAPE_ALL) + "</a>";
 }
 
 } // anonymous namespace
@@ -330,11 +341,11 @@ docstring InsetCitation::complexLabel(bool for_xhtml) const
                                else
                                        label += wrapCitation(*it, author, for_xhtml) + sep_str;
                        }
-               } 
+               }
                // nocite
                else if (cite_type == "nocite") {
                        label += *it + sep_str;
-               } 
+               }
                // (authors1 (<before> year);  ... ;
                //  authors_last (<before> year, <after>)
                else if (cite_type == "citet") {
@@ -354,8 +365,8 @@ docstring InsetCitation::complexLabel(bool for_xhtml) const
                        case ENGINE_BASIC:
                                break;
                        }
-               } 
-               // author, year; author, year; ...      
+               }
+               // author, year; author, year; ...
                else if (cite_type == "citep" ||
                           cite_type == "citealp") {
                        if (engine == ENGINE_NATBIB_NUMERICAL) {
@@ -364,7 +375,7 @@ docstring InsetCitation::complexLabel(bool for_xhtml) const
                                label += wrapCitation(*it, author + ", " + year, for_xhtml) + sep_str;
                        }
 
-               } 
+               }
                // (authors1 <before> year;
                //  authors_last <before> year, <after>)
                else if (cite_type == "citealt") {
@@ -378,15 +389,15 @@ docstring InsetCitation::complexLabel(bool for_xhtml) const
                                        wrapCitation(*it, citenum, for_xhtml) + sep_str;
                                break;
                        case ENGINE_JURABIB:
-                               label += before_str + 
+                               label += before_str +
                                        wrapCitation(*it, author + ' ' + year, for_xhtml) + sep_str;
                                break;
                        case ENGINE_BASIC:
                                break;
                        }
 
-               
-               } 
+
+               }
                // author; author; ...
                else if (cite_type == "citeauthor") {
                        label += wrapCitation(*it, author, for_xhtml) + sep_str;
@@ -419,7 +430,7 @@ docstring InsetCitation::complexLabel(bool for_xhtml) const
                label = before_str + label;
        }
 
-       if (cite_type == "citep" || cite_type == "citeyearpar" || 
+       if (cite_type == "citep" || cite_type == "citeyearpar" ||
            (cite_type == "cite" && engine == ENGINE_BASIC) )
                label = op + label + cp;
 
@@ -458,11 +469,10 @@ docstring InsetCitation::screenLabel() const
 
 void InsetCitation::updateBuffer(ParIterator const &, UpdateType)
 {
-       CiteEngine const engine = buffer().params().citeEngine();
-       if (cache.params == params() && cache.engine == engine)
+       if (!cache.recalculate && buffer().citeLabelsValid())
                return;
 
-       // The label has changed, so we have to re-create it.
+       // The label may have changed, so we have to re-create it.
        docstring const glabel = generateLabel();
 
        unsigned int const maxLabelChars = 45;
@@ -473,14 +483,13 @@ void InsetCitation::updateBuffer(ParIterator const &, UpdateType)
                label += "...";
        }
 
-       cache.engine  = engine;
-       cache.params = params();
+       cache.recalculate = false;
        cache.generated_label = glabel;
        cache.screen_label = label;
 }
 
 
-void InsetCitation::addToToc(DocIterator const & cpit)
+void InsetCitation::addToToc(DocIterator const & cpit) const
 {
        // NOTE
        // XHTML output uses the TOC to collect the citations
@@ -533,23 +542,29 @@ docstring InsetCitation::xhtml(XHTMLStream & xs, OutputParams const &) const
                return docstring();
 
        // have to output this raw, because generateLabel() will include tags
-       xs << XHTMLStream::NextRaw() << generateLabel(true);
+       xs << XHTMLStream::ESCAPE_NONE << generateLabel(true);
 
        return docstring();
 }
 
 
-void InsetCitation::tocString(odocstream & os) const
+void InsetCitation::toString(odocstream & os) const
 {
        plaintext(os, OutputParams(0));
 }
 
 
+void InsetCitation::forToc(docstring & os, size_t) const
+{
+       os += screenLabel();
+}
+
+
 // Have to overwrite the default InsetCommand method in order to check that
 // the \cite command is valid. Eg, the user has natbib enabled, inputs some
 // citations and then changes his mind, turning natbib support off. The output
 // should revert to \cite[]{}
-int InsetCitation::latex(odocstream & os, OutputParams const & runparams) const
+void InsetCitation::latex(otexstream & os, OutputParams const & runparams) const
 {
        CiteEngine cite_engine = buffer().params().citeEngine();
        BiblioInfo const & bi = buffer().masterBibInfo();
@@ -577,8 +592,6 @@ int InsetCitation::latex(odocstream & os, OutputParams const & runparams) const
 
        if (runparams.inulemcmd)
                os << "}";
-
-       return 0;
 }
 
 
@@ -598,9 +611,9 @@ void InsetCitation::validate(LaTeXFeatures & features) const
 }
 
 
-docstring InsetCitation::contextMenu(BufferView const &, int, int) const
+string InsetCitation::contextMenuName() const
 {
-       return from_ascii("context-citation");
+       return "context-citation";
 }