2002-07-05 21:24:15 +00:00
|
|
|
/*
|
|
|
|
* \file Previews.C
|
|
|
|
* Copyright 2002 the LyX Team
|
|
|
|
* Read the file COPYING
|
|
|
|
*
|
2002-07-15 10:19:45 +00:00
|
|
|
* \author Angus Leeming <leeming@lyx.org>
|
2002-07-05 21:24:15 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "Previews.h"
|
|
|
|
#include "PreviewLoader.h"
|
|
|
|
|
|
|
|
#include "buffer.h"
|
|
|
|
#include "lyxrc.h"
|
|
|
|
|
|
|
|
#include "insets/inset.h"
|
|
|
|
|
|
|
|
#include "support/LAssert.h"
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
namespace grfx {
|
|
|
|
|
|
|
|
bool Previews::activated()
|
|
|
|
{
|
|
|
|
return lyxrc.preview;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Previews & Previews::get()
|
|
|
|
{
|
|
|
|
static Previews singleton;
|
|
|
|
return singleton;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct Previews::Impl {
|
|
|
|
///
|
|
|
|
typedef boost::shared_ptr<PreviewLoader> PreviewLoaderPtr;
|
|
|
|
///
|
2002-07-16 18:10:51 +00:00
|
|
|
typedef std::map<Buffer const *, PreviewLoaderPtr> CacheType;
|
2002-07-05 21:24:15 +00:00
|
|
|
///
|
|
|
|
CacheType cache;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Previews::Previews()
|
|
|
|
: pimpl_(new Impl())
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
Previews::~Previews()
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
2002-07-16 18:10:51 +00:00
|
|
|
PreviewLoader & Previews::loader(Buffer const * buffer)
|
2002-07-05 21:24:15 +00:00
|
|
|
{
|
|
|
|
lyx::Assert(buffer);
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
2002-07-16 18:10:51 +00:00
|
|
|
|
2002-07-05 21:24:15 +00:00
|
|
|
return *it->second.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-16 18:10:51 +00:00
|
|
|
void Previews::removeLoader(Buffer const * buffer)
|
2002-07-05 21:24:15 +00:00
|
|
|
{
|
|
|
|
if (!buffer)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Impl::CacheType::iterator it = pimpl_->cache.find(buffer);
|
|
|
|
|
|
|
|
if (it != pimpl_->cache.end())
|
|
|
|
pimpl_->cache.erase(it);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-16 18:10:51 +00:00
|
|
|
void Previews::generateBufferPreviews(Buffer const & buffer)
|
2002-07-05 21:24:15 +00:00
|
|
|
{
|
2002-07-16 18:10:51 +00:00
|
|
|
PreviewLoader & ploader = loader(&buffer);
|
2002-07-05 21:24:15 +00:00
|
|
|
|
2002-07-16 18:10:51 +00:00
|
|
|
Buffer::inset_iterator it = buffer.inset_const_iterator_begin();
|
|
|
|
Buffer::inset_iterator end = buffer.inset_const_iterator_end();
|
2002-07-05 21:24:15 +00:00
|
|
|
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
if ((*it)->lyxCode() == Inset::MATH_CODE) {
|
|
|
|
(*it)->generatePreview(ploader);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ploader.startLoading();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace grfx
|