]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/views/dolphinviewactionhandler.cpp
Fix scrolling during inline renaming causes rename of wrong file
[dolphin.git] / src / views / dolphinviewactionhandler.cpp
index 858f9299b96d22ebbd81f324661cec3f3ff895e0..10aae11ce6f30d6630cfe116614905184d3bc9f5 100644 (file)
@@ -37,6 +37,7 @@
 #include <KSelectAction>
 #include <KToggleAction>
 #include <KPropertiesDialog>
+#include <KProtocolManager>
 #include <QIcon>
 
 #include "dolphindebug.h"
@@ -106,27 +107,24 @@ void DolphinViewActionHandler::createActions()
 
     // 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);
-
-    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);
-
-    // 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
+    KStandardAction::renameFile(this, &DolphinViewActionHandler::slotRename, m_actionCollection);
+
+    auto trashAction = KStandardAction::moveToTrash(this, &DolphinViewActionHandler::slotTrashActivated, m_actionCollection);
+    auto trashShortcuts = trashAction->shortcuts();
+    if (!trashShortcuts.contains(QKeySequence::Delete)) {
+        trashShortcuts.append(QKeySequence::Delete);
+        m_actionCollection->setDefaultShortcuts(trashAction, trashShortcuts);
+    }
+
+    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 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.
     QAction* deleteWithTrashShortcut = m_actionCollection->addAction(QStringLiteral("delete_shortcut"));
@@ -157,11 +155,11 @@ void DolphinViewActionHandler::createActions()
     connect(viewModeActions, static_cast<void(KSelectAction::*)(QAction*)>(&KSelectAction::triggered), this, &DolphinViewActionHandler::slotViewModeActionTriggered);
 
     KStandardAction::zoomIn(this,
-                            SLOT(zoomIn()),
+                            &DolphinViewActionHandler::zoomIn,
                             m_actionCollection);
 
     KStandardAction::zoomOut(this,
-                             SLOT(zoomOut()),
+                             &DolphinViewActionHandler::zoomOut,
                              m_actionCollection);
 
     KToggleAction* showPreview = m_actionCollection->add<KToggleAction>(QStringLiteral("show_preview"));
@@ -481,12 +479,19 @@ void DolphinViewActionHandler::slotHiddenFilesShownChanged(bool shown)
     QAction* showHiddenFilesAction = m_actionCollection->action(QStringLiteral("show_hidden_files"));
     showHiddenFilesAction->setChecked(shown);
 
+    // #374508: don't overwrite custom icons.
+    const QString iconName = showHiddenFilesAction->icon().name();
+    if (!iconName.isEmpty() && iconName != QLatin1String("visibility") && iconName != QLatin1String("hint")) {
+        return;
+    }
+
     showHiddenFilesAction->setIcon(QIcon::fromTheme(shown ? QStringLiteral("visibility") : QStringLiteral("hint")));
 }
 
 void DolphinViewActionHandler::slotWriteStateChanged(bool isFolderWritable)
 {
-    m_actionCollection->action(QStringLiteral("create_dir"))->setEnabled(isFolderWritable);
+    m_actionCollection->action(QStringLiteral("create_dir"))->setEnabled(isFolderWritable &&
+                                                                         KProtocolManager::supportsMakeDir(currentView()->url()));
 }
 
 KToggleAction* DolphinViewActionHandler::iconsModeAction()