3 * Copyright 2002 the LyX Team
4 * Read the file COPYING
6 * \author Angus Leeming <leeming@lyx.org>
12 #pragma implementation
16 #include "PreviewLoader.h"
21 #include "insets/inset.h"
23 #include "support/LAssert.h"
29 bool Previews::activated()
35 Previews & Previews::get()
37 static Previews singleton;
42 struct Previews::Impl {
44 typedef boost::shared_ptr<PreviewLoader> PreviewLoaderPtr;
46 typedef std::map<Buffer *, PreviewLoaderPtr> CacheType;
61 PreviewLoader & Previews::loader(Buffer * buffer)
65 Impl::CacheType::iterator it = pimpl_->cache.find(buffer);
67 if (it == pimpl_->cache.end()) {
68 Impl::PreviewLoaderPtr ptr(new PreviewLoader(*buffer));
69 pimpl_->cache[buffer] = ptr;
73 return *it->second.get();
77 void Previews::removeLoader(Buffer * buffer)
82 Impl::CacheType::iterator it = pimpl_->cache.find(buffer);
84 if (it != pimpl_->cache.end())
85 pimpl_->cache.erase(it);
89 void Previews::generateBufferPreviews(Buffer * buffer)
91 if (!buffer || !lyxrc.preview)
94 PreviewLoader & ploader = loader(buffer);
96 Buffer::inset_iterator it = buffer->inset_const_iterator_begin();
97 Buffer::inset_iterator end = buffer->inset_const_iterator_end();
99 for (; it != end; ++it) {
100 if ((*it)->lyxCode() == Inset::MATH_CODE) {
101 (*it)->generatePreview(ploader);
105 ploader.startLoading();