From 83d85dc2288c87bff54355846854070433832961 Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Tue, 9 Apr 2019 22:15:54 +0100 Subject: [PATCH] Add invokable public API for emitting contextualActionsAboutToShow Summary: This signal is emitted just before showing the context menu to allow lazy-loading expensive actions like hasAlternatives. This emitted by our code whenever we show a context menu from an event filter, however we want to use this code from a tooltip in D17410 Test Plan: Hovered over some applets, they correctly enabled/disabled the alternatives button Reviewers: #plasma Subscribers: kde-frameworks-devel Tags: #frameworks Differential Revision: https://phabricator.kde.org/D20417 --- src/scriptengines/qml/plasmoid/appletinterface.cpp | 7 ++++++- src/scriptengines/qml/plasmoid/appletinterface.h | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/scriptengines/qml/plasmoid/appletinterface.cpp b/src/scriptengines/qml/plasmoid/appletinterface.cpp index d54e5f7d8..54f82d195 100644 --- a/src/scriptengines/qml/plasmoid/appletinterface.cpp +++ b/src/scriptengines/qml/plasmoid/appletinterface.cpp @@ -784,6 +784,11 @@ bool AppletInterface::event(QEvent *event) return AppletQuickItem::event(event); } +void AppletInterface::prepareContextualActions() +{ + emit applet()->contextualActionsAboutToShow(); +} + bool AppletInterface::eventFilter(QObject *watched, QEvent *event) { if (event->type() == QEvent::MouseButtonPress) { @@ -825,7 +830,7 @@ bool AppletInterface::eventFilter(QObject *watched, QEvent *event) if (desktopMenu->winId()) { desktopMenu->windowHandle()->setTransientParent(window()); } - emit applet()->contextualActionsAboutToShow(); + prepareContextualActions(); ci->addAppletActions(desktopMenu, applet(), event); if (!desktopMenu->isEmpty()) { diff --git a/src/scriptengines/qml/plasmoid/appletinterface.h b/src/scriptengines/qml/plasmoid/appletinterface.h index 7423c43cf..f09f99f48 100644 --- a/src/scriptengines/qml/plasmoid/appletinterface.h +++ b/src/scriptengines/qml/plasmoid/appletinterface.h @@ -277,6 +277,14 @@ public: Q_INVOKABLE QAction *action(QString name) const; + /** + * Should be called before retrieving any action + * to ensure contents are up to date + * @see contextualActionsAboutToShow + * @since 5.58 + */ + Q_INVOKABLE void prepareContextualActions(); + /** * FIXME: remove? * Retrieve the path of a file from the Plasmoid package