Don't use the cached BufferView to get the Buffer when we have direct access

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7886 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2003-10-09 14:36:16 +00:00
parent b5b225c657
commit 8ddfa9d784
7 changed files with 46 additions and 28 deletions

View File

@ -1,3 +1,9 @@
2003-10-09 Angus Leeming <leeming@lyx.org>
* PreviewedInset.[Ch] (removePreview, previewReady): these functions
are now passed a 'Buffer const &', eliminating most of the remaining
need for PreviewedInset to use a BufferView cache.
2003-10-07 Martin Vermeer <martin.vermeer@hut.fi>
* GraphicsCache.h:

View File

@ -75,8 +75,8 @@ void PreviewedInset::addPreview(PreviewLoader & ploader)
// If this is the first time of calling, connect to the
// PreviewLoader signal that'll inform us when the preview image
// is ready for loading.
if (!connection_.connected()) {
connection_ = ploader.connect(
if (!ploader_connection_.connected()) {
ploader_connection_ = ploader.connect(
boost::bind(&PreviewedInset::imageReady, this, _1));
}
@ -84,43 +84,36 @@ void PreviewedInset::addPreview(PreviewLoader & ploader)
}
void PreviewedInset::removePreview()
void PreviewedInset::removePreview(Buffer const & buffer)
{
if (!view() || !view()->buffer() || snippet_.empty())
if (snippet_.empty())
return;
Previews & previews = Previews::get();
PreviewLoader & loader = previews.loader(*view()->buffer());
PreviewLoader & loader = previews.loader(buffer);
loader.remove(snippet_);
snippet_.erase();
pimage_ = 0;
}
bool PreviewedInset::previewReady() const
bool PreviewedInset::previewReady(Buffer const & buffer) const
{
if (!Previews::activated() || !view() || !view()->buffer())
return false;
if (!previewWanted(*view()->buffer()))
if (!Previews::activated() || !previewWanted(buffer))
return false;
if (!pimage_ || snippet_ != pimage_->snippet()) {
PreviewLoader & ploader =
Previews::get().loader(*view()->buffer());
PreviewLoader & ploader = Previews::get().loader(buffer);
pimage_ = ploader.preview(snippet_);
}
if (!pimage_)
return false;
return pimage_->image();
return pimage_ ? pimage_->image() : false;
}
void PreviewedInset::imageReady(PreviewImage const & pimage) const
{
// Check snippet against the Inset's current contents
// Check the current snippet is the same as that previewed.
if (snippet_ != pimage.snippet())
return;

View File

@ -51,10 +51,10 @@ public:
/** Remove a snippet from the cache of previews.
* Useful if previewing the contents of a file that has changed.
*/
void removePreview();
void removePreview(Buffer const &);
/// The preview has been generated and is ready to use.
bool previewReady() const;
bool previewReady(Buffer const &) const;
/// If !previewReady() returns 0.
PreviewImage const * pimage() const;
@ -83,8 +83,10 @@ private:
/// We don't own this. Cached for efficiency reasons.
mutable PreviewImage const * pimage_;
///
boost::signals::connection connection_;
/** Store the connection to the preview loader so that we connect
* only once.
*/
boost::signals::connection ploader_connection_;
};

View File

@ -1,3 +1,7 @@
2003-10-09 Angus Leeming <leeming@lyx.org>
* insetinclude.C (metrics, draw, restartLoading): pass a buffer arg
to PreviewedInset's previewReady and removePreview member functions.
2003-10-08 André Pönitz <poenitz@gmx.net>

View File

@ -538,7 +538,8 @@ void InsetInclude::fillWithBibKeys(Buffer const & buffer,
void InsetInclude::metrics(MetricsInfo & mi, Dimension & dim) const
{
if (preview_->previewReady()) {
Buffer const * buffer_ptr = mi.base.bv ? mi.base.bv->buffer() : 0;
if (buffer_ptr && preview_->previewReady(*buffer_ptr)) {
dim.asc = preview_->pimage()->ascent();
dim.des = preview_->pimage()->descent();
dim.wid = preview_->pimage()->width();
@ -563,7 +564,10 @@ void InsetInclude::metrics(MetricsInfo & mi, Dimension & dim) const
void InsetInclude::draw(PainterInfo & pi, int x, int y) const
{
cache(pi.base.bv);
if (!preview_->previewReady()) {
Buffer const * buffer_ptr = pi.base.bv ? pi.base.bv->buffer() : 0;
bool const use_preview = buffer_ptr && preview_->previewReady(*buffer_ptr);
if (!use_preview) {
button_.draw(pi, x + button_.box().x1, y);
return;
}
@ -626,12 +630,14 @@ void InsetInclude::PreviewImpl::startMonitoring(string const & file)
void InsetInclude::PreviewImpl::restartLoading()
{
removePreview();
if (!view())
return;
view()->updateInset(&parent());
if (view()->buffer())
generatePreview(*view()->buffer());
if (view()->buffer()) {
Buffer const & buffer = *view()->buffer();
removePreview(buffer);
generatePreview(buffer);
}
}

View File

@ -1,3 +1,7 @@
2003-10-09 Angus Leeming <leeming@lyx.org>
* formula.C (metrics, draw): pass a buffer arg to PreviewedInset's
previewReady and removePreview member functions.
2003-10-07 André Pönitz <poenitz@gmx.net>

View File

@ -18,6 +18,7 @@
#include "math_mathmlstream.h"
#include "textpainter.h"
#include "BufferView.h"
#include "debug.h"
#include "latexrunparams.h"
#include "LColor.h"
@ -195,7 +196,8 @@ void InsetFormula::draw(PainterInfo & pi, int x, int y) const
cache(pi.base.bv);
// This initiates the loading of the preview, so should come
// before the metrics are computed.
bool const use_preview = preview_->previewReady();
Buffer const * buffer_ptr = pi.base.bv ? pi.base.bv->buffer() : 0;
bool const use_preview = buffer_ptr && preview_->previewReady(*buffer_ptr);
int const w = dim_.wid;
int const d = dim_.des;
@ -260,7 +262,8 @@ bool InsetFormula::insetAllowed(InsetOld::Code code) const
void InsetFormula::metrics(MetricsInfo & m, Dimension & dim) const
{
view_ = m.base.bv;
if (preview_->previewReady()) {
Buffer const * buffer_ptr = m.base.bv ? m.base.bv->buffer() : 0;
if (buffer_ptr && preview_->previewReady(*buffer_ptr)) {
dim.asc = preview_->pimage()->ascent();
dim.des = preview_->pimage()->descent();
// insert a one pixel gap in front of the formula