+2002-08-02 Angus Leeming <leeming@lyx.org>
+
+ * GraphicsLoader.C: cache the BufferView as a weak_ptr.
+
+ * PreviewLoader.[Ch] (buffer): new method, returning the owner.
+ (add): don't add empty snippets.
+
+ * PreviewedInset.[Ch]: cache the BufferView as a weak_ptr.
+ (view, setView): access to to the cache_.
+
2002-08-02 Angus Leeming <leeming@lyx.org>
* PreviewedInset.[Ch]: cache the LaTeX snippet.
#endif
#include "GraphicsLoader.h"
+
+#include "BufferView.h"
+
#include "GraphicsCache.h"
#include "GraphicsCacheItem.h"
#include "GraphicsImage.h"
#include "GraphicsParams.h"
#include "GraphicsSupport.h"
+#include "frontends/LyXView.h"
#include "frontends/Timeout.h"
+#include <boost/weak_ptr.hpp>
#include <boost/bind.hpp>
#include <boost/signals/trackable.hpp>
///
InsetList insets;
///
- BufferView const * view;
+ boost::weak_ptr<BufferView const> view;
};
Loader::Impl::Impl(Params const & params)
: status_(WaitingToLoad), params_(params),
- timer(2000, Timeout::ONETIME), view(0)
+ timer(2000, Timeout::ONETIME)
{
timer.timeout.connect(boost::bind(&Impl::checkedLoading, this));
}
it = std::find(it, end, &inset);
if (it == end)
insets.push_back(&inset);
- view = &bv;
+ view = bv.owner()->view();
timer.start();
}
void Loader::Impl::checkedLoading()
{
- if (insets.empty() || !view)
+ if (insets.empty() || !view.get())
return;
- std::list<VisibleParagraph> const vps = getVisibleParagraphs(*view);
+ std::list<VisibleParagraph> const vps =
+ getVisibleParagraphs(*view.get());
InsetList::const_iterator it = insets.begin();
InsetList::const_iterator end = insets.end();
/// Emit this signal when an image is ready for display.
boost::signal1<void, PreviewImage const &> imageReady;
+ Buffer const & buffer() const { return buffer_; }
+
private:
/// Called by the Forkedcall process that generated the bitmap files.
void finishedGenerating(string const &, pid_t, int);
pimpl_->imageReady(pimage);
}
+
+Buffer const & PreviewLoader::buffer() const
+{
+ return pimpl_->buffer();
+}
+
} // namespace grfx
if (!pconverter_ || status(latex_snippet) != NotFound)
return;
- lyxerr[Debug::GRAPHICS] << "adding snippet:\n" << latex_snippet << endl;
+ string const snippet = trim(latex_snippet);
+ if (snippet.empty())
+ return;
+
+ lyxerr[Debug::GRAPHICS] << "adding snippet:\n" << snippet << endl;
- pending_.push_back(latex_snippet);
+ pending_.push_back(snippet);
}
*/
void emitSignal(PreviewImage const &) const;
+ /// Which buffer owns this loader.
+ Buffer const & buffer() const;
+
private:
/// Use the Pimpl idiom to hide the internals.
class Impl;
#include <config.h>
#include "PreviewedInset.h"
-
-#include "BufferView.h"
-
#include "GraphicsImage.h"
#include "PreviewLoader.h"
#include "PreviewImage.h"
#include "Previews.h"
+#include "buffer.h"
+#include "BufferView.h"
+
+#include "frontends/LyXView.h"
+
+#include "support/lstrings.h"
+
#include <boost/bind.hpp>
grfx::Previews & previews = grfx::Previews::get();
grfx::PreviewLoader & loader = previews.loader(view()->buffer());
addPreview(loader);
- loader.startLoading();
+ if (!snippet_.empty())
+ loader.startLoading();
}
if (!Previews::activated() || !previewWanted())
return;
- snippet_ = latexString();
+ setView(ploader.buffer().getUser());
+
+ snippet_ = trim(latexString());
+ if (snippet_.empty())
+ return;
pimage_ = ploader.preview(snippet_);
if (pimage_)
bool PreviewedInset::previewReady() const
{
- if (!grfx::Previews::activated() || !previewWanted() ||
+ if (!Previews::activated() || !previewWanted() ||
!view() || !view()->buffer())
return false;
}
+void PreviewedInset::setView(BufferView * bv)
+{
+ if (!bv)
+ return;
+
+ view_ = bv->owner()->view();
+}
+
void PreviewedInset::imageReady(grfx::PreviewImage const & pimage) const
{
// Check snippet against the Inset's current contents
return;
pimage_ = &pimage;
+
if (view())
view()->updateInset(&inset_, false);
}
#endif
#include "LString.h"
+#include <boost/weak_ptr.hpp>
#include <boost/signals/trackable.hpp>
#include <boost/signals/connection.hpp>
/// If !previewReady() returns 0.
PreviewImage const * pimage() const { return pimage_; }
+ ///
+ void setView(BufferView *);
+
protected:
/// Allow the daughter classes to cast up to the parent inset.
Inset * inset() const { return &inset_; }
+ ///
+ BufferView * view() const { return view_.get(); }
private:
/** This method is connected to the grfx::PreviewLoader::imageReady
/// Does the owning inset want a preview?
virtual bool previewWanted() const = 0;
- ///
- virtual BufferView * view() const = 0;
/// a wrapper to Inset::latex
virtual string const latexString() const = 0;
Inset & inset_;
///
string snippet_;
+ ///
+ boost::weak_ptr<BufferView> view_;
+
/// We don't own this. Cached for efficiency reasons.
mutable PreviewImage const * pimage_;
///
+2002-08-02 Angus Leeming <leeming@lyx.org>
+
+ * insetcite.C: fix typo.
+
+ * insetgraphics.C: kill current_view and instead cache the BufferView
+ as a weak_ptr.
+
+ * insetinclude.C: kill current_view and pass the BufferView to the
+ PreviewedInset so that it can cache it.
+
2002-08-01 Angus Leeming <leeming@lyx.org>
* inset.h (generatePreview): renamed as addPreview.
namespace {
// An optimisation. We assume that until the first InsetCitation::edit is
-// called, we're loding the buffer and that, therefore, we don't need to
+// called, we're loading the buffer and that, therefore, we don't need to
// reload the bibkey list
std::map<Buffer const *, bool> loading_buffer;
#include "graphics/GraphicsImage.h"
#include "graphics/GraphicsParams.h"
-#include "frontends/LyXView.h"
#include "lyxtext.h"
#include "buffer.h"
#include "BufferView.h"
#include "LaTeXFeatures.h"
#include "lyxlex.h"
-#include "frontends/Dialogs.h"
#include "frontends/Alert.h"
+#include "frontends/Dialogs.h"
+#include "frontends/LyXView.h"
+
#include "frontends/controllers/helper_funcs.h" // getVectorFromString
#include "support/LAssert.h"
#include "support/systemcall.h"
#include "support/os.h"
+#include <boost/weak_ptr.hpp>
#include <boost/bind.hpp>
#include <boost/signals/trackable.hpp>
#include <algorithm> // For the std::max
-// Very, Very UGLY!
-extern BufferView * current_view;
-
extern string system_tempdir;
using std::ostream;
grfx::Loader loader;
///
unsigned long checksum;
+ ///
+ boost::weak_ptr<BufferView> view;
private:
///
void InsetGraphics::draw(BufferView * bv, LyXFont const & font,
int baseline, float & x, bool) const
{
+ cache_->view = bv->owner()->view();
int oasc = cache_->old_ascent;
int ldescent = descent(bv, font);
void InsetGraphics::statusChanged()
{
- current_view->updateInset(this, false);
+ if (cache_->view.get())
+ cache_->view.get()->updateInset(this, false);
}
#include "BufferView.h"
#include "debug.h"
#include "lyxrc.h"
-#include "frontends/LyXView.h"
#include "LaTeXFeatures.h"
#include "gettext.h"
#include "frontends/Dialogs.h"
+#include "frontends/LyXView.h"
#include "frontends/Painter.h"
#include "support/filetools.h"
using std::pair;
extern BufferList bufferlist;
-extern BufferView * current_view;
+
class InsetInclude::PreviewImpl : public grfx::PreviewedInset {
public:
bool previewWanted() const;
///
string const latexString() const;
-
- ///
- BufferView * view() const { return current_view; }
///
InsetInclude & parent() const {
return *static_cast<InsetInclude*>(inset());
void InsetInclude::draw(BufferView * bv, LyXFont const & font, int y,
float & xx, bool b) const
{
+ preview_->setView(bv);
if (!preview_->previewReady()) {
InsetButton::draw(bv, font, y, xx, b);
return;
void InsetInclude::addPreview(grfx::PreviewLoader & ploader) const
{
- lyxerr << "InsetInclude::addPreview" << endl;
preview_->addPreview(ploader);
}
+2002-08-02 Angus Leeming <leeming@lyx.org>
+
+ * formula.C: pass the BufferView to the PreviewedInset so that it can
+ cache it.
+
2002-08-02 Angus Leeming <leeming@lyx.org>
* formulabase.[Ch]: store the BufferView as a weak_ptr.
///
string const latexString() const;
///
- BufferView * view() const
- {
- return parent().view();
- }
- ///
InsetFormula & parent() const
{
return *static_cast<InsetFormula*>(inset());
{
// This initiates the loading of the preview, so should come
// before the metrics are computed.
- view_ = bv->owner()->view();
+ preview_->setView(bv);
bool const use_preview = preview_->previewReady();
int const x = int(xx);