Commit 5a5369a0 authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇
Browse files

[Purpose Plugin] Detect cancelling the prompt more reliably

aboutToHide is emitted before an action is triggered and activeAction() is the action currently hovered.
This means we can't properly tell that the prompt got canceled, when hovering an action and then hitting
Escape to close the menu.
This patch sets a property in response to triggered and then does a delayed check for that in aboutToHide.

See also QTBUG-56761

Differential Revision: https://phabricator.kde.org/D28719
parent f2969d96
......@@ -73,12 +73,27 @@ QJsonObject PurposePlugin::handleData(int serial, const QString &event, const QJ
m_menu.reset(new Purpose::Menu());
m_menu->model()->setPluginType(QStringLiteral("Export"));
connect(m_menu.data(), &QMenu::aboutToShow, this, [this] {
m_menu->setProperty("actionInvoked", false);
});
connect(m_menu.data(), &QMenu::aboutToHide, this, [this] {
if (!m_menu->activeAction()) {
sendPendingReply(false, {
{QStringLiteral("errorCode"), QStringLiteral("CANCELED")}
});
}
// aboutToHide is emitted before an action is triggered and activeAction() is
// the action currently hovered. This means we can't properly tell that the prompt
// got canceled, when hovering an action and then hitting Escape to close the menu.
// Hence delaying this and checking if an action got invoked :(
QMetaObject::invokeMethod(this, [this] {
if (!m_menu->property("actionInvoked").toBool()) {
sendPendingReply(false, {
{QStringLiteral("errorCode"), QStringLiteral("CANCELED")}
});
}
}, Qt::QueuedConnection);
});
connect(m_menu.data(), &QMenu::triggered, this, [this] {
m_menu->setProperty("actionInvoked", true);
});
connect(m_menu.data(), &Purpose::Menu::finished, this, [this](const QJsonObject &output, int errorCode, const QString &errorMessage) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment