]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetRef.cpp
How about if we write a script to do some of this and stop doing it
[lyx.git] / src / insets / InsetRef.cpp
index b9e7909b220b45b4cc00c1e55a468e7f6882130d..7e0eb6db33f8dc78092998e30294916cd70ab800 100644 (file)
@@ -3,7 +3,7 @@
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
- * \author José Matos
+ * \author José Matos
  *
  * Full author contact details are available in file CREDITS.
  */
@@ -18,6 +18,7 @@
 #include "LaTeXFeatures.h"
 #include "LyXFunc.h"
 #include "OutputParams.h"
+#include "output_xhtml.h"
 #include "ParIterator.h"
 #include "sgml.h"
 #include "TocBackend.h"
 #include "support/gettext.h"
 #include "support/lstrings.h"
 
-using namespace std;
 using namespace lyx::support;
+using namespace std;
 
 namespace lyx {
 
 
-InsetRef::InsetRef(InsetCommandParams const & p, Buffer const & buf)
-       : InsetCommand(p, "ref"), isLatex(buf.isLatex())
+InsetRef::InsetRef(Buffer * buf, InsetCommandParams const & p)
+       : InsetCommand(buf, p, "ref"), isLatex(buf->isLatex())
 {}
 
 
@@ -65,45 +66,13 @@ ParamInfo const & InsetRef::findInfo(string const & /* cmdName */)
 }
 
 
-void InsetRef::doDispatch(Cursor & cur, FuncRequest & cmd)
-{
-       switch (cmd.action) {
-       case LFUN_MOUSE_RELEASE:
-               // Eventually trigger dialog with button 3 not 1
-               if (cmd.button() == mouse_button::button3)
-                       lyx::dispatch(FuncRequest(LFUN_LABEL_GOTO,
-                                                 getParam("reference")));
-               else
-                       InsetCommand::doDispatch(cur, cmd);
-               break;
-
-       default:
-               InsetCommand::doDispatch(cur, cmd);
-       }
-}
-
-
-docstring const InsetRef::getScreenLabel(Buffer const &) const
+docstring InsetRef::screenLabel() const
 {
-       docstring temp;
-       for (int i = 0; !types[i].latex_name.empty(); ++i) {
-               if (getCmdName() == types[i].latex_name) {
-                       temp = _(types[i].short_gui_name);
-                       break;
-               }
-       }
-       temp += getParam("reference");
-
-       if (!isLatex && !getParam("name").empty()) {
-               temp += "||";
-               temp += getParam("name");
-       }
-       return temp;
+       return screen_label_;
 }
 
 
-int InsetRef::latex(Buffer const &, odocstream & os,
-                   OutputParams const &) const
+int InsetRef::latex(odocstream & os, OutputParams const &) const
 {
        // We don't want to output p_["name"], since that is only used 
        // in docbook. So we construct new params, without it, and use that.
@@ -114,8 +83,7 @@ int InsetRef::latex(Buffer const &, odocstream & os,
 }
 
 
-int InsetRef::plaintext(Buffer const &, odocstream & os,
-                       OutputParams const &) const
+int InsetRef::plaintext(odocstream & os, OutputParams const &) const
 {
        docstring const str = getParam("reference");
        os << '[' << str << ']';
@@ -123,23 +91,22 @@ int InsetRef::plaintext(Buffer const &, odocstream & os,
 }
 
 
-int InsetRef::docbook(Buffer const & buf, odocstream & os,
-                     OutputParams const & runparams) const
+int InsetRef::docbook(odocstream & os, OutputParams const & runparams) const
 {
        docstring const & name = getParam("name");
        if (name.empty()) {
                if (runparams.flavor == OutputParams::XML) {
                        os << "<xref linkend=\""
-                          << sgml::cleanID(buf, runparams, getParam("reference"))
+                          << sgml::cleanID(buffer(), runparams, getParam("reference"))
                           << "\" />";
                } else {
                        os << "<xref linkend=\""
-                          << sgml::cleanID(buf, runparams, getParam("reference"))
+                          << sgml::cleanID(buffer(), runparams, getParam("reference"))
                           << "\">";
                }
        } else {
                os << "<link linkend=\""
-                  << sgml::cleanID(buf, runparams, getParam("reference"))
+                  << sgml::cleanID(buffer(), runparams, getParam("reference"))
                   << "\">"
                   << getParam("name")
                   << "</link>";
@@ -149,33 +116,58 @@ int InsetRef::docbook(Buffer const & buf, odocstream & os,
 }
 
 
-void InsetRef::textString(Buffer const & buf, odocstream & os) const
+docstring InsetRef::xhtml(XHTMLStream & xs, OutputParams const &) const
 {
-       plaintext(buf, os, OutputParams(0));
+       // FIXME What we'd really like to do is to be able to output some
+       // appropriate sort of text here. But to do that, we need to associate
+       // some sort of counter with the label, and we don't have that yet.
+       docstring const ref = html::cleanAttr(getParam("reference"));
+       string const attr = "href=\"#" + to_utf8(ref) + "\"";
+       xs << StartTag("a", attr);
+       xs << ref;
+       xs << EndTag("a");
+       return docstring();
 }
 
 
-void InsetRef::addToToc(Buffer const & buf,
-       ParConstIterator const & cpit) const
+void InsetRef::tocString(odocstream & os) const
+{
+       plaintext(os, OutputParams(0));
+}
+
+
+void InsetRef::updateLabels(ParIterator const & it, bool)
 {
        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)
+       // register this inset into the buffer reference cache.
+       buffer().references(label).push_back(make_pair(this, it));
+
+       for (int i = 0; !types[i].latex_name.empty(); ++i) {
+               if (getCmdName() == types[i].latex_name) {
+                       screen_label_ = _(types[i].short_gui_name);
                        break;
+               }
        }
+       screen_label_ += label;
 
-       if (it == end)
-               //FIXME: this is an orphan, is this really possible?
+       if (!isLatex && !getParam("name").empty()) {
+               screen_label_ += "||";
+               screen_label_ += getParam("name");
+       }
+}
+
+
+void InsetRef::addToToc(DocIterator const & cpit)
+{
+       docstring const & label = getParam("reference");
+       if (buffer().insetLabel(label))
+               // This InsetRef has already been taken care of in InsetLabel::addToToc().
                return;
 
-       docstring const reflabel = getScreenLabel(buf);
-       ++it;
-       while (it->str() == reflabel && it != end)
-               ++it;
-       toc.insert(it, TocItem(cpit, 1, reflabel));
+       // It seems that this reference does not point to any valid label.
+       screen_label_ = _("BROKEN: ") + screen_label_;
+       Toc & toc = buffer().tocBackend().toc("label");
+       toc.push_back(TocItem(cpit, 0, screen_label_));
 }