]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinremoveaction.cpp
Add a SetFolderIcon ItemAction plugin
[dolphin.git] / src / dolphinremoveaction.cpp
1 /*
2 * SPDX-FileCopyrightText: 2013 Dawit Alemayehu <adawit@kde.org>
3 * SPDX-FileCopyrightText: 2017 Elvis Angelaccio <elvis.angelaccio@kde.org>
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 */
7
8 #include "dolphinremoveaction.h"
9
10 #include <QApplication>
11
12 DolphinRemoveAction::DolphinRemoveAction(QObject *parent, KActionCollection *collection)
13 : QAction(parent)
14 , m_collection(collection)
15 {
16 update();
17 connect(this, &DolphinRemoveAction::triggered, this, &DolphinRemoveAction::slotRemoveActionTriggered);
18 }
19
20 void DolphinRemoveAction::slotRemoveActionTriggered()
21 {
22 if (m_action) {
23 m_action->trigger();
24 }
25 }
26
27 void DolphinRemoveAction::update(ShiftState shiftState)
28 {
29 if (!m_collection) {
30 m_action = nullptr;
31 return;
32 }
33
34 if (shiftState == ShiftState::Unknown) {
35 shiftState = QGuiApplication::keyboardModifiers() & Qt::ShiftModifier ? ShiftState::Pressed : ShiftState::Released;
36 }
37
38 switch (shiftState) {
39 case ShiftState::Pressed: {
40 m_action = m_collection->action(KStandardAction::name(KStandardAction::DeleteFile));
41 // Make sure we show Shift+Del in the context menu.
42 auto deleteShortcuts = m_action->shortcuts();
43 deleteShortcuts.removeAll(Qt::SHIFT | Qt::Key_Delete);
44 deleteShortcuts.prepend(Qt::SHIFT | Qt::Key_Delete);
45 m_collection->setDefaultShortcuts(this, deleteShortcuts);
46 break;
47 }
48 case ShiftState::Released: {
49 m_action = m_collection->action(KStandardAction::name(KStandardAction::MoveToTrash));
50 // Make sure we show Del in the context menu.
51 auto trashShortcuts = m_action->shortcuts();
52 trashShortcuts.removeAll(QKeySequence::Delete);
53 trashShortcuts.prepend(QKeySequence::Delete);
54 m_collection->setDefaultShortcuts(this, trashShortcuts);
55 break;
56 }
57 case ShiftState::Unknown:
58 Q_UNREACHABLE();
59 break;
60 }
61
62 if (m_action) {
63 setText(m_action->text());
64 setIcon(m_action->icon());
65 setEnabled(m_action->isEnabled());
66 }
67 }
68
69 #include "moc_dolphinremoveaction.cpp"