]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetRef.cpp
He he he, something I've been dreaming of for a long time: label and reference navigator!
[lyx.git] / src / insets / InsetRef.cpp
index 9a3209f894df83ef646da71ef7e0ddb2d8029fbe..ddbff5ebb5a362e5b7aece417a6ca17f286321f2 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;
@@ -52,12 +54,14 @@ bool InsetRef::isCompatibleCommand(string const & s) {
 }
 
 
-CommandInfo const * InsetRef::findInfo(string const & /* cmdName */)
+ParamInfo const & InsetRef::findInfo(string const & /* cmdName */)
 {
-       static const char * const paramnames[] = {"name", "reference", ""};
-       static const bool isoptional[] = {true, false};
-       static const CommandInfo info = {2, paramnames, isoptional};
-       return &info;
+       static ParamInfo param_info_;
+       if (param_info_.empty()) {
+               param_info_.add("name", ParamInfo::LATEX_OPTIONAL);
+               param_info_.add("reference", ParamInfo::LATEX_REQUIRED);
+       }
+       return param_info_;
 }
 
 
@@ -151,6 +155,23 @@ 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::const_iterator it = toc.begin();
+       Toc::const_iterator end = toc.end();
+       for (; it != end; ++it) {
+               if (it->str() == label) {
+                       ++it;
+                       toc.insert(it, TocItem(cpit, 1, getScreenLabel(buf)));
+                       break;
+               }
+       }
+}
+
+
 void InsetRef::validate(LaTeXFeatures & features) const
 {
        if (getCmdName() == "vref" || getCmdName() == "vpageref")