]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetInclude.cpp
Fix bug #8782.
[lyx.git] / src / insets / InsetInclude.cpp
index fe0c1edae48e374b5d87df5d80093f28b6f1bfc9..1031f3a557ac66f92c9b6f08048123f2b424d147 100644 (file)
@@ -31,7 +31,6 @@
 #include "LayoutFile.h"
 #include "LayoutModuleList.h"
 #include "LyX.h"
-#include "LyXRC.h"
 #include "Lexer.h"
 #include "MetricsInfo.h"
 #include "output_plaintext.h"
@@ -61,6 +60,7 @@
 #include "support/lassert.h"
 #include "support/lstrings.h" // contains
 #include "support/lyxalgo.h"
+#include "support/mutex.h"
 
 #include "support/bind.h"
 
@@ -77,6 +77,8 @@ namespace {
 docstring const uniqueID()
 {
        static unsigned int seed = 1000;
+       static Mutex mutex;
+       Mutex::Locker lock(&mutex);
        return "file" + convert<docstring>(++seed);
 }
 
@@ -125,7 +127,7 @@ bool isVerbatim(InsetCommandParams const & params)
 bool isInputOrInclude(InsetCommandParams const & params)
 {
        Types const t = type(params);
-       return t == INPUT || t == INCLUDE;
+       return t == INPUT || t == INCLUDE;
 }
 
 
@@ -407,7 +409,9 @@ Buffer * InsetInclude::getChildBuffer() const
 {
        Buffer * childBuffer = loadIfNeeded(); 
 
-       // FIXME: recursive includes
+       // FIXME RECURSIVE INCLUDE
+       // This isn't sufficient, as the inclusion could be downstream.
+       // But it'll have to do for now.
        return (childBuffer == &buffer()) ? 0 : childBuffer;
 }
 
@@ -551,7 +555,8 @@ void InsetInclude::latex(otexstream & os, OutputParams const & runparams) const
                        from_utf8(incfile), true);
        }
 
-       FileName const writefile(makeAbsPath(mangled, masterBuffer->temppath()));
+       FileName const writefile(makeAbsPath(mangled, runparams.for_preview ?
+                                                buffer().temppath() : masterBuffer->temppath()));
 
        LYXERR(Debug::LATEX, "incfile:" << incfile);
        LYXERR(Debug::LATEX, "exportfile:" << exportfile);
@@ -683,9 +688,9 @@ void InsetInclude::latex(otexstream & os, OutputParams const & runparams) const
                // and language.
                Encoding const * const oldEnc = runparams.encoding;
                Language const * const oldLang = runparams.master_language;
-               // If the master has full unicode flavor (XeTeX, LuaTeX),
+               // If the master uses non-TeX fonts (XeTeX, LuaTeX),
                // the children must be encoded in plain utf8!
-               runparams.encoding = runparams.isFullUnicode() ?
+               runparams.encoding = masterBuffer->params().useNonTeXFonts ?
                        encodings.fromLyXName("utf8-plain")
                        : &tmp->params().encoding();
                runparams.master_language = buffer().params().language;
@@ -972,6 +977,11 @@ void InsetInclude::collectBibKeys(InsetIterator const & /*di*/) const
        Buffer * child = loadIfNeeded();
        if (!child)
                return;
+       // FIXME RECURSIVE INCLUDE
+       // This isn't sufficient, as the inclusion could be downstream.
+       // But it'll have to do for now.
+       if (child == &buffer())
+               return;
        child->collectBibKeys();
 }
 
@@ -981,7 +991,7 @@ void InsetInclude::metrics(MetricsInfo & mi, Dimension & dim) const
        LBUFERR(mi.base.bv);
 
        bool use_preview = false;
