2002-09-05 11:31:30 +00:00
|
|
|
/**
|
2002-07-05 21:24:15 +00:00
|
|
|
* \file Previews.C
|
2002-09-05 15:14:23 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-07-05 21:24:15 +00:00
|
|
|
*
|
2002-12-01 22:59:25 +00:00
|
|
|
* \author Angus Leeming
|
2002-09-05 11:31:30 +00:00
|
|
|
*
|
2002-09-05 14:10:50 +00:00
|
|
|
* Full author contact details are available in file CREDITS
|
2002-07-05 21:24:15 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "Previews.h"
|
|
|
|
#include "PreviewLoader.h"
|
|
|
|
|
|
|
|
#include "buffer.h"
|
|
|
|
#include "lyxrc.h"
|
|
|
|
|
|
|
|
#include "insets/inset.h"
|
|
|
|
|
|
|
|
#include "support/LAssert.h"
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
using namespace lyx::support;
|
|
|
|
|
2002-07-05 21:24:15 +00:00
|
|
|
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-17 16:56:42 +00:00
|
|
|
PreviewLoader & Previews::loader(Buffer const * buffer) const
|
2002-07-05 21:24:15 +00:00
|
|
|
{
|
2003-06-30 23:56:22 +00:00
|
|
|
Assert(buffer);
|
2002-07-05 21:24:15 +00:00
|
|
|
|
|
|
|
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-17 16:56:42 +00:00
|
|
|
void Previews::removeLoader(Buffer const * buffer) const
|
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-17 16:56:42 +00:00
|
|
|
void Previews::generateBufferPreviews(Buffer const & buffer) const
|
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
|
|
|
|
2002-08-20 17:18:21 +00:00
|
|
|
for (; it != end; ++it)
|
|
|
|
it->addPreview(ploader);
|
2002-07-05 21:24:15 +00:00
|
|
|
|
|
|
|
ploader.startLoading();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace grfx
|