]> git.lyx.org Git - features.git/commitdiff
safeguards:
authorAbdelrazak Younes <younes@lyx.org>
Mon, 14 Jul 2008 07:16:00 +0000 (07:16 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Mon, 14 Jul 2008 07:16:00 +0000 (07:16 +0000)
- 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

src/Buffer.cpp
src/BufferView.cpp
src/LyX.cpp
src/LyX.h
src/graphics/Previews.cpp
src/graphics/Previews.h

index 6173666b61f5aba803312caf46eba73dc5427353..84341b3920e384da60e2e1f20bfeceae310f6ae3 100644 (file)
@@ -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);
index 009017c2ae7d1f0b5571788f41de1801a0c41340..2f41a497a2989e0921f5f904b93f705a1ea128b8 100644 (file)
@@ -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_);
 }
 
 
index 5ff73f64eaf9a7b92987944b6c9627c3377d7f03..fcf0750ef950dd4a656d969ec6f2ea4eeddff562 100644 (file)
@@ -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<string> 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
index 2a83af88c873b7132b79f0cc5da0ed118ed2ad1b..9170cc31821444f9743efaaaed13c4a681c8c26d 100644 (file)
--- 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
index c513d58e59d59d3ecaa5d1107b88825f89bdfb7d..aeadfbec860d304df949c6d4f1e249ba1b26f522 100644 (file)
@@ -31,42 +31,26 @@ LyXRC_PreviewStatus Previews::status()
 }
 
 
-Previews & Previews::get()
-{
-       static Previews singleton;
-       return singleton;
+namespace {
+typedef boost::shared_ptr<PreviewLoader> PreviewLoaderPtr;
+///
+typedef map<Buffer const *, PreviewLoaderPtr> CacheType;
+///
+static CacheType preview_cache_;
 }
 
 
-class Previews::Impl {
-public:
-       ///
-       typedef boost::shared_ptr<PreviewLoader> PreviewLoaderPtr;
-       ///
-       typedef map<Buffer const *, PreviewLoaderPtr> 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);
 }
 
 
index 0a50e29e36b3c64d679eedb90b053f1bfe99464f..4d58e1c00cd6dd81a22918681b73509221fa489c 100644 (file)
@@ -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