1 /***************************************************************************
2 * Copyright (C) 2013 by Dawit Alemayehu <adawit@kde.org> *
3 * Copyright (C) 2017 by Elvis Angelaccio <elvis.angelaccio@kde.org> *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
21 #include "dolphinremoveaction.h"
23 #include <QApplication>
25 DolphinRemoveAction::DolphinRemoveAction(QObject
* parent
, KActionCollection
* collection
) :
27 m_collection(collection
)
30 connect(this, &DolphinRemoveAction::triggered
, this, &DolphinRemoveAction::slotRemoveActionTriggered
);
33 void DolphinRemoveAction::slotRemoveActionTriggered()
40 void DolphinRemoveAction::update(ShiftState shiftState
)
47 if (shiftState
== ShiftState::Unknown
) {
48 shiftState
= QGuiApplication::keyboardModifiers() & Qt::ShiftModifier
? ShiftState::Pressed
: ShiftState::Released
;
52 case ShiftState::Pressed
: {
53 m_action
= m_collection
->action(KStandardAction::name(KStandardAction::DeleteFile
));
54 // Make sure we show Shift+Del in the context menu.
55 auto deleteShortcuts
= m_action
->shortcuts();
56 deleteShortcuts
.removeAll(Qt::SHIFT
| Qt::Key_Delete
);
57 deleteShortcuts
.prepend(Qt::SHIFT
| Qt::Key_Delete
);
58 m_collection
->setDefaultShortcuts(this, deleteShortcuts
);
61 case ShiftState::Released
: {
62 m_action
= m_collection
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
63 // Make sure we show Del in the context menu.
64 auto trashShortcuts
= m_action
->shortcuts();
65 trashShortcuts
.removeAll(QKeySequence::Delete
);
66 trashShortcuts
.prepend(QKeySequence::Delete
);
67 m_collection
->setDefaultShortcuts(this, trashShortcuts
);
70 case ShiftState::Unknown
:
76 setText(m_action
->text());
77 setIcon(m_action
->icon());
78 setEnabled(m_action
->isEnabled());