Add a hook into click handler activation.

This commit is contained in:
John Preston 2023-06-23 20:05:35 +04:00
parent 8a56048801
commit fc8d4d25de
3 changed files with 14 additions and 1 deletions

View file

@ -8,6 +8,7 @@
#include "base/algorithm.h"
#include "ui/text/text_entity.h"
#include "ui/integration.h"
#include <QtCore/QPointer>
@ -170,7 +171,9 @@ void ActivateClickHandler(
ClickContext context) {
crl::on_main(guard, [=, weak = std::weak_ptr<ClickHandler>(handler)] {
if (const auto strong = weak.lock()) {
strong->onClick(context);
if (Ui::Integration::Instance().allowClickHandlerActivation(strong, context)) {
strong->onClick(context);
}
}
});
}

View file

@ -76,6 +76,12 @@ Fn<void()> Integration::createSpoilerRepaint(const std::any &context) {
return nullptr;
}
bool Integration::allowClickHandlerActivation(
const std::shared_ptr<ClickHandler> &handler,
const ClickContext &context) {
return true;
}
bool Integration::handleUrlClick(
const QString &url,
const QVariant &context) {

View file

@ -20,6 +20,7 @@ class QVariant;
struct TextParseOptions;
class ClickHandler;
struct ClickContext;
struct EntityLinkData;
namespace Ui {
@ -64,6 +65,9 @@ public:
const std::any &context) -> std::unique_ptr<Text::CustomEmoji>;
[[nodiscard]] virtual Fn<void()> createSpoilerRepaint(
const std::any &context);
[[nodiscard]] virtual bool allowClickHandlerActivation(
const std::shared_ptr<ClickHandler> &handler,
const ClickContext &context);
[[nodiscard]] virtual rpl::producer<> forcePopupMenuHideRequests();