mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
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:
parent
dcc8e1c499
commit
0842e22f45
@ -524,12 +524,18 @@ bool InsetExternal::showInsetDialog(BufferView * bv) const
|
|||||||
|
|
||||||
void InsetExternal::metrics(MetricsInfo & mi, Dimension & dim) const
|
void InsetExternal::metrics(MetricsInfo & mi, Dimension & dim) const
|
||||||
{
|
{
|
||||||
|
if (!isRendererValid())
|
||||||
|
updatePreview();
|
||||||
|
|
||||||
renderer_->metrics(mi, dim);
|
renderer_->metrics(mi, dim);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void InsetExternal::draw(PainterInfo & pi, int x, int y) const
|
void InsetExternal::draw(PainterInfo & pi, int x, int y) const
|
||||||
{
|
{
|
||||||
|
if (!isRendererValid())
|
||||||
|
updatePreview();
|
||||||
|
|
||||||
if (renderer_->asButton())
|
if (renderer_->asButton())
|
||||||
renderer_->setRenderState(mouse_hover_[pi.base.bv]);
|
renderer_->setRenderState(mouse_hover_[pi.base.bv]);
|
||||||
renderer_->draw(pi, x, y);
|
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.
|
// will use this.
|
||||||
defaultTemplateName = params_.templatename();
|
defaultTemplateName = params_.templatename();
|
||||||
|
|
||||||
if (!external::getTemplatePtr(params_) || params_.filename.empty()
|
updatePreview();
|
||||||
|| !params_.display
|
}
|
||||||
|| !lyxrc.display_graphics
|
|
||||||
|| params_.preview_mode == PREVIEW_OFF
|
|
||||||
|| (params_.preview_mode == PREVIEW_INSTANT
|
void InsetExternal::updatePreview() const
|
||||||
&& !RenderPreview::previewText())) {
|
{
|
||||||
|
if (!isPreviewed()) {
|
||||||
RenderButton * button_ptr = renderer_->asButton();
|
RenderButton * button_ptr = renderer_->asButton();
|
||||||
if (!button_ptr) {
|
if (!button_ptr) {
|
||||||
renderer_.reset(new RenderButton);
|
renderer_.reset(new RenderButton);
|
||||||
|
@ -108,7 +108,7 @@ public:
|
|||||||
///
|
///
|
||||||
void setParams(InsetExternalParams const &);
|
void setParams(InsetExternalParams const &);
|
||||||
/// Update not loaded previews
|
/// Update not loaded previews
|
||||||
void updatePreview();
|
void updatePreview() const;
|
||||||
/// \returns the number of rows (\n's) of generated code.
|
/// \returns the number of rows (\n's) of generated code.
|
||||||
void latex(otexstream &, OutputParams const &) const;
|
void latex(otexstream &, OutputParams const &) const;
|
||||||
///
|
///
|
||||||
@ -163,11 +163,15 @@ private:
|
|||||||
* and the preview should be regenerated.
|
* and the preview should be regenerated.
|
||||||
*/
|
*/
|
||||||
void fileChanged() const;
|
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
|
/// The current params
|
||||||
InsetExternalParams params_;
|
InsetExternalParams params_;
|
||||||
/// The thing that actually draws the image on LyX's screen.
|
/// 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
|
/// changes color of the button when mouse enters/leaves this inset
|
||||||
mutable std::map<BufferView const *, bool> mouse_hover_;
|
mutable std::map<BufferView const *, bool> mouse_hover_;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user