InsetExternal: update renderer after preview status change

This fixes a crash when changing instant preview prefs while
document with previewed external inset is opened.

Fixes: #10785
This commit is contained in:
Juergen Spitzmueller 2017-11-12 14:44:18 +01:00
parent dcc8e1c499
commit 0842e22f45
2 changed files with 34 additions and 10 deletions

View File

@ -524,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);
@ -595,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();
}
@ -609,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);

View File

@ -108,7 +108,7 @@ public:
///
void setParams(InsetExternalParams const &);
/// Update not loaded previews
void updatePreview();
void updatePreview() const;
/// \returns the number of rows (\n's) of generated code.
void latex(otexstream &, OutputParams const &) const;
///
@ -163,11 +163,15 @@ private:
* and the preview should be regenerated.
*/
void fileChanged() const;
/// Is this inset using (instant or graphics) preview?
bool isPreviewed() const;
/// Do we have the right renderer (button, graphic or monitored preview)?
bool isRendererValid() const;
/// The current params
InsetExternalParams params_;
/// The thing that actually draws the image on LyX's screen.
unique_ptr<RenderBase> renderer_;
mutable unique_ptr<RenderBase> renderer_;
/// changes color of the button when mouse enters/leaves this inset
mutable std::map<BufferView const *, bool> mouse_hover_;
};