From 5908bb3ea6e6962308c70bd05a7f61baa8f2e0ce Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Tue, 19 Jan 2021 13:23:03 +0100 Subject: [PATCH] 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. --- src/insets/InsetCommand.h | 2 -- src/insets/InsetInclude.cpp | 24 +++++++++++------------- src/insets/InsetInclude.h | 6 ++---- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/insets/InsetCommand.h b/src/insets/InsetCommand.h index 7b2b5bde08..7ad10af0ae 100644 --- a/src/insets/InsetCommand.h +++ b/src/insets/InsetCommand.h @@ -127,8 +127,6 @@ protected: //@} private: - /// - RenderButton & button() const { return button_; } /// This should provide the text for the button virtual docstring screenLabel() const = 0; diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp index 33defcebfd..467cd110af 100644 --- a/src/insets/InsetInclude.cpp +++ b/src/insets/InsetInclude.cpp @@ -182,7 +182,7 @@ char_type replaceCommaInBraces(docstring & params) InsetInclude::InsetInclude(Buffer * buf, InsetCommandParams const & p) : InsetCommand(buf, p), include_label(uniqueID()), preview_(make_unique(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) { preview_->connect([this](){ fileChanged(); }); @@ -198,7 +198,7 @@ InsetInclude::InsetInclude(Buffer * buf, InsetCommandParams const & p) InsetInclude::InsetInclude(InsetInclude const & other) : InsetCommand(other), include_label(other.include_label), preview_(make_unique(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_) { preview_->connect([this](){ fileChanged(); }); @@ -376,7 +376,6 @@ void InsetInclude::setParams(InsetCommandParams const & p) recursion_error_ = false; InsetCommand::setParams(p); - set_label_ = false; if (preview_->monitoring()) 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 { LBUFERR(mi.base.bv); @@ -1210,13 +1215,9 @@ void InsetInclude::metrics(MetricsInfo & mi, Dimension & dim) const if (use_preview) { preview_->metrics(mi, dim); } else { - if (!set_label_) { - set_label_ = true; - button_.update(screenLabel(), true, false, !file_exist_ || recursion_error_); - } - button_.metrics(mi, dim); + setBroken(!file_exist_ || recursion_error_); + InsetCommand::metrics(mi, dim); } - } @@ -1234,7 +1235,7 @@ void InsetInclude::draw(PainterInfo & pi, int x, int y) const if (use_preview) preview_->draw(pi, x, y); 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 (!checkForRecursiveInclude(childbuffer)) childbuffer->updateBuffer(Buffer::UpdateChildOnly, utype); - button_.update(screenLabel(), true, false, recursion_error_); return; } - button_.update(screenLabel(), true, false, !file_exist_); - if (!isListings(params())) return; diff --git a/src/insets/InsetInclude.h b/src/insets/InsetInclude.h index 4b589ca4d8..8585222070 100644 --- a/src/insets/InsetInclude.h +++ b/src/insets/InsetInclude.h @@ -15,8 +15,6 @@ #include "InsetCommand.h" -#include "RenderButton.h" - #include "support/unique_ptr.h" @@ -70,6 +68,8 @@ public: void setBuffer(Buffer & buffer) override; /// bool isLabeled() const override { return true; } + /// + bool inheritFont() const override; /// Override these InsetButton methods if Previewing void metrics(MetricsInfo & mi, Dimension & dim) const override; /// @@ -168,8 +168,6 @@ private: /// mutable bool failedtoload_; /// cache - mutable bool set_label_; - mutable RenderButton button_; mutable docstring listings_label_; InsetLabel * label_; mutable Buffer * child_buffer_; -- 2.39.5