From 2f78698fbdfa762edc46f220ae397ede0e3d201c Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Wed, 21 Jul 2010 21:51:33 +0000 Subject: [PATCH] First step towards fixing some issues noted by Vincent. We record in the Buffer whether we are exporting or not, rather than rely upon isClone(), which could be adapted to other purposes. And, of course, someone might choose locally to disable cloning.... git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@34999 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Buffer.cpp | 40 +++++++++++++++++++++++++++++++--- src/Buffer.h | 4 ++++ src/graphics/PreviewLoader.cpp | 2 +- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 1cd24493fc..392efd762a 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -157,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; @@ -289,7 +289,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; @@ -322,7 +324,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(); @@ -3260,10 +3262,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(¶ms().encoding()); runparams.flavor = OutputParams::LATEX; @@ -3460,6 +3493,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)) diff --git a/src/Buffer.h b/src/Buffer.h index 811727e5a8..dafb61ec88 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -525,6 +525,10 @@ public: std::vector exportableFormats(bool only_viewable) const; /// bool isExportableFormat(std::string const & format) const; + /// mark the buffer as busy exporting something, or not + void setExportStatus(bool e) const; + /// + bool isExporting() const; /// typedef std::vector > References; diff --git a/src/graphics/PreviewLoader.cpp b/src/graphics/PreviewLoader.cpp index 8bec4cc922..aa54254a67 100644 --- a/src/graphics/PreviewLoader.cpp +++ b/src/graphics/PreviewLoader.cpp @@ -588,7 +588,7 @@ void PreviewLoader::Impl::startLoading(bool wait) // For XHTML image export, we need to control the background // color here. - ColorCode bg = buffer_.isClone() + ColorCode bg = buffer_.isExporting() ? Color_white : PreviewLoader::backgroundColor(); // The conversion command. ostringstream cs;