mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 05:16:21 +00:00
Graphics cleanup: get rid of Previews.{h,cpp}
The PreviewLoader is created directly by Buffer on demand. The PreviewLoader cache was complex and unneeded because there is one and only one PreviewLoader per Buffer. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@39276 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
034a03b0f5
commit
850e4d80c0
@ -77,12 +77,12 @@
|
||||
#include "mathed/MathMacroTemplate.h"
|
||||
#include "mathed/MathSupport.h"
|
||||
|
||||
#include "graphics/PreviewLoader.h"
|
||||
|
||||
#include "frontends/alert.h"
|
||||
#include "frontends/Delegates.h"
|
||||
#include "frontends/WorkAreaManager.h"
|
||||
|
||||
#include "graphics/Previews.h"
|
||||
|
||||
#include "support/lassert.h"
|
||||
#include "support/convert.h"
|
||||
#include "support/debug.h"
|
||||
@ -117,6 +117,7 @@
|
||||
|
||||
using namespace std;
|
||||
using namespace lyx::support;
|
||||
using namespace lyx::graphics;
|
||||
|
||||
namespace lyx {
|
||||
|
||||
@ -150,6 +151,7 @@ public:
|
||||
|
||||
~Impl()
|
||||
{
|
||||
delete preview_loader_;
|
||||
if (wa_) {
|
||||
wa_->closeAll();
|
||||
delete wa_;
|
||||
@ -267,6 +269,9 @@ public:
|
||||
/// our Text that should be wrapped in an InsetText
|
||||
InsetText * inset;
|
||||
|
||||
///
|
||||
PreviewLoader * preview_loader_;
|
||||
|
||||
/// This is here to force the test to be done whenever parent_buffer
|
||||
/// is accessed.
|
||||
Buffer const * parent() const {
|
||||
@ -331,10 +336,11 @@ Buffer::Impl::Impl(Buffer * owner, FileName const & file, bool readonly_,
|
||||
Buffer const * cloned_buffer)
|
||||
: owner_(owner), lyx_clean(true), bak_clean(true), unnamed(false),
|
||||
read_only(readonly_), filename(file), file_fully_loaded(false),
|
||||
toc_backend(owner), macro_lock(false), timestamp_(0),
|
||||
checksum_(0), wa_(0), gui_(0), undo_(*owner), bibinfo_cache_valid_(false),
|
||||
bibfile_cache_valid_(false), cite_labels_valid_(false),
|
||||
cloned_buffer_(cloned_buffer), doing_export(false), parent_buffer(0)
|
||||
toc_backend(owner), macro_lock(false), timestamp_(0), checksum_(0),
|
||||
wa_(0), gui_(0), undo_(*owner), preview_loader_(0),
|
||||
bibinfo_cache_valid_(false), bibfile_cache_valid_(false),
|
||||
cite_labels_valid_(false), cloned_buffer_(cloned_buffer),
|
||||
doing_export(false), parent_buffer(0)
|
||||
{
|
||||
if (!cloned_buffer_) {
|
||||
temppath = createBufferTmpDir();
|
||||
@ -946,16 +952,35 @@ void Buffer::setFullyLoaded(bool value)
|
||||
}
|
||||
|
||||
|
||||
void Buffer::updatePreviews() const
|
||||
PreviewLoader * Buffer::loader() const
|
||||
{
|
||||
if (graphics::Previews::status() != LyXRC::PREVIEW_OFF)
|
||||
thePreviews().generateBufferPreviews(*this);
|
||||
if (lyxrc.preview == LyXRC::PREVIEW_OFF)
|
||||
return 0;
|
||||
if (!d->preview_loader_)
|
||||
d->preview_loader_ = new PreviewLoader(*this);
|
||||
return d->preview_loader_;
|
||||
}
|
||||
|
||||
|
||||
void Buffer::removePreviews() const
|
||||
{
|
||||
thePreviews().removeLoader(*this);
|
||||
delete d->preview_loader_;
|
||||
d->preview_loader_ = 0;
|
||||
}
|
||||
|
||||
|
||||
void Buffer::updatePreviews() const
|
||||
{
|
||||
PreviewLoader * ploader = loader();
|
||||
if (!ploader)
|
||||
return;
|
||||
|
||||
InsetIterator it = inset_iterator_begin(*d->inset);
|
||||
InsetIterator const end = inset_iterator_end(*d->inset);
|
||||
for (; it != end; ++it)
|
||||
it->addPreview(it, *ploader);
|
||||
|
||||
ploader->startLoading();
|
||||
}
|
||||
|
||||
|
||||
|
@ -72,6 +72,10 @@ class FileName;
|
||||
class FileNameList;
|
||||
}
|
||||
|
||||
namespace graphics {
|
||||
class PreviewLoader;
|
||||
}
|
||||
|
||||
|
||||
class Buffer;
|
||||
typedef std::list<Buffer *> ListOfBuffers;
|
||||
@ -511,6 +515,8 @@ public:
|
||||
/// Set by buffer_funcs' newFile.
|
||||
void setFullyLoaded(bool);
|
||||
|
||||
/// FIXME: Needed by RenderPreview.
|
||||
graphics::PreviewLoader * Buffer::loader() const;
|
||||
/// Update the LaTeX preview snippets associated with this buffer
|
||||
void updatePreviews() const;
|
||||
/// Remove any previewed LaTeX snippets associated with this buffer
|
||||
|
@ -69,8 +69,6 @@
|
||||
#include "frontends/Painter.h"
|
||||
#include "frontends/Selection.h"
|
||||
|
||||
#include "graphics/Previews.h"
|
||||
|
||||
#include "support/convert.h"
|
||||
#include "support/debug.h"
|
||||
#include "support/ExceptionMessage.h"
|
||||
|
11
src/LyX.cpp
11
src/LyX.cpp
@ -48,8 +48,6 @@
|
||||
#include "frontends/alert.h"
|
||||
#include "frontends/Application.h"
|
||||
|
||||
#include "graphics/Previews.h"
|
||||
|
||||
#include "support/lassert.h"
|
||||
#include "support/debug.h"
|
||||
#include "support/environment.h"
|
||||
@ -193,8 +191,6 @@ struct LyX::Impl
|
||||
/// the parsed command line batch command if any
|
||||
vector<string> batch_commands;
|
||||
|
||||
///
|
||||
graphics::Previews preview_;
|
||||
///
|
||||
SpellChecker * spell_checker_;
|
||||
///
|
||||
@ -1380,13 +1376,6 @@ Messages const & getGuiMessages()
|
||||
}
|
||||
|
||||
|
||||
graphics::Previews & thePreviews()
|
||||
{
|
||||
LASSERT(singleton_, /**/);
|
||||
return singleton_->pimpl_->preview_;
|
||||
}
|
||||
|
||||
|
||||
Session & theSession()
|
||||
{
|
||||
LASSERT(singleton_, /**/);
|
||||
|
@ -57,10 +57,6 @@ namespace frontend {
|
||||
class Application;
|
||||
}
|
||||
|
||||
namespace graphics {
|
||||
class Previews;
|
||||
}
|
||||
|
||||
/// initial startup
|
||||
class LyX {
|
||||
public:
|
||||
@ -151,7 +147,6 @@ private:
|
||||
friend void setMover(std::string const & fmt, std::string const & command);
|
||||
friend Movers & theSystemMovers();
|
||||
friend frontend::Application * theApp();
|
||||
friend graphics::Previews & thePreviews();
|
||||
friend Session & theSession();
|
||||
friend CmdDef & theTopLevelCmdDef();
|
||||
friend SpellChecker * theSpellChecker();
|
||||
|
@ -348,9 +348,7 @@ liblyxgraphics_a_SOURCES = \
|
||||
graphics/PreviewImage.h \
|
||||
graphics/PreviewImage.cpp \
|
||||
graphics/PreviewLoader.h \
|
||||
graphics/PreviewLoader.cpp \
|
||||
graphics/Previews.h \
|
||||
graphics/Previews.cpp
|
||||
graphics/PreviewLoader.cpp
|
||||
|
||||
|
||||
############################### Mathed ##############################
|
||||
|
@ -1,82 +0,0 @@
|
||||
/**
|
||||
* \file Previews.cpp
|
||||
* This file is part of LyX, the document processor.
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* \author Angus Leeming
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "Previews.h"
|
||||
#include "PreviewLoader.h"
|
||||
|
||||
#include "Buffer.h"
|
||||
#include "InsetIterator.h"
|
||||
#include "LyXRC.h"
|
||||
|
||||
#include "insets/Inset.h"
|
||||
#include "support/shared_ptr.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace lyx {
|
||||
|
||||
namespace graphics {
|
||||
|
||||
LyXRC_PreviewStatus Previews::status()
|
||||
{
|
||||
return lyxrc.preview;
|
||||
}
|
||||
|
||||
|
||||
namespace {
|
||||
typedef shared_ptr<PreviewLoader> PreviewLoaderPtr;
|
||||
///
|
||||
typedef map<Buffer const *, PreviewLoaderPtr> LyxCacheType;
|
||||
///
|
||||
static LyxCacheType preview_cache_;
|
||||
}
|
||||
|
||||
|
||||
PreviewLoader & Previews::loader(Buffer const & buffer) const
|
||||
{
|
||||
LyxCacheType::iterator it = preview_cache_.find(&buffer);
|
||||
|
||||
if (it == preview_cache_.end()) {
|
||||
PreviewLoaderPtr ptr(new PreviewLoader(buffer));
|
||||
preview_cache_[&buffer] = ptr;
|
||||
return *ptr.get();
|
||||
}
|
||||
|
||||
return *it->second.get();
|
||||
}
|
||||
|
||||
|
||||
void Previews::removeLoader(Buffer const & buffer) const
|
||||
{
|
||||
LyxCacheType::iterator it = preview_cache_.find(&buffer);
|
||||
|
||||
if (it != preview_cache_.end())
|
||||
preview_cache_.erase(it);
|
||||
}
|
||||
|
||||
|
||||
void Previews::generateBufferPreviews(Buffer const & buffer) const
|
||||
{
|
||||
PreviewLoader & ploader = loader(buffer);
|
||||
|
||||
Inset & inset = buffer.inset();
|
||||
InsetIterator it = inset_iterator_begin(inset);
|
||||
InsetIterator const end = inset_iterator_end(inset);
|
||||
|
||||
for (; it != end; ++it)
|
||||
it->addPreview(it, ploader);
|
||||
|
||||
ploader.startLoading();
|
||||
}
|
||||
|
||||
} // namespace graphics
|
||||
} // namespace lyx
|
@ -1,63 +0,0 @@
|
||||
// -*- C++ -*-
|
||||
/**
|
||||
* \file Previews.h
|
||||
* This file is part of LyX, the document processor.
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* \author Angus Leeming
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*
|
||||
* graphics::Previews is a singleton class that stores the
|
||||
* graphics::PreviewLoader for each buffer requiring one.
|
||||
*/
|
||||
|
||||
#ifndef PREVIEWS_H
|
||||
#define PREVIEWS_H
|
||||
|
||||
namespace lyx {
|
||||
|
||||
class Buffer;
|
||||
class LyXRC_PreviewStatus;
|
||||
|
||||
namespace graphics {
|
||||
|
||||
class PreviewLoader;
|
||||
|
||||
class Previews {
|
||||
public:
|
||||
/// This should be a singleton class only instanciated in LyX.cpp.
|
||||
Previews() {}
|
||||
|
||||
/// a wrapper for lyxrc.preview
|
||||
static LyXRC_PreviewStatus status();
|
||||
|
||||
/** Returns the PreviewLoader for this buffer.
|
||||
* Used by individual insets to update their own preview.
|
||||
*/
|
||||
PreviewLoader & loader(Buffer const & buffer) const;
|
||||
|
||||
/// Called from the Buffer d-tor.
|
||||
void removeLoader(Buffer const & buffer) const;
|
||||
|
||||
/** For a particular buffer, initiate the generation of previews
|
||||
* for each and every snippet of LaTeX that's of interest with
|
||||
* a single forked process.
|
||||
*/
|
||||
void generateBufferPreviews(Buffer const & buffer) const;
|
||||
|
||||
private:
|
||||
/// noncopyable
|
||||
Previews(Previews const &);
|
||||
void operator=(Previews const &);
|
||||
};
|
||||
|
||||
} // namespace graphics
|
||||
|
||||
/// This is a singleton class. Get the instance.
|
||||
/// Implemented in LyX.cpp.
|
||||
graphics::Previews & thePreviews();
|
||||
|
||||
} // namespace lyx
|
||||
|
||||
#endif // PREVIEWS_H
|
@ -13,6 +13,7 @@
|
||||
#include "insets/RenderPreview.h"
|
||||
#include "insets/Inset.h"
|
||||
|
||||
#include "Buffer.h"
|
||||
#include "BufferView.h"
|
||||
#include "Dimension.h"
|
||||
#include "LyX.h"
|
||||
@ -24,7 +25,6 @@
|
||||
|
||||
#include "graphics/PreviewImage.h"
|
||||
#include "graphics/PreviewLoader.h"
|
||||
#include "graphics/Previews.h"
|
||||
|
||||
#include "support/FileName.h"
|
||||
#include "support/gettext.h"
|
||||
@ -41,7 +41,7 @@ namespace lyx {
|
||||
|
||||
LyXRC_PreviewStatus RenderPreview::status()
|
||||
{
|
||||
return graphics::Previews::status();
|
||||
return lyxrc.preview;
|
||||
}
|
||||
|
||||
|
||||
@ -74,19 +74,13 @@ RenderBase * RenderPreview::clone(Inset const * inset) const
|
||||
|
||||
namespace {
|
||||
|
||||
graphics::PreviewLoader & getPreviewLoader(Buffer const & buffer)
|
||||
{
|
||||
return thePreviews().loader(buffer);
|
||||
}
|
||||
|
||||
|
||||
docstring const statusMessage(BufferView const * bv, string const & snippet)
|
||||
{
|
||||
LASSERT(bv, /**/);
|
||||
|
||||
Buffer const & buffer = bv->buffer();
|
||||
graphics::PreviewLoader const & loader = getPreviewLoader(buffer);
|
||||
graphics::PreviewLoader::Status const status = loader.status(snippet);
|
||||
graphics::PreviewLoader const * loader = buffer.loader();
|
||||
graphics::PreviewLoader::Status const status = loader->status(snippet);
|
||||
|
||||
docstring message;
|
||||
switch (status) {
|
||||
@ -111,8 +105,9 @@ docstring const statusMessage(BufferView const * bv, string const & snippet)
|
||||
graphics::PreviewImage const *
|
||||
RenderPreview::getPreviewImage(Buffer const & buffer) const
|
||||
{
|
||||
graphics::PreviewLoader const & loader = getPreviewLoader(buffer);
|
||||
return loader.preview(snippet_);
|
||||
graphics::PreviewLoader const * loader = buffer.loader();
|
||||
LASSERT(loader, return 0);
|
||||
return loader->preview(snippet_);
|
||||
}
|
||||
|
||||
|
||||
@ -180,8 +175,9 @@ void RenderPreview::startLoading(Buffer const & buffer, bool forexport) const
|
||||
if (!forexport && (status() == LyXRC::PREVIEW_OFF || snippet_.empty()))
|
||||
return;
|
||||
|
||||
graphics::PreviewLoader const & loader = getPreviewLoader(buffer);
|
||||
loader.startLoading(forexport);
|
||||
graphics::PreviewLoader * loader = buffer.loader();
|
||||
LASSERT(loader, return);
|
||||
loader->startLoading(forexport);
|
||||
}
|
||||
|
||||
|
||||
@ -192,8 +188,9 @@ void RenderPreview::addPreview(docstring const & latex_snippet,
|
||||
if (status() == LyXRC::PREVIEW_OFF && !ignore_lyxrc)
|
||||
return;
|
||||
|
||||
graphics::PreviewLoader & loader = getPreviewLoader(buffer);
|
||||
addPreview(latex_snippet, loader, ignore_lyxrc);
|
||||
graphics::PreviewLoader * loader = buffer.loader();
|
||||
LASSERT(loader, return);
|
||||
addPreview(latex_snippet, *loader, ignore_lyxrc);
|
||||
}
|
||||
|
||||
|
||||
@ -230,8 +227,9 @@ void RenderPreview::removePreview(Buffer const & buffer)
|
||||
if (snippet_.empty())
|
||||
return;
|
||||
|
||||
graphics::PreviewLoader & loader = getPreviewLoader(buffer);
|
||||
loader.remove(snippet_);
|
||||
graphics::PreviewLoader * loader = buffer.loader();
|
||||
LASSERT(loader, return);
|
||||
loader->remove(snippet_);
|
||||
snippet_.erase();
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ class PreviewLoader;
|
||||
|
||||
class RenderPreview : public RenderBase, public boost::signals::trackable {
|
||||
public:
|
||||
/// a wrapper for Previews::status()
|
||||
/// a wrapper for lyxrc.preview
|
||||
static LyXRC_PreviewStatus status();
|
||||
|
||||
RenderPreview(Inset const *);
|
||||
|
Loading…
Reference in New Issue
Block a user