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
This commit is contained in:
Richard Heck 2010-07-21 21:51:33 +00:00
parent c12dea0182
commit 2f78698fbd
3 changed files with 42 additions and 4 deletions

View File

@ -289,6 +289,8 @@ public:
/// If non zero, this buffer is a clone of existing buffer \p cloned_buffer_ /// If non zero, this buffer is a clone of existing buffer \p cloned_buffer_
/// This one is useful for preview detached in a thread. /// This one is useful for preview detached in a thread.
Buffer const * cloned_buffer_; Buffer const * cloned_buffer_;
/// are we in the process of exporting this buffer?
mutable bool doing_export;
private: private:
/// So we can force access via the accessors. /// So we can force access via the accessors.
@ -322,7 +324,7 @@ Buffer::Impl::Impl(Buffer * owner, FileName const & file, bool readonly_,
read_only(readonly_), filename(file), file_fully_loaded(false), read_only(readonly_), filename(file), file_fully_loaded(false),
toc_backend(owner), macro_lock(false), timestamp_(0), toc_backend(owner), macro_lock(false), timestamp_(0),
checksum_(0), wa_(0), gui_(0), undo_(*owner), bibinfo_cache_valid_(false), 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_) { if (!cloned_buffer_) {
temppath = createBufferTmpDir(); 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 Buffer::doExport(string const & format, bool put_in_tempdir,
bool includeall, string & result_file) const bool includeall, string & result_file) const
{ {
MarkAsExporting exporting(this);
string backend_format; string backend_format;
OutputParams runparams(&params().encoding()); OutputParams runparams(&params().encoding());
runparams.flavor = OutputParams::LATEX; 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 bool Buffer::preview(string const & format, bool includeall) const
{ {
MarkAsExporting exporting(this);
string result_file; string result_file;
// (1) export with all included children (omit \includeonly) // (1) export with all included children (omit \includeonly)
if (includeall && !doExport(format, true, true)) if (includeall && !doExport(format, true, true))

View File

@ -525,6 +525,10 @@ public:
std::vector<Format const *> exportableFormats(bool only_viewable) const; std::vector<Format const *> exportableFormats(bool only_viewable) const;
/// ///
bool isExportableFormat(std::string const & format) 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<std::pair<Inset *, ParIterator> > References; typedef std::vector<std::pair<Inset *, ParIterator> > References;

View File

@ -588,7 +588,7 @@ void PreviewLoader::Impl::startLoading(bool wait)
// For XHTML image export, we need to control the background // For XHTML image export, we need to control the background
// color here. // color here.
ColorCode bg = buffer_.isClone() ColorCode bg = buffer_.isExporting()
? Color_white : PreviewLoader::backgroundColor(); ? Color_white : PreviewLoader::backgroundColor();
// The conversion command. // The conversion command.
ostringstream cs; ostringstream cs;