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 #include <KLocalizedString>
28 DolphinRemoveAction::DolphinRemoveAction(QObject
* parent
, KActionCollection
* collection
) :
30 m_collection(collection
)
33 connect(this, &DolphinRemoveAction::triggered
, this, &DolphinRemoveAction::slotRemoveActionTriggered
);
36 void DolphinRemoveAction::slotRemoveActionTriggered()
43 void DolphinRemoveAction::update(ShiftState shiftState
)
50 if (shiftState
== ShiftState::Unknown
) {
51 shiftState
= QGuiApplication::keyboardModifiers() & Qt::ShiftModifier
? ShiftState::Pressed
: ShiftState::Released
;
55 case ShiftState::Pressed
: {
56 m_action
= m_collection
->action(KStandardAction::name(KStandardAction::DeleteFile
));
57 // Make sure we show Shift+Del in the context menu.
58 auto deleteShortcuts
= m_action
->shortcuts();
59 deleteShortcuts
.removeAll(Qt::SHIFT
| Qt::Key_Delete
);
60 deleteShortcuts
.prepend(Qt::SHIFT
| Qt::Key_Delete
);
61 m_collection
->setDefaultShortcuts(this, deleteShortcuts
);
64 case ShiftState::Released
:
65 m_action
= m_collection
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
66 m_collection
->setDefaultShortcuts(this, m_action
->shortcuts());
68 case ShiftState::Unknown
:
74 setText(m_action
->text());
75 setIcon(m_action
->icon());
76 setEnabled(m_action
->isEnabled());