Changeset View
Changeset View
Standalone View
Standalone View
src/dolphinremoveaction.cpp
1 | /*************************************************************************** | 1 | /*************************************************************************** | ||
---|---|---|---|---|---|
2 | * Copyright (C) 2013 by Dawit Alemayehu <adawit@kde.org * | 2 | * Copyright (C) 2013 by Dawit Alemayehu <adawit@kde.org> * | ||
3 | * Copyright (C) 2017 by Elvis Angelaccio <elvis.angelaccio@kde.org> * | ||||
3 | * * | 4 | * * | ||
4 | * This program is free software; you can redistribute it and/or modify * | 5 | * This program is free software; you can redistribute it and/or modify * | ||
5 | * it under the terms of the GNU General Public License as published by * | 6 | * it under the terms of the GNU General Public License as published by * | ||
6 | * the Free Software Foundation; either version 2 of the License, or * | 7 | * the Free Software Foundation; either version 2 of the License, or * | ||
7 | * (at your option) any later version. * | 8 | * (at your option) any later version. * | ||
8 | * * | 9 | * * | ||
9 | * This program is distributed in the hope that it will be useful, * | 10 | * This program is distributed in the hope that it will be useful, * | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
Show All 23 Lines | |||||
34 | 35 | | |||
35 | void DolphinRemoveAction::slotRemoveActionTriggered() | 36 | void DolphinRemoveAction::slotRemoveActionTriggered() | ||
36 | { | 37 | { | ||
37 | if (m_action) { | 38 | if (m_action) { | ||
38 | m_action->trigger(); | 39 | m_action->trigger(); | ||
39 | } | 40 | } | ||
40 | } | 41 | } | ||
41 | 42 | | |||
42 | void DolphinRemoveAction::update() | 43 | void DolphinRemoveAction::update(ShiftState shiftState) | ||
43 | { | 44 | { | ||
44 | Q_ASSERT(m_collection); | 45 | if (!m_collection) { | ||
45 | if (qApp->queryKeyboardModifiers() & Qt::ShiftModifier) { | 46 | m_action = nullptr; | ||
46 | m_action = m_collection ? m_collection->action(KStandardAction::name(KStandardAction::DeleteFile)) : 0; | 47 | return; | ||
47 | } else { | 48 | } | ||
48 | m_action = m_collection ? m_collection->action(KStandardAction::name(KStandardAction::MoveToTrash)) : 0; | 49 | | ||
50 | if (shiftState == ShiftState::Unknown) { | ||||
51 | shiftState = QGuiApplication::keyboardModifiers() & Qt::ShiftModifier ? ShiftState::Pressed : ShiftState::Released; | ||||
52 | } | ||||
53 | | ||||
54 | switch (shiftState) { | ||||
55 | case ShiftState::Pressed: | ||||
56 | m_action = m_collection->action(KStandardAction::name(KStandardAction::DeleteFile)); | ||||
57 | break; | ||||
emmanuelp: I would perform the resolving before the switch (by updating `shiftState`) to avoid the… | |||||
58 | case ShiftState::Released: | ||||
59 | m_action = m_collection->action(KStandardAction::name(KStandardAction::MoveToTrash)); | ||||
60 | break; | ||||
61 | case ShiftState::Unknown: | ||||
62 | Q_UNREACHABLE(); | ||||
63 | break; | ||||
49 | } | 64 | } | ||
50 | 65 | | |||
51 | if (m_action) { | 66 | if (m_action) { | ||
52 | setText(m_action->text()); | 67 | setText(m_action->text()); | ||
53 | setIcon(m_action->icon()); | 68 | setIcon(m_action->icon()); | ||
54 | m_collection->setDefaultShortcuts(this, m_action->shortcuts()); | 69 | m_collection->setDefaultShortcuts(this, m_action->shortcuts()); | ||
55 | setEnabled(m_action->isEnabled()); | 70 | setEnabled(m_action->isEnabled()); | ||
56 | } | 71 | } | ||
57 | } | 72 | } |
I would perform the resolving before the switch (by updating shiftState) to avoid the duplicated state/modifiers<->action mapping and instead add an unreachable assertion to the QueryShiftState case, but this is a matter of taste.