mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 05:16:21 +00:00
safeguards:
- move Previews singleton to LyX - LyX.cpp: set singleton to zero at destruction. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@25594 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
7b7f95a439
commit
647ac4a221
@ -286,7 +286,7 @@ Buffer::~Buffer()
|
||||
}
|
||||
|
||||
// Remove any previewed LaTeX snippets associated with this buffer.
|
||||
graphics::Previews::get().removeLoader(*this);
|
||||
thePreviews()->removeLoader(*this);
|
||||
|
||||
delete d;
|
||||
}
|
||||
@ -2374,11 +2374,12 @@ bool Buffer::doExport(string const & format, bool put_in_tempdir,
|
||||
|
||||
string const error_type = (format == "program")
|
||||
? "Build" : bufferFormat();
|
||||
ErrorList & error_list = d->errorLists[error_type];
|
||||
string const ext = formats.extension(format);
|
||||
FileName const tmp_result_file(changeExtension(filename, ext));
|
||||
bool const success = theConverters().convert(this, FileName(filename),
|
||||
tmp_result_file, FileName(absFileName()), backend_format, format,
|
||||
errorList(error_type));
|
||||
error_list);
|
||||
// Emit the signal to show the error list.
|
||||
if (format != backend_format)
|
||||
errors(error_type);
|
||||
|
@ -282,7 +282,7 @@ BufferView::BufferView(Buffer & buf)
|
||||
d->cursor_.setCurrentFont();
|
||||
|
||||
if (graphics::Previews::status() != LyXRC::PREVIEW_OFF)
|
||||
graphics::Previews::get().generateBufferPreviews(buffer_);
|
||||
thePreviews()->generateBufferPreviews(buffer_);
|
||||
}
|
||||
|
||||
|
||||
|
12
src/LyX.cpp
12
src/LyX.cpp
@ -44,6 +44,8 @@
|
||||
#include "frontends/alert.h"
|
||||
#include "frontends/Application.h"
|
||||
|
||||
#include "graphics/Previews.h"
|
||||
|
||||
#include "support/lassert.h"
|
||||
#include "support/debug.h"
|
||||
#include "support/environment.h"
|
||||
@ -164,6 +166,9 @@ struct LyX::Impl
|
||||
bool first_start;
|
||||
/// the parsed command line batch command if any
|
||||
vector<string> batch_commands;
|
||||
|
||||
///
|
||||
graphics::Previews preview_;
|
||||
};
|
||||
|
||||
///
|
||||
@ -178,6 +183,7 @@ frontend::Application * theApp()
|
||||
|
||||
LyX::~LyX()
|
||||
{
|
||||
singleton_ = 0;
|
||||
delete pimpl_;
|
||||
}
|
||||
|
||||
@ -1310,4 +1316,10 @@ Messages & getGuiMessages()
|
||||
return LyX::ref().getGuiMessages();
|
||||
}
|
||||
|
||||
|
||||
graphics::Previews * thePreviews()
|
||||
{
|
||||
return singleton_ ? 0 : &singleton_->pimpl_->preview_;
|
||||
}
|
||||
|
||||
} // namespace lyx
|
||||
|
@ -38,6 +38,10 @@ class Application;
|
||||
class LyXView;
|
||||
}
|
||||
|
||||
namespace graphics {
|
||||
class Previews;
|
||||
}
|
||||
|
||||
/// initial startup
|
||||
class LyX {
|
||||
public:
|
||||
@ -160,6 +164,7 @@ private:
|
||||
friend Movers & theSystemMovers();
|
||||
friend frontend::Application * theApp();
|
||||
friend KeyMap & theTopLevelKeymap();
|
||||
friend graphics::Previews * thePreviews();
|
||||
};
|
||||
|
||||
} // namespace lyx
|
||||
|
@ -31,42 +31,26 @@ LyXRC_PreviewStatus Previews::status()
|
||||
}
|
||||
|
||||
|
||||
Previews & Previews::get()
|
||||
{
|
||||
static Previews singleton;
|
||||
return singleton;
|
||||
namespace {
|
||||
typedef boost::shared_ptr<PreviewLoader> PreviewLoaderPtr;
|
||||
///
|
||||
typedef map<Buffer const *, PreviewLoaderPtr> CacheType;
|
||||
///
|
||||
static CacheType preview_cache_;
|
||||
}
|
||||
|
||||
|
||||
class Previews::Impl {
|
||||
public:
|
||||
///
|
||||
typedef boost::shared_ptr<PreviewLoader> PreviewLoaderPtr;
|
||||
///
|
||||
typedef map<Buffer const *, PreviewLoaderPtr> CacheType;
|
||||
///
|
||||
CacheType cache;
|
||||
};
|
||||
|
||||
|
||||
Previews::Previews()
|
||||
: pimpl_(new Impl)
|
||||
{}
|
||||
|
||||
|
||||
Previews::~Previews()
|
||||
{
|
||||
delete pimpl_;
|
||||
}
|
||||
|
||||
|
||||
PreviewLoader & Previews::loader(Buffer const & buffer) const
|
||||
{
|
||||
Impl::CacheType::iterator it = pimpl_->cache.find(&buffer);
|
||||
CacheType::iterator it = preview_cache_.find(&buffer);
|
||||
|
||||
if (it == pimpl_->cache.end()) {
|
||||
Impl::PreviewLoaderPtr ptr(new PreviewLoader(buffer));
|
||||
pimpl_->cache[&buffer] = ptr;
|
||||
if (it == preview_cache_.end()) {
|
||||
PreviewLoaderPtr ptr(new PreviewLoader(buffer));
|
||||
preview_cache_[&buffer] = ptr;
|
||||
return *ptr.get();
|
||||
}
|
||||
|
||||
@ -76,10 +60,10 @@ PreviewLoader & Previews::loader(Buffer const & buffer) const
|
||||
|
||||
void Previews::removeLoader(Buffer const & buffer) const
|
||||
{
|
||||
Impl::CacheType::iterator it = pimpl_->cache.find(&buffer);
|
||||
CacheType::iterator it = preview_cache_.find(&buffer);
|
||||
|
||||
if (it != pimpl_->cache.end())
|
||||
pimpl_->cache.erase(it);
|
||||
if (it != preview_cache_.end())
|
||||
preview_cache_.erase(it);
|
||||
}
|
||||
|
||||
|
||||
|
@ -29,9 +29,6 @@ public:
|
||||
/// a wrapper for lyxrc.preview
|
||||
static LyXRC_PreviewStatus status();
|
||||
|
||||
/// This is a singleton class. Get the instance.
|
||||
static Previews & get();
|
||||
|
||||
/** Returns the PreviewLoader for this buffer.
|
||||
* Used by individual insets to update their own preview.
|
||||
*/
|
||||
@ -47,6 +44,7 @@ public:
|
||||
void generateBufferPreviews(Buffer const & buffer) const;
|
||||
|
||||
private:
|
||||
friend class LyX;
|
||||
/// noncopyable
|
||||
Previews(Previews const &);
|
||||
void operator=(Previews const &);
|
||||
@ -55,15 +53,14 @@ private:
|
||||
* are instantiated.
|
||||
*/
|
||||
Previews();
|
||||
~Previews();
|
||||
|
||||
/// Use the Pimpl idiom to hide the internals.
|
||||
class Impl;
|
||||
/// The pointer never changes although *pimpl_'s contents may.
|
||||
Impl * const pimpl_;
|
||||
};
|
||||
|
||||
} // namespace graphics
|
||||
|
||||
/// This is a singleton class. Get the instance.
|
||||
/// Implemented in LyX.cpp.
|
||||
graphics::Previews * thePreviews();
|
||||
|
||||
} // namespace lyx
|
||||
|
||||
#endif // PREVIEWS_H
|
||||
|
Loading…
Reference in New Issue
Block a user