Cleanup button handling in InsetInclude

The include inset has its own button_ object, that hides the button_
object of the InsetCommand parent. Remove that.

Remove the hand-made caching that uses the set_label_ boolean.

Let metrics() and draw() use the inherited methods. This requires to
use setBroken as needed and to implement inheritFont.

The use of InsetCommand::draw is what restores the hover effect.

Fixes bug #10415.
This commit is contained in:
Jean-Marc Lasgouttes 2021-01-19 13:23:03 +01:00
parent 64b22a6d80
commit 5908bb3ea6
3 changed files with 13 additions and 19 deletions

View File

@ -127,8 +127,6 @@ protected:
//@} //@}
private: private:
///
RenderButton & button() const { return button_; }
/// This should provide the text for the button /// This should provide the text for the button
virtual docstring screenLabel() const = 0; virtual docstring screenLabel() const = 0;

View File

@ -182,7 +182,7 @@ char_type replaceCommaInBraces(docstring & params)
InsetInclude::InsetInclude(Buffer * buf, InsetCommandParams const & p) InsetInclude::InsetInclude(Buffer * buf, InsetCommandParams const & p)
: InsetCommand(buf, p), include_label(uniqueID()), : InsetCommand(buf, p), include_label(uniqueID()),
preview_(make_unique<RenderMonitoredPreview>(this)), failedtoload_(false), preview_(make_unique<RenderMonitoredPreview>(this)), failedtoload_(false),
set_label_(false), label_(nullptr), child_buffer_(nullptr), file_exist_(false), label_(nullptr), child_buffer_(nullptr), file_exist_(false),
recursion_error_(false) recursion_error_(false)
{ {
preview_->connect([this](){ fileChanged(); }); preview_->connect([this](){ fileChanged(); });
@ -198,7 +198,7 @@ InsetInclude::InsetInclude(Buffer * buf, InsetCommandParams const & p)
InsetInclude::InsetInclude(InsetInclude const & other) InsetInclude::InsetInclude(InsetInclude const & other)
: InsetCommand(other), include_label(other.include_label), : InsetCommand(other), include_label(other.include_label),
preview_(make_unique<RenderMonitoredPreview>(this)), failedtoload_(false), preview_(make_unique<RenderMonitoredPreview>(this)), failedtoload_(false),
set_label_(false), label_(nullptr), child_buffer_(nullptr), label_(nullptr), child_buffer_(nullptr),
file_exist_(other.file_exist_),recursion_error_(other.recursion_error_) file_exist_(other.file_exist_),recursion_error_(other.recursion_error_)
{ {
preview_->connect([this](){ fileChanged(); }); preview_->connect([this](){ fileChanged(); });
@ -376,7 +376,6 @@ void InsetInclude::setParams(InsetCommandParams const & p)
recursion_error_ = false; recursion_error_ = false;
InsetCommand::setParams(p); InsetCommand::setParams(p);
set_label_ = false;
if (preview_->monitoring()) if (preview_->monitoring())
preview_->stopMonitoring(); preview_->stopMonitoring();
@ -1196,6 +1195,12 @@ void InsetInclude::collectBibKeys(InsetIterator const & /*di*/, FileNameList & c
} }
bool InsetInclude::inheritFont() const
{
return !isVerbatim(params());
}
void InsetInclude::metrics(MetricsInfo & mi, Dimension & dim) const void InsetInclude::metrics(MetricsInfo & mi, Dimension & dim) const
{ {
LBUFERR(mi.base.bv); LBUFERR(mi.base.bv);
@ -1210,13 +1215,9 @@ void InsetInclude::metrics(MetricsInfo & mi, Dimension & dim) const
if (use_preview) { if (use_preview) {
preview_->metrics(mi, dim); preview_->metrics(mi, dim);
} else { } else {
if (!set_label_) { setBroken(!file_exist_ || recursion_error_);
set_label_ = true; InsetCommand::metrics(mi, dim);
button_.update(screenLabel(), true, false, !file_exist_ || recursion_error_);
}
button_.metrics(mi, dim);
} }
} }
@ -1234,7 +1235,7 @@ void InsetInclude::draw(PainterInfo & pi, int x, int y) const
if (use_preview) if (use_preview)
preview_->draw(pi, x, y); preview_->draw(pi, x, y);
else else
button_.draw(pi, x, y); InsetCommand::draw(pi, x, y);
} }
@ -1425,12 +1426,9 @@ void InsetInclude::updateBuffer(ParIterator const & it, UpdateType utype, bool c
if (childbuffer) { if (childbuffer) {
if (!checkForRecursiveInclude(childbuffer)) if (!checkForRecursiveInclude(childbuffer))
childbuffer->updateBuffer(Buffer::UpdateChildOnly, utype); childbuffer->updateBuffer(Buffer::UpdateChildOnly, utype);
button_.update(screenLabel(), true, false, recursion_error_);
return; return;
} }
button_.update(screenLabel(), true, false, !file_exist_);
if (!isListings(params())) if (!isListings(params()))
return; return;

View File

@ -15,8 +15,6 @@
#include "InsetCommand.h" #include "InsetCommand.h"
#include "RenderButton.h"
#include "support/unique_ptr.h" #include "support/unique_ptr.h"
@ -70,6 +68,8 @@ public:
void setBuffer(Buffer & buffer) override; void setBuffer(Buffer & buffer) override;
/// ///
bool isLabeled() const override { return true; } bool isLabeled() const override { return true; }
///
bool inheritFont() const override;
/// Override these InsetButton methods if Previewing /// Override these InsetButton methods if Previewing
void metrics(MetricsInfo & mi, Dimension & dim) const override; void metrics(MetricsInfo & mi, Dimension & dim) const override;
/// ///
@ -168,8 +168,6 @@ private:
/// ///
mutable bool failedtoload_; mutable bool failedtoload_;
/// cache /// cache
mutable bool set_label_;
mutable RenderButton button_;
mutable docstring listings_label_; mutable docstring listings_label_;
InsetLabel * label_; InsetLabel * label_;
mutable Buffer * child_buffer_; mutable Buffer * child_buffer_;