2002-09-05 11:31:30 +00:00
|
|
|
/**
|
2007-04-25 03:01:35 +00:00
|
|
|
* \file Previews.cpp
|
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
|
|
|
*
|
2003-08-23 00:17:00 +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"
|
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Buffer.h"
|
|
|
|
#include "InsetIterator.h"
|
|
|
|
#include "LyXRC.h"
|
|
|
|
#include "Paragraph.h"
|
2002-07-05 21:24:15 +00:00
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
#include "insets/Inset.h"
|
2003-09-09 11:24:33 +00:00
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
|
2003-09-04 00:29:22 +00:00
|
|
|
namespace lyx {
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2003-07-04 08:23:23 +00:00
|
|
|
namespace graphics {
|
2002-07-05 21:24:15 +00:00
|
|
|
|
2004-04-19 13:31:17 +00:00
|
|
|
LyXRC_PreviewStatus Previews::status()
|
2002-07-05 21:24:15 +00:00
|
|
|
{
|
|
|
|
return lyxrc.preview;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Previews & Previews::get()
|
|
|
|
{
|
|
|
|
static Previews singleton;
|
|
|
|
return singleton;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-19 15:03:31 +00:00
|
|
|
class Previews::Impl {
|
|
|
|
public:
|
2002-07-05 21:24:15 +00:00
|
|
|
///
|
|
|
|
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()
|
2003-09-21 16:02:54 +00:00
|
|
|
: pimpl_(new Impl)
|
2002-07-05 21:24:15 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
Previews::~Previews()
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
PreviewLoader & Previews::loader(Buffer const & buffer) const
|
2002-07-05 21:24:15 +00:00
|
|
|
{
|
2003-08-28 07:41:31 +00:00
|
|
|
Impl::CacheType::iterator it = pimpl_->cache.find(&buffer);
|
2002-07-05 21:24:15 +00:00
|
|
|
|
|
|
|
if (it == pimpl_->cache.end()) {
|
2003-08-28 07:41:31 +00:00
|
|
|
Impl::PreviewLoaderPtr ptr(new PreviewLoader(buffer));
|
|
|
|
pimpl_->cache[&buffer] = ptr;
|
2002-07-05 21:24:15 +00:00
|
|
|
return *ptr.get();
|
|
|
|
}
|
2002-07-16 18:10:51 +00:00
|
|
|
|
2002-07-05 21:24:15 +00:00
|
|
|
return *it->second.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
void Previews::removeLoader(Buffer const & buffer) const
|
2002-07-05 21:24:15 +00:00
|
|
|
{
|
2003-08-28 07:41:31 +00:00
|
|
|
Impl::CacheType::iterator it = pimpl_->cache.find(&buffer);
|
2002-07-05 21:24:15 +00:00
|
|
|
|
|
|
|
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
|
|
|
{
|
2003-08-28 07:41:31 +00:00
|
|
|
PreviewLoader & ploader = loader(buffer);
|
2002-07-05 21:24:15 +00:00
|
|
|
|
2004-04-13 13:10:33 +00:00
|
|
|
InsetBase & inset = buffer.inset();
|
|
|
|
InsetIterator it = inset_iterator_begin(inset);
|
|
|
|
InsetIterator const end = inset_iterator_end(inset);
|
|
|
|
|
|
|
|
for (; it != end; ++it)
|
2002-08-20 17:18:21 +00:00
|
|
|
it->addPreview(ploader);
|
2002-07-05 21:24:15 +00:00
|
|
|
|
|
|
|
ploader.startLoading();
|
|
|
|
}
|
|
|
|
|
2003-07-04 08:23:23 +00:00
|
|
|
} // namespace graphics
|
|
|
|
} // namespace lyx
|