]> git.lyx.org Git - lyx.git/blobdiff - src/Buffer.cpp
Partially revert r34995, which broke math output. Not sure why yet....
[lyx.git] / src / Buffer.cpp
index 78ca6dd038f19756dcd71727657517eb5bcf7d10..ba77061463c56c7176f0dbf685adb2d8172648e1 100644 (file)
@@ -72,6 +72,7 @@
 #include "insets/InsetInclude.h"
 #include "insets/InsetText.h"
 
+#include "mathed/InsetMathHull.h"
 #include "mathed/MacroTable.h"
 #include "mathed/MathMacroTemplate.h"
 #include "mathed/MathSupport.h"
@@ -156,7 +157,7 @@ public:
                }
                delete inset;
        }
-
+       
        /// search for macro in local (buffer) table or in children
        MacroData const * getBufferMacro(docstring const & name,
                DocIterator const & pos) const;
@@ -287,7 +288,9 @@ public:
        /// If non zero, this buffer is a clone of existing buffer \p cloned_buffer_
        /// This one is useful for preview detached in a thread.
        Buffer const * cloned_buffer_;
-
+       /// are we in the process of exporting this buffer?
+       mutable bool doing_export;
+       
 private:
        /// So we can force access via the accessors.
        mutable Buffer const * parent_buffer;
@@ -320,7 +323,7 @@ Buffer::Impl::Impl(Buffer * owner, FileName const & file, bool readonly_,
          read_only(readonly_), filename(file), file_fully_loaded(false),
          toc_backend(owner), macro_lock(false), timestamp_(0),
          checksum_(0), wa_(0), gui_(0), undo_(*owner), bibinfo_cache_valid_(false),
-         cloned_buffer_(cloned_buffer), parent_buffer(0)
+         cloned_buffer_(cloned_buffer), doing_export(false), parent_buffer(0)
 {
        if (!cloned_buffer_) {
                temppath = createBufferTmpDir();
@@ -403,7 +406,8 @@ Buffer::~Buffer()
        }
 
        // Remove any previewed LaTeX snippets associated with this buffer.
-       thePreviews().removeLoader(*this);
+       if (!isClone())
+               thePreviews().removeLoader(*this);
 
        delete d;
 }
@@ -2717,6 +2721,14 @@ void Buffer::Impl::updateMacros(DocIterator & it, DocIterator & scope)
                                continue;
                        }
 
+                       if (doing_export && iit->inset->asInsetMath()) {
+                               InsetMath * im = static_cast<InsetMath *>(iit->inset);
+                               if (im->asHullInset()) {
+                                       InsetMathHull * hull = static_cast<InsetMathHull *>(im);
+                                       hull->recordLocation(it);
+                               }
+                       }
+
                        if (iit->inset->lyxCode() != MATHMACRO_CODE)
                                continue;
 
@@ -3248,10 +3260,41 @@ string Buffer::getDefaultOutputFormat() const
 }
 
 
+namespace {
+       // helper class, to guarantee this gets reset properly
+       class MarkAsExporting   {
+       public:
+               MarkAsExporting(Buffer const * buf) : buf_(buf) 
+               {
+                       LASSERT(buf_, /* */);
+                       buf_->setExportStatus(true);
+               }
+               ~MarkAsExporting() 
+               {
+                       buf_->setExportStatus(false);
+               }
+       private:
+               Buffer const * const buf_;
+       };
+}
+
+
+void Buffer::setExportStatus(bool e) const
+{
+       d->doing_export = e;    
+}
+
+
+bool Buffer::isExporting() const
+{
+       return d->doing_export;
+}
+
 
 bool Buffer::doExport(string const & format, bool put_in_tempdir,
        bool includeall, string & result_file) const
 {
+       MarkAsExporting exporting(this);
        string backend_format;
        OutputParams runparams(&params().encoding());
        runparams.flavor = OutputParams::LATEX;
@@ -3448,6 +3491,7 @@ bool Buffer::doExport(string const & format, bool put_in_tempdir,
 
 bool Buffer::preview(string const & format, bool includeall) const
 {
+       MarkAsExporting exporting(this);
        string result_file;
        // (1) export with all included children (omit \includeonly)
        if (includeall && !doExport(format, true, true))