]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetRef.cpp
doubly stupid bug fix.
[lyx.git] / src / insets / InsetRef.cpp
index f1838c28fcf71a2bfe74fce5969dbef1799e7710..84a602e8648a0e63da8f0bd713a2445851fd94ee 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,6 +42,29 @@ InsetRef::InsetRef(InsetRef const & ir)
 {}
 
 
+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" 
+               || s == "pageref"
+               || s == "vref" 
+               || s == "vpageref"
+               || s == "prettyref"
+               || s == "eqref";
+}
+
+
+ParamInfo const & InsetRef::findInfo(string const & /* cmdName */)
+{
+       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_;
+}
+
+
 void InsetRef::doDispatch(Cursor & cur, FuncRequest & cmd)
 {
        switch (cmd.action) {
@@ -126,10 +149,39 @@ 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
 {
-       return plaintext(buf, os, op);
+       plaintext(buf, os, OutputParams(0));
+}
+
+
+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));
 }