diff --git a/src/dolphincontextmenu.cpp b/src/dolphincontextmenu.cpp --- a/src/dolphincontextmenu.cpp +++ b/src/dolphincontextmenu.cpp @@ -124,15 +124,15 @@ void DolphinContextMenu::keyPressEvent(QKeyEvent *ev) { if (m_removeAction && ev->key() == Qt::Key_Shift) { - m_removeAction->update(); + m_removeAction->update(DolphinRemoveAction::ShiftState::Pressed); } QMenu::keyPressEvent(ev); } void DolphinContextMenu::keyReleaseEvent(QKeyEvent *ev) { if (m_removeAction && ev->key() == Qt::Key_Shift) { - m_removeAction->update(); + m_removeAction->update(DolphinRemoveAction::ShiftState::Released); } QMenu::keyReleaseEvent(ev); } diff --git a/src/dolphinpart.cpp b/src/dolphinpart.cpp --- a/src/dolphinpart.cpp +++ b/src/dolphinpart.cpp @@ -597,14 +597,15 @@ bool DolphinPart::eventFilter(QObject* obj, QEvent* event) { + using ShiftState = DolphinRemoveAction::ShiftState; const int type = event->type(); if ((type == QEvent::KeyPress || type == QEvent::KeyRelease) && m_removeAction) { QMenu* menu = qobject_cast(obj); if (menu && menu->parent() == m_view) { QKeyEvent* ev = static_cast(event); if (ev->key() == Qt::Key_Shift) { - m_removeAction->update(); + m_removeAction->update(type == QEvent::KeyPress ? ShiftState::Pressed : ShiftState::Released); } } } diff --git a/src/dolphinremoveaction.h b/src/dolphinremoveaction.h --- a/src/dolphinremoveaction.h +++ b/src/dolphinremoveaction.h @@ -1,5 +1,6 @@ /*************************************************************************** - * Copyright (C) 2013 by Dawit Alemayehu * + * Copyright (C) 2017 by Elvis Angelaccio * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -38,11 +39,20 @@ { Q_OBJECT public: + + enum class ShiftState { + Unknown, + Pressed, + Released + }; + DolphinRemoveAction(QObject* parent, KActionCollection* collection); + /** - * Updates this action key based on the state of the Shift key. + * Updates this action key based on @p shiftState. + * Default value is QueryShiftState, meaning it will query QGuiApplication::modifiers(). */ - void update(); + void update(ShiftState shiftState = ShiftState::Unknown); private Q_SLOTS: void slotRemoveActionTriggered(); diff --git a/src/dolphinremoveaction.cpp b/src/dolphinremoveaction.cpp --- a/src/dolphinremoveaction.cpp +++ b/src/dolphinremoveaction.cpp @@ -1,5 +1,6 @@ /*************************************************************************** - * Copyright (C) 2013 by Dawit Alemayehu * + * Copyright (C) 2017 by Elvis Angelaccio * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -39,13 +40,27 @@ } } -void DolphinRemoveAction::update() +void DolphinRemoveAction::update(ShiftState shiftState) { - Q_ASSERT(m_collection); - if (qApp->queryKeyboardModifiers() & Qt::ShiftModifier) { - m_action = m_collection ? m_collection->action(KStandardAction::name(KStandardAction::DeleteFile)) : 0; - } else { - m_action = m_collection ? m_collection->action(KStandardAction::name(KStandardAction::MoveToTrash)) : 0; + if (!m_collection) { + m_action = nullptr; + return; + } + + if (shiftState == ShiftState::Unknown) { + shiftState = QGuiApplication::keyboardModifiers() & Qt::ShiftModifier ? ShiftState::Pressed : ShiftState::Released; + } + + switch (shiftState) { + case ShiftState::Pressed: + m_action = m_collection->action(KStandardAction::name(KStandardAction::DeleteFile)); + break; + case ShiftState::Released: + m_action = m_collection->action(KStandardAction::name(KStandardAction::MoveToTrash)); + break; + case ShiftState::Unknown: + Q_UNREACHABLE(); + break; } if (m_action) {