X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FInsetExternal.cpp;h=1f0f5f2b770d271dbcedfd52514849cf6c6932f0;hb=22e6659780390a19174d1bf896317a5baf9e40d7;hp=3b8159bdb328a82070710ebf82df4f7e457e0495;hpb=db58111360d68f76c5797069a7b80967447d1379;p=lyx.git diff --git a/src/insets/InsetExternal.cpp b/src/insets/InsetExternal.cpp index 3b8159bdb3..1f0f5f2b77 100644 --- a/src/insets/InsetExternal.cpp +++ b/src/insets/InsetExternal.cpp @@ -61,7 +61,7 @@ unsigned int const defaultLyxScale = 100; string defaultTemplateName; -} // namespace anon +} // namespace namespace lyx { @@ -102,7 +102,7 @@ TempName & TempName::operator=(TempName const & other) tempname_.removeFile(); support::TempFile f("lyxextXXXXXX.tmp"); f.setAutoRemove(false); - tempname_ = f.name(); + tempname_ = f.name(); } return *this; } @@ -148,7 +148,7 @@ void clearIfNotFound(T & data, external::TransformID value, data = T(); } -} // namespace anon +} // namespace void InsetExternalParams::settemplate(string const & name) @@ -170,7 +170,7 @@ void InsetExternalParams::settemplate(string const & name) clearIfNotFound(resizedata, external::Resize, ids); clearIfNotFound(rotationdata, external::Rotate, ids); - // + // preview_mode = et->preview_mode; } @@ -414,8 +414,7 @@ docstring screenLabel(InsetExternalParams const & params, return gui; } -} // namespace anon - +} // namespace InsetExternal::InsetExternal(Buffer * buf) @@ -525,12 +524,18 @@ bool InsetExternal::showInsetDialog(BufferView * bv) const void InsetExternal::metrics(MetricsInfo & mi, Dimension & dim) const { + if (!isRendererValid()) + updatePreview(); + renderer_->metrics(mi, dim); } void InsetExternal::draw(PainterInfo & pi, int x, int y) const { + if (!isRendererValid()) + updatePreview(); + if (renderer_->asButton()) renderer_->setRenderState(mouse_hover_[pi.base.bv]); renderer_->draw(pi, x, y); @@ -553,7 +558,7 @@ graphics::Params get_grfx_params(InsetExternalParams const & eparams) return gparams; } -} // namespace anon +} // namespace static bool isPreviewWanted(InsetExternalParams const & params) @@ -596,9 +601,22 @@ InsetExternalParams const & InsetExternal::params() const } -void InsetExternal::updatePreview() +bool InsetExternal::isPreviewed() const { - setParams(params_); + return (external::getTemplatePtr(params_) && !params_.filename.empty() + && params_.display + && lyxrc.display_graphics + && params_.preview_mode != PREVIEW_OFF + && (params_.preview_mode != PREVIEW_INSTANT + || RenderPreview::previewText())); +} + + +bool InsetExternal::isRendererValid() const +{ + if (!renderer_->asButton()) + return isPreviewed(); + return !isPreviewed(); } @@ -610,12 +628,13 @@ void InsetExternal::setParams(InsetExternalParams const & p) // will use this. defaultTemplateName = params_.templatename(); - if (!external::getTemplatePtr(params_) || params_.filename.empty() - || !params_.display - || !lyxrc.display_graphics - || params_.preview_mode == PREVIEW_OFF - || (params_.preview_mode == PREVIEW_INSTANT - && !RenderPreview::previewText())) { + updatePreview(); +} + + +void InsetExternal::updatePreview() const +{ + if (!isPreviewed()) { RenderButton * button_ptr = renderer_->asButton(); if (!button_ptr) { renderer_.reset(new RenderButton);