From 6ef5e10e660a4fb0021090e78ba756332950af5d Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Sun, 12 Nov 2017 14:44:18 +0100 Subject: [PATCH] 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 (cherry picked from commit 0842e22f4551e84dbf24259c65994c760fc22925) --- src/insets/InsetExternal.cpp | 36 ++++++++++++++++++++++++++++-------- src/insets/InsetExternal.h | 8 ++++++-- status.22x | 3 +++ 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/insets/InsetExternal.cpp b/src/insets/InsetExternal.cpp index 4122cfdb05..cb1bc7bda1 100644 --- a/src/insets/InsetExternal.cpp +++ b/src/insets/InsetExternal.cpp @@ -520,12 +520,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); @@ -592,9 +598,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(); } @@ -606,12 +625,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); diff --git a/src/insets/InsetExternal.h b/src/insets/InsetExternal.h index 813e933a0a..c5f106cef5 100644 --- a/src/insets/InsetExternal.h +++ b/src/insets/InsetExternal.h @@ -110,7 +110,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; /// @@ -165,11 +165,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. - boost::scoped_ptr renderer_; + mutable boost::scoped_ptr renderer_; /// changes color of the button when mouse enters/leaves this inset mutable std::map mouse_hover_; }; diff --git a/status.22x b/status.22x index aac55fc5de..b5af1fea1d 100644 --- a/status.22x +++ b/status.22x @@ -100,6 +100,9 @@ What's new - Fix crash with undo and child documents (bug 10643). +- Fix crash when changing preview preferences while previewable + external inset is open (bug 10785). + - Remove duplicate entries from the Symbols dialog (bug 10644). - Always show the float type in the float inset label (bug 10618).