]>
cloud.milkyroute.net Git - dolphin.git/blob - src/disabledactionnotifier.cpp
2 * SPDX-FileCopyrightText: 2024 Jin Liu <m.liu.jin@gmail.com>
4 * SPDX-License-Identifier: GPL-2.0-or-later
7 #include "disabledactionnotifier.h"
9 DisabledActionNotifier::DisabledActionNotifier(QObject
*parent
)
14 void DisabledActionNotifier::setDisabledReason(QAction
*action
, QStringView reason
)
16 if (action
->isEnabled()) {
20 if (m_shortcuts
.contains(action
)) {
21 m_shortcuts
.take(action
)->deleteLater();
24 QShortcut
*shortcut
= new QShortcut(action
->shortcut(), parent());
25 m_shortcuts
.insert(action
, shortcut
);
27 connect(action
, &QAction::enabledChanged
, this, [this, action
](bool enabled
) {
29 m_shortcuts
.take(action
)->deleteLater();
33 // Don't capture QStringView, as it may reference a temporary QString
34 QString reasonString
= reason
.toString();
35 connect(shortcut
, &QShortcut::activated
, this, [this, action
, reasonString
]() {
36 Q_EMIT
disabledActionTriggered(action
, reasonString
);
40 void DisabledActionNotifier::clearDisabledReason(QAction
*action
)
42 if (action
->isEnabled()) {
46 if (m_shortcuts
.contains(action
)) {
47 m_shortcuts
.take(action
)->deleteLater();
51 #include "moc_disabledactionnotifier.cpp"