lyx_mirror/src/graphics/Previews.C
Angus Leeming d91ffd8d78 Previews for \input insets.
Refactor code common to InsetInclude and InsetFormula into a new
PreviewedInset class.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4830 a592a061-630c-0410-9148-cb99ea01b6c8
2002-08-01 17:28:59 +00:00

104 lines
1.6 KiB
C

/*
* \file Previews.C
* Copyright 2002 the LyX Team
* Read the file COPYING
*
* \author Angus Leeming <leeming@lyx.org>
*/
#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;
///
typedef std::map<Buffer const *, PreviewLoaderPtr> CacheType;
///
CacheType cache;
};
Previews::Previews()
: pimpl_(new Impl())
{}
Previews::~Previews()
{}
PreviewLoader & Previews::loader(Buffer const * buffer) const
{
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();
}
return *it->second.get();
}
void Previews::removeLoader(Buffer const * buffer) const
{
if (!buffer)
return;
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);
Buffer::inset_iterator it = buffer.inset_const_iterator_begin();
Buffer::inset_iterator end = buffer.inset_const_iterator_end();
for (; it != end; ++it) {
(*it)->addPreview(ploader);
}
ploader.startLoading();
}
} // namespace grfx