]> 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 2cccc2931f42492ad96216b3e6d91e08cc5adbdd..ddbff5ebb5a362e5b7aece417a6ca17f286321f2 100644 (file)
 #include "Cursor.h"
 #include "DispatchResult.h"
 #include "FuncRequest.h"
-#include "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;
+using namespace lyx::support;
 
 namespace lyx {
 
-using support::escape;
-
-using std::string;
-using std::ostream;
-
 
 InsetRef::InsetRef(InsetCommandParams const & p, Buffer const & buf)
        : InsetCommand(p, "ref"), isLatex(buf.isLatex())
@@ -42,7 +42,7 @@ InsetRef::InsetRef(InsetRef const & ir)
 {}
 
 
-bool InsetRef::isCompatibleCommand(std::string const & s) {
+bool InsetRef::isCompatibleCommand(string const & s) {
        //FIXME This is likely not the best way to handle this.
        //But this stuff is hardcoded elsewhere already.
        return s == "ref" 
@@ -54,12 +54,14 @@ bool InsetRef::isCompatibleCommand(std::string const & s) {
 }
 
 
-CommandInfo const * InsetRef::findInfo(std::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_;
 }
 
 
@@ -147,10 +149,26 @@ int InsetRef::docbook(Buffer const & buf, odocstream & os,
 }
 
 
-int InsetRef::textString(Buffer const & buf, odocstream & os,
-                      OutputParams const & op) const
+void InsetRef::textString(Buffer const & buf, odocstream & os) const
+{
+       plaintext(buf, os, OutputParams(0));
+}
+
+
+void InsetRef::addToToc(Buffer const & buf,
+       ParConstIterator const & cpit) const
 {
-       return plaintext(buf, os, op);
+       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;
+               }
+       }
 }