]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Port to KStandardAction::DeleteFile
authorElvis Angelaccio <elvis.angelaccio@kde.org>
Fri, 10 Mar 2017 18:31:33 +0000 (19:31 +0100)
committerElvis Angelaccio <elvis.angelaccio@kde.org>
Mon, 13 Mar 2017 18:40:07 +0000 (19:40 +0100)
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

src/dolphincontextmenu.cpp
src/dolphinmainwindow.cpp
src/dolphinpart.cpp
src/dolphinremoveaction.cpp
src/dolphinremoveaction.h
src/views/dolphinviewactionhandler.cpp

index 58e2f4de5cb9aa67a9255b756574ab56d6a5f431..890494ff8ac7ac37ea13b9d9c566a569cfdc32b1 100644 (file)
@@ -172,7 +172,7 @@ void DolphinContextMenu::openTrashItemContextMenu()
     QAction* restoreAction = new QAction(i18nc("@action:inmenu", "Restore"), m_mainWindow);
     addAction(restoreAction);
 
     QAction* restoreAction = new QAction(i18nc("@action:inmenu", "Restore"), m_mainWindow);
     addAction(restoreAction);
 
-    QAction* deleteAction = m_mainWindow->actionCollection()->action(QStringLiteral("delete"));
+    QAction* deleteAction = m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::DeleteFile));
     addAction(deleteAction);
 
     QAction* propertiesAction = m_mainWindow->actionCollection()->action(QStringLiteral("properties"));
     addAction(deleteAction);
 
     QAction* propertiesAction = m_mainWindow->actionCollection()->action(QStringLiteral("properties"));