-       if (RenderPreview::status() != LyXRC::PREVIEW_OFF) {
+       if (RenderPreview::previewText()) {
                graphics::PreviewImage const * pimage =
                        preview_->getPreviewImage(mi.base.bv->buffer());
                use_preview = pimage && pimage->image();
@@ -1007,7 +1017,7 @@ void InsetInclude::draw(PainterInfo & pi, int x, int y) const
        LBUFERR(pi.base.bv);
 
        bool use_preview = false;
-       if (RenderPreview::status() != LyXRC::PREVIEW_OFF) {
+       if (RenderPreview::previewText()) {
                graphics::PreviewImage const * pimage =
                        preview_->getPreviewImage(pi.base.bv->buffer());
                use_preview = pimage && pimage->image();
@@ -1020,6 +1030,12 @@ void InsetInclude::draw(PainterInfo & pi, int x, int y) const
 }
 
 
+void InsetInclude::write(ostream & os) const
+{
+       params().Write(os, &buffer());
+}
+
+
 string InsetInclude::contextMenuName() const
 {
        return "context-include";
@@ -1051,7 +1067,7 @@ void InsetInclude::fileChanged() const
                return;
 
        preview_->removePreview(*buffer);
-       add_preview(*preview_.get(), *this, *buffer);
+       add_preview(*preview_, *this, *buffer);
        preview_->startLoading(*buffer);
 }
 
@@ -1076,6 +1092,7 @@ docstring latexString(InsetInclude const & inset)
        // by latex() anyway.
        OutputParams runparams(0);
        runparams.flavor = OutputParams::LATEX;
+       runparams.for_preview = true;
        inset.latex(os, runparams);
 
        return ods.str();
@@ -1086,8 +1103,7 @@ void add_preview(RenderMonitoredPreview & renderer, InsetInclude const & inset,
                 Buffer const & buffer)
 {
        InsetCommandParams const & params = inset.params();
-       if (RenderPreview::status() != LyXRC::PREVIEW_OFF &&
-           preview_wanted(params, buffer)) {
+       if (RenderPreview::previewText() && preview_wanted(params, buffer)) {
                renderer.setAbsFile(includedFileName(buffer, params));
                docstring const snippet = latexString(inset);
                renderer.addPreview(snippet, buffer);
@@ -1109,41 +1125,42 @@ void InsetInclude::addPreview(DocIterator const & /*inset_pos*/,
 }
 
 
-void InsetInclude::addToToc(DocIterator const & cpit, bool output_active) const
+void InsetInclude::addToToc(DocIterator const & cpit, bool output_active,
+                                                       UpdateType utype) const
 {
        TocBackend & backend = buffer().tocBackend();
 
        if (isListings(params())) {
                if (label_)
-                       label_->addToToc(cpit, output_active);
+                       label_->addToToc(cpit, output_active, utype);
 
                InsetListingsParams p(to_utf8(params()["lstparams"]));
                string caption = p.getParamValue("caption");
                if (caption.empty())
                        return;
-               Toc & toc = backend.toc("listing");
-               docstring str = convert<docstring>(toc.size() + 1)
+               shared_ptr<Toc> toc = backend.toc("listing");
+               docstring str = convert<docstring>(toc->size() + 1)
                        + ". " +  from_utf8(caption);
                DocIterator pit = cpit;
-               toc.push_back(TocItem(pit, 0, str, output_active));
-               return;
-       }
-       Buffer const * const childbuffer = getChildBuffer();
-       if (!childbuffer)
-               return;
+               toc->push_back(TocItem(pit, 0, str, output_active));
+       } else {
+               Buffer const * const childbuffer = getChildBuffer();
+               if (!childbuffer)
+                       return;
 
-       Toc & toc = backend.toc("child");
-       docstring str = childbuffer->fileName().displayName();
-       toc.push_back(TocItem(cpit, 0, str, output_active));
-
-       TocList & toclist = backend.tocs();
-       childbuffer->tocBackend().update(output_active);
-       TocList const & childtoclist = childbuffer->tocBackend().tocs();
-       TocList::const_iterator it = childtoclist.begin();
-       TocList::const_iterator const end = childtoclist.end();
-       for(; it != end; ++it)
-               toclist[it->first].insert(toclist[it->first].end(),
-                       it->second.begin(), it->second.end());
+               shared_ptr<Toc> toc = backend.toc("child");
+               docstring str = childbuffer->fileName().displayName();
+               toc->push_back(TocItem(cpit, 0, str, output_active));
+
+               childbuffer->tocBackend().update(output_active, utype);
+               TocList const & childtoclist = childbuffer->tocBackend().tocs();
+               TocList::const_iterator it = childtoclist.begin();
+               TocList::const_iterator const end = childtoclist.end();
+               for(; it != end; ++it) {
+                       shared_ptr<Toc> toc = backend.toc(it->first);
+                       toc->insert(toc->end(), it->second->begin(), it->second->end());
+               }
+       }
 }