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 0842e22f45)
This commit is contained in:
Juergen Spitzmueller 2017-11-12 14:44:18 +01:00
parent 9235d5299e
commit 6ef5e10e66
3 changed files with 37 additions and 10 deletions

View File

@ -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);

View File

@ -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<RenderBase> renderer_;
mutable boost::scoped_ptr<RenderBase> renderer_;
/// changes color of the button when mouse enters/leaves this inset
mutable std::map<BufferView const *, bool> mouse_hover_;
};

View File

@ -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).