From: Abdelrazak Younes Date: Mon, 14 Jul 2008 07:16:00 +0000 (+0000) Subject: safeguards: X-Git-Tag: 1.6.10~4087 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=647ac4a2219a7df07a565298057d151a2ae045a0;p=features.git safeguards: - move Previews singleton to LyX - LyX.cpp: set singleton to zero at destruction. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@25594 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 6173666b61..84341b3920 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -286,7 +286,7 @@ Buffer::~Buffer() } // Remove any previewed LaTeX snippets associated with this buffer. - graphics::Previews::get().removeLoader(*this); + thePreviews()->removeLoader(*this); delete d; } @@ -2374,11 +2374,12 @@ bool Buffer::doExport(string const & format, bool put_in_tempdir, string const error_type = (format == "program") ? "Build" : bufferFormat(); + ErrorList & error_list = d->errorLists[error_type]; string const ext = formats.extension(format); FileName const tmp_result_file(changeExtension(filename, ext)); bool const success = theConverters().convert(this, FileName(filename), tmp_result_file, FileName(absFileName()), backend_format, format, - errorList(error_type)); + error_list); // Emit the signal to show the error list. if (format != backend_format) errors(error_type); diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 009017c2ae..2f41a497a2 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -282,7 +282,7 @@ BufferView::BufferView(Buffer & buf) d->cursor_.setCurrentFont(); if (graphics::Previews::status() != LyXRC::PREVIEW_OFF) - graphics::Previews::get().generateBufferPreviews(buffer_); + thePreviews()->generateBufferPreviews(buffer_); } diff --git a/src/LyX.cpp b/src/LyX.cpp index 5ff73f64ea..fcf0750ef9 100644 --- a/src/LyX.cpp +++ b/src/LyX.cpp @@ -44,6 +44,8 @@ #include "frontends/alert.h" #include "frontends/Application.h" +#include "graphics/Previews.h" + #include "support/lassert.h" #include "support/debug.h" #include "support/environment.h" @@ -164,6 +166,9 @@ struct LyX::Impl bool first_start; /// the parsed command line batch command if any vector batch_commands; + + /// + graphics::Previews preview_; }; /// @@ -178,6 +183,7 @@ frontend::Application * theApp() LyX::~LyX() { + singleton_ = 0; delete pimpl_; } @@ -1310,4 +1316,10 @@ Messages & getGuiMessages() return LyX::ref().getGuiMessages(); } + +graphics::Previews * thePreviews() +{ + return singleton_ ? 0 : &singleton_->pimpl_->preview_; +} + } // namespace lyx diff --git a/src/LyX.h b/src/LyX.h index 2a83af88c8..9170cc3182 100644 --- a/src/LyX.h +++ b/src/LyX.h @@ -38,6 +38,10 @@ class Application; class LyXView; } +namespace graphics { +class Previews; +} + /// initial startup class LyX { public: @@ -160,6 +164,7 @@ private: friend Movers & theSystemMovers(); friend frontend::Application * theApp(); friend KeyMap & theTopLevelKeymap(); + friend graphics::Previews * thePreviews(); }; } // namespace lyx diff --git a/src/graphics/Previews.cpp b/src/graphics/Previews.cpp index c513d58e59..aeadfbec86 100644 --- a/src/graphics/Previews.cpp +++ b/src/graphics/Previews.cpp @@ -31,42 +31,26 @@ LyXRC_PreviewStatus Previews::status() } -Previews & Previews::get() -{ - static Previews singleton; - return singleton; +namespace { +typedef boost::shared_ptr PreviewLoaderPtr; +/// +typedef map CacheType; +/// +static CacheType preview_cache_; } -class Previews::Impl { -public: - /// - typedef boost::shared_ptr PreviewLoaderPtr; - /// - typedef map CacheType; - /// - CacheType cache; -}; - - Previews::Previews() - : pimpl_(new Impl) {} -Previews::~Previews() -{ - delete pimpl_; -} - - PreviewLoader & Previews::loader(Buffer const & buffer) const { - Impl::CacheType::iterator it = pimpl_->cache.find(&buffer); + CacheType::iterator it = preview_cache_.find(&buffer); - if (it == pimpl_->cache.end()) { - Impl::PreviewLoaderPtr ptr(new PreviewLoader(buffer)); - pimpl_->cache[&buffer] = ptr; + if (it == preview_cache_.end()) { + PreviewLoaderPtr ptr(new PreviewLoader(buffer)); + preview_cache_[&buffer] = ptr; return *ptr.get(); } @@ -76,10 +60,10 @@ PreviewLoader & Previews::loader(Buffer const & buffer) const void Previews::removeLoader(Buffer const & buffer) const { - Impl::CacheType::iterator it = pimpl_->cache.find(&buffer); + CacheType::iterator it = preview_cache_.find(&buffer); - if (it != pimpl_->cache.end()) - pimpl_->cache.erase(it); + if (it != preview_cache_.end()) + preview_cache_.erase(it); } diff --git a/src/graphics/Previews.h b/src/graphics/Previews.h index 0a50e29e36..4d58e1c00c 100644 --- a/src/graphics/Previews.h +++ b/src/graphics/Previews.h @@ -29,9 +29,6 @@ public: /// a wrapper for lyxrc.preview static LyXRC_PreviewStatus status(); - /// This is a singleton class. Get the instance. - static Previews & get(); - /** Returns the PreviewLoader for this buffer. * Used by individual insets to update their own preview. */ @@ -47,6 +44,7 @@ public: void generateBufferPreviews(Buffer const & buffer) const; private: + friend class LyX; /// noncopyable Previews(Previews const &); void operator=(Previews const &); @@ -55,15 +53,14 @@ private: * are instantiated. */ Previews(); - ~Previews(); - - /// Use the Pimpl idiom to hide the internals. - class Impl; - /// The pointer never changes although *pimpl_'s contents may. - Impl * const pimpl_; }; } // namespace graphics + +/// This is a singleton class. Get the instance. +/// Implemented in LyX.cpp. +graphics::Previews * thePreviews(); + } // namespace lyx #endif // PREVIEWS_H