]> git.lyx.org Git - features.git/blobdiff - src/insets/InsetLabel.cpp
Introduce a labels&references cache at buffer level. This cache uses the already...
[features.git] / src / insets / InsetLabel.cpp
index c0b6b4d19d316c3fec4a57c2f5227d86a3ea062c..c23cee2b06ae45f32efee58f2d94284b2676a9d1 100644 (file)
 
 #include "InsetLabel.h"
 
+#include "InsetRef.h"
+
 #include "Buffer.h"
 #include "BufferView.h"
 #include "DispatchResult.h"
 #include "FuncRequest.h"
-#include "Text.h"
+#include "InsetIterator.h"
+#include "ParIterator.h"
 #include "sgml.h"
+#include "Text.h"
+#include "TocBackend.h"
+
+#include "frontends/alert.h"
 
-#include "support/lstrings.h"
 #include "support/lyxalgo.h"
+#include "support/gettext.h"
+#include "support/lstrings.h"
 
 using namespace std;
 using namespace lyx::support;
@@ -43,21 +51,44 @@ ParamInfo const & InsetLabel::findInfo(string const & /* cmdName */)
 }
 
 
-Inset * InsetLabel::clone() const
+void InsetLabel::getLabelList(vector<docstring> & list) const
 {
-       return new InsetLabel(params());
+       list.push_back(getParam("name"));
 }
 
 
-void InsetLabel::getLabelList(Buffer const &, vector<docstring> & list) const
+docstring InsetLabel::screenLabel() const
 {
-       list.push_back(getParam("name"));
+       return getParam("name");
 }
 
 
-docstring const InsetLabel::getScreenLabel(Buffer const &) const
+void InsetLabel::updateLabels(ParIterator const & it)
 {
-       return getParam("name");
+       docstring const & label = getParam("name");
+       if (buffer().insetLabel(label))
+               // Problem: We already have an InsetLabel with the same name!
+               return;
+       buffer().setInsetLabel(label, this);
+}
+
+
+void InsetLabel::addToToc(ParConstIterator const & cpit) const
+{
+       docstring const & label = getParam("name");
+       Toc & toc = buffer().tocBackend().toc("label");
+       if (buffer().insetLabel(label) != this) {
+               toc.push_back(TocItem(cpit, 0, _("DUPLICATE: ") + label));
+               return;
+       }
+       toc.push_back(TocItem(cpit, 0, label));
+       Buffer::References const & refs = buffer().references(label);
+       Buffer::References::const_iterator it = refs.begin();
+       Buffer::References::const_iterator end = refs.end();
+       for (; it != end; ++it) {
+               ParConstIterator const ref_pit(it->second);
+               toc.push_back(TocItem(ref_pit, 1, it->first->screenLabel()));
+       }
 }
 
 
@@ -87,16 +118,14 @@ void InsetLabel::doDispatch(Cursor & cur, FuncRequest & cmd)
 }
 
 
-int InsetLabel::latex(Buffer const &, odocstream & os,
-                     OutputParams const &) const
+int InsetLabel::latex(odocstream & os, OutputParams const &) const
 {
        os << escape(getCommand());
        return 0;
 }
 
 
-int InsetLabel::plaintext(Buffer const &, odocstream & os,
-                         OutputParams const &) const
+int InsetLabel::plaintext(odocstream & os, OutputParams const &) const
 {
        docstring const str = getParam("name");
        os << '<' << str << '>';
@@ -104,11 +133,10 @@ int InsetLabel::plaintext(Buffer const &, odocstream & os,
 }
 
 
-int InsetLabel::docbook(Buffer const & buf, odocstream & os,
-                       OutputParams const & runparams) const
+int InsetLabel::docbook(odocstream & os, OutputParams const & runparams) const
 {
        os << "<!-- anchor id=\""
-          << sgml::cleanID(buf, runparams, getParam("name"))
+          << sgml::cleanID(buffer(), runparams, getParam("name"))
           << "\" -->";
        return 0;
 }