2020-08-25 17:07:38 +00:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: 2013 Dawit Alemayehu <adawit@kde.org>
|
|
|
|
* SPDX-FileCopyrightText: 2017 Elvis Angelaccio <elvis.angelaccio@kde.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2013-02-09 20:56:51 +00:00
|
|
|
|
|
|
|
#include "dolphinremoveaction.h"
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
2023-02-03 17:14:53 +00:00
|
|
|
DolphinRemoveAction::DolphinRemoveAction(QObject *parent, KActionCollection *collection)
|
|
|
|
: QAction(parent)
|
|
|
|
, m_collection(collection)
|
2013-02-09 20:56:51 +00:00
|
|
|
{
|
|
|
|
update();
|
2014-04-10 14:53:41 +00:00
|
|
|
connect(this, &DolphinRemoveAction::triggered, this, &DolphinRemoveAction::slotRemoveActionTriggered);
|
2013-02-09 20:56:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DolphinRemoveAction::slotRemoveActionTriggered()
|
|
|
|
{
|
|
|
|
if (m_action) {
|
|
|
|
m_action->trigger();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-24 16:33:27 +00:00
|
|
|
void DolphinRemoveAction::update(ShiftState shiftState)
|
2013-02-09 20:56:51 +00:00
|
|
|
{
|
2017-08-24 16:33:27 +00:00
|
|
|
if (!m_collection) {
|
|
|
|
m_action = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (shiftState == ShiftState::Unknown) {
|
|
|
|
shiftState = QGuiApplication::keyboardModifiers() & Qt::ShiftModifier ? ShiftState::Pressed : ShiftState::Released;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (shiftState) {
|
2017-09-17 09:56:42 +00:00
|
|
|
case ShiftState::Pressed: {
|
2017-08-24 16:33:27 +00:00
|
|
|
m_action = m_collection->action(KStandardAction::name(KStandardAction::DeleteFile));
|
2017-09-02 14:28:49 +00:00
|
|
|
// Make sure we show Shift+Del in the context menu.
|
|
|
|
auto deleteShortcuts = m_action->shortcuts();
|
|
|
|
deleteShortcuts.removeAll(Qt::SHIFT | Qt::Key_Delete);
|
|
|
|
deleteShortcuts.prepend(Qt::SHIFT | Qt::Key_Delete);
|
|
|
|
m_collection->setDefaultShortcuts(this, deleteShortcuts);
|
2017-08-24 16:33:27 +00:00
|
|
|
break;
|
2017-09-17 09:56:42 +00:00
|
|
|
}
|
2017-10-16 17:56:31 +00:00
|
|
|
case ShiftState::Released: {
|
2017-08-24 16:33:27 +00:00
|
|
|
m_action = m_collection->action(KStandardAction::name(KStandardAction::MoveToTrash));
|
2017-10-16 17:56:31 +00:00
|
|
|
// Make sure we show Del in the context menu.
|
|
|
|
auto trashShortcuts = m_action->shortcuts();
|
|
|
|
trashShortcuts.removeAll(QKeySequence::Delete);
|
|
|
|
trashShortcuts.prepend(QKeySequence::Delete);
|
|
|
|
m_collection->setDefaultShortcuts(this, trashShortcuts);
|
2017-08-24 16:33:27 +00:00
|
|
|
break;
|
2017-10-16 17:56:31 +00:00
|
|
|
}
|
2017-08-24 16:33:27 +00:00
|
|
|
case ShiftState::Unknown:
|
|
|
|
Q_UNREACHABLE();
|
|
|
|
break;
|
2013-02-09 20:56:51 +00:00
|
|
|
}
|
|
|
|
|
2013-06-22 12:04:45 +00:00
|
|
|
if (m_action) {
|
2017-08-09 21:15:30 +00:00
|
|
|
setText(m_action->text());
|
2013-02-09 20:56:51 +00:00
|
|
|
setIcon(m_action->icon());
|
2013-06-22 12:04:45 +00:00
|
|
|
setEnabled(m_action->isEnabled());
|
2013-02-09 20:56:51 +00:00
|
|
|
}
|
|
|
|
}
|
2023-07-04 20:07:48 +00:00
|
|
|
|
|
|
|
#include "moc_dolphinremoveaction.cpp"
|