]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetRef.cpp
doubly stupid bug fix.
[lyx.git] / src / insets / InsetRef.cpp
index 642d99a3a98c58c4592de0b6f1870ebfaf6748f8..84a602e8648a0e63da8f0bd713a2445851fd94ee 100644 (file)
 #include "Cursor.h"
 #include "DispatchResult.h"
 #include "FuncRequest.h"
-#include "support/gettext.h"
 #include "LaTeXFeatures.h"
 #include "LyXFunc.h"
 #include "OutputParams.h"
+#include "ParIterator.h"
 #include "sgml.h"
+#include "TocBackend.h"
 
 #include "support/docstream.h"
+#include "support/gettext.h"
 #include "support/lstrings.h"
 
 using namespace std;
@@ -56,8 +58,8 @@ ParamInfo const & InsetRef::findInfo(string const & /* cmdName */)
 {
        static ParamInfo param_info_;
        if (param_info_.empty()) {
-               param_info_.add("name", true);
-               param_info_.add("reference", false);
+               param_info_.add("name", ParamInfo::LATEX_OPTIONAL);
+               param_info_.add("reference", ParamInfo::LATEX_REQUIRED);
        }
        return param_info_;
 }
@@ -153,6 +155,36 @@ void InsetRef::textString(Buffer const & buf, odocstream & os) const
 }
 
 
+void InsetRef::addToToc(Buffer const & buf,
+       ParConstIterator const & cpit) const
+{
+       docstring const & label = getParam("reference");
+       Toc & toc = buf.tocBackend().toc("label");
+       Toc::iterator it = toc.begin();
+       Toc::iterator end = toc.end();
+       for (; it != end; ++it) {
+               if (it->str() == label)
+                       break;
+       }
+
+       docstring const reflabel = getScreenLabel(buf);
+       if (it == end) {
+               // This label has not been parsed yet so we just add it temporarily.
+               // InsetLabel::addTocToc() will fix that later.
+               toc.push_back(TocItem(cpit, 0, label));
+               toc.push_back(TocItem(cpit, 1, reflabel));
+               return;
+       }
+
+       // The Toc item for this label already exists so let's add
+       // this inset to this node.
+       ++it;
+       while (it != end && it->str() == reflabel)
+               ++it;
+       toc.insert(it, TocItem(cpit, 1, reflabel));
+}
+
+
 void InsetRef::validate(LaTeXFeatures & features) const
 {
        if (getCmdName() == "vref" || getCmdName() == "vpageref")