@@ -406,9 +406,9 @@ void DolphinContextMenu::insertDefaultItemActions(const KFileItemListProperties&
             delete m_removeAction;
             m_removeAction = 0;
             addAction(m_mainWindow->actionCollection()->action(QStringLiteral("move_to_trash")));
             delete m_removeAction;
             m_removeAction = 0;
             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 {
             if (!m_removeAction) {
                 m_removeAction = new DolphinRemoveAction(this, m_mainWindow->actionCollection());
         } else {
             if (!m_removeAction) {
                 m_removeAction = new DolphinRemoveAction(this, m_mainWindow->actionCollection());
index 431ecda443595ef8ed1fc054713f64dc97bbd2b4..de8601d4e96ad2bbe0bbd58c659bf11421d227c6 100644 (file)
@@ -1015,12 +1015,8 @@ void DolphinMainWindow::setupActions()
                           SLOT(undo()),
                           actionCollection());
 
                           SLOT(undo()),
                           actionCollection());
 
-    // need to remove shift+del from cut action, else the shortcut for deletejob
-    // doesn't work
-    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::cut(this, SLOT(cut()), actionCollection());
     KStandardAction::copy(this, SLOT(copy()), actionCollection());
     QAction* paste = KStandardAction::paste(this, SLOT(paste()), actionCollection());
     // The text of the paste-action is modified dynamically by Dolphin
     KStandardAction::copy(this, SLOT(copy()), actionCollection());
     QAction* paste = KStandardAction::paste(this, SLOT(paste()), actionCollection());
     // The text of the paste-action is modified dynamically by Dolphin
@@ -1316,7 +1312,7 @@ void DolphinMainWindow::updateEditActions()
         KActionCollection* col = actionCollection();
         QAction* renameAction      = col->action(QStringLiteral("rename"));
         QAction* moveToTrashAction = col->action(QStringLiteral("move_to_trash"));
         KActionCollection* col = actionCollection();
         QAction* renameAction      = col->action(QStringLiteral("rename"));
         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* deleteWithTrashShortcut = col->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
 
         QAction* cutAction         = col->action(KStandardAction::name(KStandardAction::Cut));
         QAction* deleteWithTrashShortcut = col->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
 
index b55bcabb25e9eeb1315eabf5dbe314f4f26397ff..352e9a44faf241a63526891b600876871a9c6e45 100644 (file)
@@ -255,7 +255,7 @@ void DolphinPart::slotSelectionChanged(const KFileItemList& selection)
 
     QAction* renameAction  = actionCollection()->action(QStringLiteral("rename"));
     QAction* moveToTrashAction = actionCollection()->action(QStringLiteral("move_to_trash"));
 
     QAction* renameAction  = actionCollection()->action(QStringLiteral("rename"));
     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* propertiesAction = actionCollection()->action(QStringLiteral("properties"));
     QAction* deleteWithTrashShortcut = actionCollection()->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
     QAction* editMimeTypeAction = actionCollection()->action(QStringLiteral("editMimeType"));
     QAction* propertiesAction = actionCollection()->action(QStringLiteral("properties"));
     QAction* deleteWithTrashShortcut = actionCollection()->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
@@ -433,9 +433,9 @@ void DolphinPart::slotOpenContextMenu(const QPoint& pos,
                 delete m_removeAction;
                 m_removeAction = 0;
                 editActions.append(actionCollection()->action(QStringLiteral("move_to_trash")));
                 delete m_removeAction;
                 m_removeAction = 0;
                 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 {
                 if (!m_removeAction)
                     m_removeAction = new DolphinRemoveAction(this, actionCollection());
             } else {
                 if (!m_removeAction)
                     m_removeAction = new DolphinRemoveAction(this, actionCollection());
index 10ab25112a7ecd2587de1bf89fcfa05c0722a625..ad00f6286ef5843a8a1562315212479e1433c940 100644 (file)
@@ -46,7 +46,7 @@ void DolphinRemoveAction::update()
     // 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) {
     // 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(QStringLiteral("delete")) : 0;
+        m_action = m_collection ? m_collection->action(KStandardAction::name(KStandardAction::DeleteFile)) : 0;
         setText(i18nc("@action:inmenu", "&Delete"));
     } else {
         m_action = m_collection ? m_collection->action(QStringLiteral("move_to_trash")) : 0;
         setText(i18nc("@action:inmenu", "&Delete"));
     } else {
         m_action = m_collection ? m_collection->action(QStringLiteral("move_to_trash")) : 0;
index 85f404318b74da575ba954d5110c5f7e9b7107b7..fd8fc35d664a8369419c5c5394de29930d150a4d 100644 (file)
@@ -31,8 +31,8 @@
  * A QAction that manages the delete based on the current state of
  * the Shift key or the parameter passed to update.
  *
  * A QAction that manages the delete based on the current state of
  * the Shift key or the parameter passed to update.
  *
- * This class expects the presence of both the "move_to_trash" and "delete"
- * actions in @ref collection.
+ * This class expects the presence of both the "move_to_trash" and
+ * KStandardAction::DeleteFile actions in @ref collection.
  */
 class DOLPHIN_EXPORT DolphinRemoveAction : public QAction
 {
  */
 class DOLPHIN_EXPORT DolphinRemoveAction : public QAction
 {
index 273bcdd76a1046277424045c0c5ebd25e42aa9e2..7e52d5b284b76f90ae1ab8944e7f2895e45b3f4c 100644 (file)
@@ -120,14 +120,10 @@ void DolphinViewActionHandler::createActions()
     connect(moveToTrash, &QAction::triggered,
             this, &DolphinViewActionHandler::slotTrashActivated);
 
     connect(moveToTrash, &QAction::triggered,
             this, &DolphinViewActionHandler::slotTrashActivated);
 
-    QAction* deleteAction = m_actionCollection->addAction(QStringLiteral("delete"));
-    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);
+    KStandardAction::deleteFile(this, &DolphinViewActionHandler::slotDeleteItems, m_actionCollection);
 
     // 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
     // so that the Edit menu isn't affected.
     QAction* deleteWithTrashShortcut = m_actionCollection->addAction(QStringLiteral("delete_shortcut"));
     // can be used for deleting the file (#76016). It needs to be a separate action
     // so that the Edit menu isn't affected.
     QAction* deleteWithTrashShortcut = m_actionCollection->addAction(QStringLiteral("delete_shortcut"));