mirror of
https://invent.kde.org/system/dolphin
synced 2024-11-05 18:47:12 +00:00
Port to KStandardAction::DeleteFile
Summary: It was introduced in kconfig 5.25 and it properly handles the shift+del shortcut (together with kxmlgui >= 5.30). This allows us to drop the custom delete shortcut as well as the shift+del workaround in DolphinMainWindow. Test Plan: Shift+Del still deletes files, without the 'ambiguous shortcut' warning dialog. Reviewers: emmanuelp Differential Revision: https://phabricator.kde.org/D5010
This commit is contained in:
parent
042b0c8409
commit
68bb0ec22a
6 changed files with 14 additions and 22 deletions
|
@ -172,7 +172,7 @@ void DolphinContextMenu::openTrashItemContextMenu()
|
||||||
QAction* restoreAction = new QAction(i18nc("@action:inmenu", "Restore"), m_mainWindow);
|
QAction* restoreAction = new QAction(i18nc("@action:inmenu", "Restore"), m_mainWindow);
|
||||||
addAction(restoreAction);
|
addAction(restoreAction);
|
||||||
|
|
||||||
QAction* deleteAction = m_mainWindow->actionCollection()->action(QStringLiteral("delete"));
|
QAction* deleteAction = m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::DeleteFile));
|
||||||
addAction(deleteAction);
|
addAction(deleteAction);
|
||||||
|
|
||||||
QAction* propertiesAction = m_mainWindow->actionCollection()->action(QStringLiteral("properties"));
|
QAction* propertiesAction = m_mainWindow->actionCollection()->action(QStringLiteral("properties"));
|
||||||
|
@ -406,9 +406,9 @@ void DolphinContextMenu::insertDefaultItemActions(const KFileItemListProperties&
|
||||||
delete m_removeAction;
|
delete m_removeAction;
|
||||||
m_removeAction = 0;
|
m_removeAction = 0;
|
||||||
addAction(m_mainWindow->actionCollection()->action(QStringLiteral("move_to_trash")));
|
addAction(m_mainWindow->actionCollection()->action(QStringLiteral("move_to_trash")));
|
||||||
addAction(m_mainWindow->actionCollection()->action(QStringLiteral("delete")));
|
addAction(m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::DeleteFile)));
|
||||||
} else if (showDeleteAction && !showMoveToTrashAction) {
|
} else if (showDeleteAction && !showMoveToTrashAction) {
|
||||||
addAction(m_mainWindow->actionCollection()->action(QStringLiteral("delete")));
|
addAction(m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::DeleteFile)));
|
||||||
} else {
|
} else {
|
||||||
if (!m_removeAction) {
|
if (!m_removeAction) {
|
||||||
m_removeAction = new DolphinRemoveAction(this, m_mainWindow->actionCollection());
|
m_removeAction = new DolphinRemoveAction(this, m_mainWindow->actionCollection());
|
||||||
|
|
|
@ -1015,12 +1015,8 @@ void DolphinMainWindow::setupActions()
|
||||||
SLOT(undo()),
|
SLOT(undo()),
|
||||||
actionCollection());
|
actionCollection());
|
||||||
|
|
||||||
// need to remove shift+del from cut action, else the shortcut for deletejob
|
|
||||||
// doesn't work
|
KStandardAction::cut(this, SLOT(cut()), actionCollection());
|
||||||
QAction* cut = KStandardAction::cut(this, SLOT(cut()), actionCollection());
|
|
||||||
auto cutShortcuts = cut->shortcuts();
|
|
||||||
cutShortcuts.removeAll(QKeySequence(Qt::SHIFT | Qt::Key_Delete));
|
|
||||||
actionCollection()->setDefaultShortcuts(cut, cutShortcuts);
|
|
||||||
KStandardAction::copy(this, SLOT(copy()), actionCollection());
|
KStandardAction::copy(this, SLOT(copy()), actionCollection());
|
||||||
QAction* paste = KStandardAction::paste(this, SLOT(paste()), actionCollection());
|
QAction* paste = KStandardAction::paste(this, SLOT(paste()), actionCollection());
|
||||||
// The text of the paste-action is modified dynamically by Dolphin
|
// The text of the paste-action is modified dynamically by Dolphin
|
||||||
|
@ -1316,7 +1312,7 @@ void DolphinMainWindow::updateEditActions()
|
||||||
KActionCollection* col = actionCollection();
|
KActionCollection* col = actionCollection();
|
||||||
QAction* renameAction = col->action(QStringLiteral("rename"));
|
QAction* renameAction = col->action(QStringLiteral("rename"));
|
||||||
QAction* moveToTrashAction = col->action(QStringLiteral("move_to_trash"));
|
QAction* moveToTrashAction = col->action(QStringLiteral("move_to_trash"));
|
||||||
QAction* deleteAction = col->action(QStringLiteral("delete"));
|
QAction* deleteAction = col->action(KStandardAction::name(KStandardAction::DeleteFile));
|
||||||
QAction* cutAction = col->action(KStandardAction::name(KStandardAction::Cut));
|
QAction* cutAction = col->action(KStandardAction::name(KStandardAction::Cut));
|
||||||
QAction* deleteWithTrashShortcut = col->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
|
QAction* deleteWithTrashShortcut = col->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
|
||||||
|
|
||||||
|
|
|
@ -255,7 +255,7 @@ void DolphinPart::slotSelectionChanged(const KFileItemList& selection)
|
||||||
|
|
||||||
QAction* renameAction = actionCollection()->action(QStringLiteral("rename"));
|
QAction* renameAction = actionCollection()->action(QStringLiteral("rename"));
|
||||||
QAction* moveToTrashAction = actionCollection()->action(QStringLiteral("move_to_trash"));
|
QAction* moveToTrashAction = actionCollection()->action(QStringLiteral("move_to_trash"));
|
||||||
QAction* deleteAction = actionCollection()->action(QStringLiteral("delete"));
|
QAction* deleteAction = actionCollection()->action(KStandardAction::name(KStandardAction::DeleteFile));
|
||||||
QAction* editMimeTypeAction = actionCollection()->action(QStringLiteral("editMimeType"));
|
QAction* editMimeTypeAction = actionCollection()->action(QStringLiteral("editMimeType"));
|
||||||
QAction* propertiesAction = actionCollection()->action(QStringLiteral("properties"));
|
QAction* propertiesAction = actionCollection()->action(QStringLiteral("properties"));
|
||||||
QAction* deleteWithTrashShortcut = actionCollection()->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
|
QAction* deleteWithTrashShortcut = actionCollection()->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
|
||||||
|
@ -433,9 +433,9 @@ void DolphinPart::slotOpenContextMenu(const QPoint& pos,
|
||||||
delete m_removeAction;
|
delete m_removeAction;
|
||||||
m_removeAction = 0;
|
m_removeAction = 0;
|
||||||
editActions.append(actionCollection()->action(QStringLiteral("move_to_trash")));
|
editActions.append(actionCollection()->action(QStringLiteral("move_to_trash")));
|
||||||
editActions.append(actionCollection()->action(QStringLiteral("delete")));
|
editActions.append(actionCollection()->action(KStandardAction::name(KStandardAction::DeleteFile)));
|
||||||
} else if (showDeleteAction && !showMoveToTrashAction) {
|
} else if (showDeleteAction && !showMoveToTrashAction) {
|
||||||
editActions.append(actionCollection()->action(QStringLiteral("delete")));
|
editActions.append(actionCollection()->action(KStandardAction::name(KStandardAction::DeleteFile)));
|
||||||
} else {
|
} else {
|
||||||
if (!m_removeAction)
|
if (!m_removeAction)
|
||||||
m_removeAction = new DolphinRemoveAction(this, actionCollection());
|
m_removeAction = new DolphinRemoveAction(this, actionCollection());
|
||||||
|
|
|
@ -46,7 +46,7 @@ void DolphinRemoveAction::update()
|
||||||
// This is only done until the original action has been shown at least once. To
|
// 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.
|
// bypass this issue, the text and &-shortcut is applied manually.
|
||||||
if (qApp->queryKeyboardModifiers() & Qt::ShiftModifier) {
|
if (qApp->queryKeyboardModifiers() & Qt::ShiftModifier) {
|
||||||
m_action = m_collection ? m_collection->action(QStringLiteral("delete")) : 0;
|
m_action = m_collection ? m_collection->action(KStandardAction::name(KStandardAction::DeleteFile)) : 0;
|
||||||
setText(i18nc("@action:inmenu", "&Delete"));
|
setText(i18nc("@action:inmenu", "&Delete"));
|
||||||
} else {
|
} else {
|
||||||
m_action = m_collection ? m_collection->action(QStringLiteral("move_to_trash")) : 0;
|
m_action = m_collection ? m_collection->action(QStringLiteral("move_to_trash")) : 0;
|
||||||
|
|
|
@ -31,8 +31,8 @@
|
||||||
* A QAction that manages the delete based on the current state of
|
* A QAction that manages the delete based on the current state of
|
||||||
* the Shift key or the parameter passed to update.
|
* the Shift key or the parameter passed to update.
|
||||||
*
|
*
|
||||||
* This class expects the presence of both the "move_to_trash" and "delete"
|
* This class expects the presence of both the "move_to_trash" and
|
||||||
* actions in @ref collection.
|
* KStandardAction::DeleteFile actions in @ref collection.
|
||||||
*/
|
*/
|
||||||
class DOLPHIN_EXPORT DolphinRemoveAction : public QAction
|
class DOLPHIN_EXPORT DolphinRemoveAction : public QAction
|
||||||
{
|
{
|
||||||
|
|
|
@ -120,14 +120,10 @@ void DolphinViewActionHandler::createActions()
|
||||||
connect(moveToTrash, &QAction::triggered,
|
connect(moveToTrash, &QAction::triggered,
|
||||||
this, &DolphinViewActionHandler::slotTrashActivated);
|
this, &DolphinViewActionHandler::slotTrashActivated);
|
||||||
|
|
||||||
QAction* deleteAction = m_actionCollection->addAction(QStringLiteral("delete"));
|
KStandardAction::deleteFile(this, &DolphinViewActionHandler::slotDeleteItems, m_actionCollection);
|
||||||
deleteAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-delete")));
|
|
||||||
deleteAction->setText(i18nc("@action:inmenu File", "Delete"));
|
|
||||||
m_actionCollection->setDefaultShortcut(deleteAction, Qt::SHIFT | Qt::Key_Delete);
|
|
||||||
connect(deleteAction, &QAction::triggered, this, &DolphinViewActionHandler::slotDeleteItems);
|
|
||||||
|
|
||||||
// This action is useful for being enabled when "move_to_trash" should be
|
// This action is useful for being enabled when "move_to_trash" should be
|
||||||
// disabled and "delete" is enabled (e.g. non-local files), so that Key_Del
|
// 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
|
// can be used for deleting the file (#76016). It needs to be a separate action
|
||||||
// so that the Edit menu isn't affected.
|
// so that the Edit menu isn't affected.
|
||||||
QAction* deleteWithTrashShortcut = m_actionCollection->addAction(QStringLiteral("delete_shortcut"));
|
QAction* deleteWithTrashShortcut = m_actionCollection->addAction(QStringLiteral("delete_shortcut"));
|
||||||
|
|
Loading…
Reference in a new issue