]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetRef.cpp
Fix quotation marks in PDF TOC
[lyx.git] / src / insets / InsetRef.cpp
index fbcea451051754542a0c995400cb37bb8c6ed985..79dfad24806415beefb79254718844040bd042f0 100644 (file)
@@ -22,6 +22,7 @@
 #include "LyX.h"
 #include "OutputParams.h"
 #include "output_xhtml.h"
+#include "Paragraph.h"
 #include "ParIterator.h"
 #include "sgml.h"
 #include "texstream.h"
@@ -40,12 +41,12 @@ namespace lyx {
 
 
 InsetRef::InsetRef(Buffer * buf, InsetCommandParams const & p)
-       : InsetCommand(buf, p), broken_(false)
+       : InsetCommand(buf, p), broken_(false), active_(true)
 {}
 
 
 InsetRef::InsetRef(InsetRef const & ir)
-       : InsetCommand(ir), broken_(false)
+       : InsetCommand(ir), broken_(false), active_(true)
 {}
 
 
@@ -401,6 +402,23 @@ void InsetRef::forOutliner(docstring & os, size_t const, bool const) const
 void InsetRef::updateBuffer(ParIterator const & it, UpdateType, bool const /*deleted*/)
 {
        docstring const & ref = getParam("reference");
+
+       // Check if this one is active (i.e., neither deleted with change-tracking
+       // nor in an inset that does not produce output, such as notes or inactive branches)
+       Paragraph const & para = it.paragraph();
+       active_ = !para.isDeleted(it.pos()) && para.inInset().producesOutput();
+       // If not, check whether we are in a deleted/non-outputting inset
+       if (active_) {
+               for (size_type sl = 0 ; sl < it.depth() ; ++sl) {
+                       Paragraph const & outer_par = it[sl].paragraph();
+                       if (outer_par.isDeleted(it[sl].pos())
+                           || !outer_par.inInset().producesOutput()) {
+                               active_ = false;
+                               break;
+                       }
+               }
+       }
+
        // register this inset into the buffer reference cache.
        buffer().addReference(ref, this, it);
 
@@ -443,6 +461,7 @@ void InsetRef::updateBuffer(ParIterator const & it, UpdateType, bool const /*del
 
        screen_label_ = label;
        broken_ = false;
+       setBroken(broken_);
 }
 
 
@@ -453,20 +472,28 @@ docstring InsetRef::screenLabel() const
 
 
 void InsetRef::addToToc(DocIterator const & cpit, bool output_active,
-                                               UpdateType, TocBackend & backend) const
+                       UpdateType, TocBackend & backend) const
 {
+       active_ = output_active;
        docstring const & label = getParam("reference");
        if (buffer().insetLabel(label)) {
                broken_ = !buffer().activeLabel(label);
+               setBroken(broken_);
+               if (broken_ && output_active) {
+                       shared_ptr<Toc> toc2 = backend.toc("brokenrefs");
+                       toc2->push_back(TocItem(cpit, 0, screenLabel(), output_active));
+               }
                // This InsetRef has already been taken care of in InsetLabel::addToToc().
                return;
        }
 
        // It seems that this reference does not point to any valid label.
-
        broken_ = true;
+       setBroken(broken_);
        shared_ptr<Toc> toc = backend.toc("label");
        toc->push_back(TocItem(cpit, 0, screenLabel(), output_active));
+       shared_ptr<Toc> toc2 = backend.toc("brokenrefs");
+       toc2->push_back(TocItem(cpit, 0, screenLabel(), output_active));
 }
 
 
@@ -533,6 +560,11 @@ InsetRef::type_info const InsetRef::types[] = {
 
 docstring InsetRef::getTOCString() const
 {
+       docstring const & label = getParam("reference");
+       if (buffer().insetLabel(label))
+               broken_ = !buffer().activeLabel(label) && active_;
+       else 
+               broken_ = active_;
        return tooltip_.empty() ? screenLabel() : tooltip_;
 }