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"
|
2002-07-05 21:24:15 +00:00
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
#include "insets/Inset.h"
|
2003-09-09 11:24:33 +00:00
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
using namespace std;
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-14 07:16:00 +00:00
|
|
|
namespace {
|
|
|
|
typedef boost::shared_ptr<PreviewLoader> PreviewLoaderPtr;
|
|
|
|
///
|
2008-08-13 21:39:59 +00:00
|
|
|
typedef map<Buffer const *, PreviewLoaderPtr> LyxCacheType;
|
2008-07-14 07:16:00 +00:00
|
|
|
///
|
2008-08-13 21:39:59 +00:00
|
|
|
static LyxCacheType preview_cache_;
|
2002-07-05 21:24:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
PreviewLoader & Previews::loader(Buffer const & buffer) const
|
2002-07-05 21:24:15 +00:00
|
|
|
{
|
2008-08-13 21:39:59 +00:00
|
|
|
LyxCacheType::iterator it = preview_cache_.find(&buffer);
|
2002-07-05 21:24:15 +00:00
|
|
|
|
2008-07-14 07:16:00 +00:00
|
|
|
if (it == preview_cache_.end()) {
|
|
|
|
PreviewLoaderPtr ptr(new PreviewLoader(buffer));
|
|
|
|
preview_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
|
|
|
{
|
2008-08-13 21:39:59 +00:00
|
|
|
LyxCacheType::iterator it = preview_cache_.find(&buffer);
|
2002-07-05 21:24:15 +00:00
|
|
|
|
2008-07-14 07:16:00 +00:00
|
|
|
if (it != preview_cache_.end())
|
|
|
|
preview_cache_.erase(it);
|
2002-07-05 21:24:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
Inset & inset = buffer.inset();
|
2004-04-13 13:10:33 +00:00
|
|
|
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
|