3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
8 * Full author contact details are available in file CREDITS.
14 #include "PreviewLoader.h"
17 #include "InsetIterator.h"
20 #include "insets/Inset.h"
28 LyXRC_PreviewStatus Previews::status()
34 Previews & Previews::get()
36 static Previews singleton;
41 class Previews::Impl {
44 typedef boost::shared_ptr<PreviewLoader> PreviewLoaderPtr;
46 typedef map<Buffer const *, PreviewLoaderPtr> CacheType;
63 PreviewLoader & Previews::loader(Buffer const & buffer) const
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 const & buffer) const
79 Impl::CacheType::iterator it = pimpl_->cache.find(&buffer);
81 if (it != pimpl_->cache.end())
82 pimpl_->cache.erase(it);
86 void Previews::generateBufferPreviews(Buffer const & buffer) const
88 PreviewLoader & ploader = loader(buffer);
90 Inset & inset = buffer.inset();
91 InsetIterator it = inset_iterator_begin(inset);
92 InsetIterator const end = inset_iterator_end(inset);
94 for (; it != end; ++it)
95 it->addPreview(ploader);
97 ploader.startLoading();
100 } // namespace graphics