}
}
-void DolphinRemoveAction::update()
+void DolphinRemoveAction::update(ShiftState shiftState)
{
- Q_ASSERT(m_collection);
- // Using setText(action->text()) does not apply the &-shortcut.
- // This is only done until the original action has been shown at least once. To
- // bypass this issue, the text and &-shortcut is applied manually.
- if (qApp->queryKeyboardModifiers() & Qt::ShiftModifier) {
- m_action = m_collection ? m_collection->action(KStandardAction::name(KStandardAction::DeleteFile)) : 0;
- setText(i18nc("@action:inmenu", "&Delete"));
+ 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:
++ case ShiftState::Pressed: {
+ m_action = m_collection->action(KStandardAction::name(KStandardAction::DeleteFile));
+ // Make sure we show Shift+Del in the context menu.
+ auto deleteShortcuts = m_action->shortcuts();
+ deleteShortcuts.removeAll(Qt::SHIFT | Qt::Key_Delete);
+ deleteShortcuts.prepend(Qt::SHIFT | Qt::Key_Delete);
+ m_collection->setDefaultShortcuts(this, deleteShortcuts);
- } else {
- m_action = m_collection ? m_collection->action(QStringLiteral("move_to_trash")) : 0;
- setText(i18nc("@action:inmenu", "&Move to Trash"));
+ break;
++ }
+ case ShiftState::Released:
+ m_action = m_collection->action(KStandardAction::name(KStandardAction::MoveToTrash));
+ m_collection->setDefaultShortcuts(this, m_action->shortcuts());
+ break;
+ case ShiftState::Unknown:
+ Q_UNREACHABLE();
+ break;
}
if (m_action) {
+ setText(m_action->text());
setIcon(m_action->icon());
- m_collection->setDefaultShortcuts(this, m_action->shortcuts());
setEnabled(m_action->isEnabled());
}
}
// File menu
- QAction* rename = m_actionCollection->addAction(QStringLiteral("rename"));
- rename->setText(i18nc("@action:inmenu File", "Rename..."));
- m_actionCollection->setDefaultShortcut(rename, Qt::Key_F2);
- rename->setIcon(QIcon::fromTheme(QStringLiteral("edit-rename")));
- connect(rename, &QAction::triggered, this, &DolphinViewActionHandler::slotRename);
-
- QAction* moveToTrash = m_actionCollection->addAction(QStringLiteral("move_to_trash"));
- moveToTrash->setText(i18nc("@action:inmenu File", "Move to Trash"));
- moveToTrash->setIcon(QIcon::fromTheme(QStringLiteral("user-trash")));
- m_actionCollection->setDefaultShortcut(moveToTrash, QKeySequence::Delete);
- connect(moveToTrash, &QAction::triggered,
- this, &DolphinViewActionHandler::slotTrashActivated);
+ KStandardAction::renameFile(this, &DolphinViewActionHandler::slotRename, m_actionCollection);
- KStandardAction::deleteFile(this, &DolphinViewActionHandler::slotDeleteItems, m_actionCollection);
+ KStandardAction::moveToTrash(this, &DolphinViewActionHandler::slotTrashActivated, m_actionCollection);
+ auto deleteAction = KStandardAction::deleteFile(this, &DolphinViewActionHandler::slotDeleteItems, m_actionCollection);
+ auto deleteShortcuts = deleteAction->shortcuts();
+ if (!deleteShortcuts.contains(Qt::SHIFT | Qt::Key_Delete)) {
+ deleteShortcuts.append(Qt::SHIFT | Qt::Key_Delete);
+ m_actionCollection->setDefaultShortcuts(deleteAction, deleteShortcuts);
+ }
- // This action is useful for being enabled when "move_to_trash" should be
+ // This action is useful for being enabled when KStandardAction::MoveToTrash should be
// disabled and KStandardAction::DeleteFile is enabled (e.g. non-local files), so that Key_Del
// can be used for deleting the file (#76016). It needs to be a separate action
// so that the Edit menu isn't affected.