]> 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 4c87e69591affdd09551625e0b2ff0a99721671e..c23cee2b06ae45f32efee58f2d94284b2676a9d1 100644 (file)
 
 #include "InsetLabel.h"
 
+#include "InsetRef.h"
+
 #include "Buffer.h"
 #include "BufferView.h"
 #include "DispatchResult.h"
 #include "FuncRequest.h"
+#include "InsetIterator.h"
 #include "ParIterator.h"
 #include "sgml.h"
 #include "Text.h"
 #include "TocBackend.h"
 
-#include "support/lstrings.h"
+#include "frontends/alert.h"
+
 #include "support/lyxalgo.h"
+#include "support/gettext.h"
+#include "support/lstrings.h"
 
 using namespace std;
 using namespace lyx::support;
@@ -57,10 +63,32 @@ docstring InsetLabel::screenLabel() const
 }
 
 
+void InsetLabel::updateLabels(ParIterator const & it)
+{
+       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");
-       toc.push_back(TocItem(cpit, 0, screenLabel()));
+       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()));
+       }
 }