mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-11 13:46:43 +00:00
52ed731842
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8544 a592a061-630c-0410-9148-cb99ea01b6c8
94 lines
1.6 KiB
C
94 lines
1.6 KiB
C
/**
|
|
* \file Previews.C
|
|
* This file is part of LyX, the document processor.
|
|
* Licence details can be found in the file COPYING.
|
|
*
|
|
* \author Angus Leeming
|
|
*
|
|
* Full author contact details are available in file CREDITS.
|
|
*/
|
|
|
|
#include <config.h>
|
|
|
|
#include "Previews.h"
|
|
#include "PreviewLoader.h"
|
|
|
|
#include "buffer.h"
|
|
#include "insetiterator.h"
|
|
#include "lyxrc.h"
|
|
#include "paragraph.h"
|
|
|
|
#include "insets/inset.h"
|
|
|
|
|
|
namespace lyx {
|
|
namespace graphics {
|
|
|
|
bool Previews::activated()
|
|
{
|
|
return lyxrc.preview;
|
|
}
|
|
|
|
|
|
Previews & Previews::get()
|
|
{
|
|
static Previews singleton;
|
|
return singleton;
|
|
}
|
|
|
|
|
|
struct Previews::Impl {
|
|
///
|
|
typedef boost::shared_ptr<PreviewLoader> PreviewLoaderPtr;
|
|
///
|
|
typedef std::map<Buffer const *, PreviewLoaderPtr> CacheType;
|
|
///
|
|
CacheType cache;
|
|
};
|
|
|
|
|
|
Previews::Previews()
|
|
: pimpl_(new Impl)
|
|
{}
|
|
|
|
|
|
Previews::~Previews()
|
|
{}
|
|
|
|
|
|
PreviewLoader & Previews::loader(Buffer const & buffer) const
|
|
{
|
|
Impl::CacheType::iterator it = pimpl_->cache.find(&buffer);
|
|
|
|
if (it == pimpl_->cache.end()) {
|
|
Impl::PreviewLoaderPtr ptr(new PreviewLoader(buffer));
|
|
pimpl_->cache[&buffer] = ptr;
|
|
return *ptr.get();
|
|
}
|
|
|
|
return *it->second.get();
|
|
}
|
|
|
|
|
|
void Previews::removeLoader(Buffer const & buffer) const
|
|
{
|
|
Impl::CacheType::iterator it = pimpl_->cache.find(&buffer);
|
|
|
|
if (it != pimpl_->cache.end())
|
|
pimpl_->cache.erase(it);
|
|
}
|
|
|
|
|
|
void Previews::generateBufferPreviews(Buffer const & buffer) const
|
|
{
|
|
PreviewLoader & ploader = loader(buffer);
|
|
|
|
for (InsetIterator it(buffer.inset()); it; ++it)
|
|
it->addPreview(ploader);
|
|
|
|
ploader.startLoading();
|
|
}
|
|
|
|
} // namespace graphics
|
|
} // namespace lyx
|