]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/views/dolphinviewactionhandler.cpp
dolphinview: Fix right click broken on placeholderLabel
[dolphin.git] / src / views / dolphinviewactionhandler.cpp
index a66d1f6dda76abf97c08775b9623fbe4e26b8ec2..fc88f5c1790b742c985582cf0258d3dcc7826873 100644 (file)
@@ -7,12 +7,11 @@
 
 #include "dolphinviewactionhandler.h"
 
-#include "dolphindebug.h"
 #include "kitemviews/kfileitemlisttostring.h"
 #include "kitemviews/kfileitemmodel.h"
+#include "selectionmode/actiontexthelper.h"
 #include "settings/viewpropertiesdialog.h"
 #include "views/zoomlevelinfo.h"
-#include "kconfig_version.h"
 
 #if HAVE_BALOO
 #include <Baloo/IndexerConfig>
@@ -29,9 +28,7 @@
 #include <QMenu>
 #include <QPointer>
 
-#include <iostream>
-
-DolphinViewActionHandler::DolphinViewActionHandler(KActionCollection* collection, QObject* parent) :
+DolphinViewActionHandler::DolphinViewActionHandler(KActionCollection* collection, SelectionMode::ActionTextHelper* actionTextHelper, QObject* parent) :
     QObject(parent),
     m_actionCollection(collection),
     m_currentView(nullptr),
@@ -39,7 +36,7 @@ DolphinViewActionHandler::DolphinViewActionHandler(KActionCollection* collection
     m_visibleRoles()
 {
     Q_ASSERT(m_actionCollection);
-    createActions();
+    createActions(actionTextHelper);
 }
 
 void DolphinViewActionHandler::setCurrentView(DolphinView* view)
@@ -74,8 +71,8 @@ void DolphinViewActionHandler::setCurrentView(DolphinView* view)
             this, &DolphinViewActionHandler::slotZoomLevelChanged);
     connect(view, &DolphinView::writeStateChanged,
             this, &DolphinViewActionHandler::slotWriteStateChanged);
-    connect(view, &DolphinView::selectionModeRequested,
-            this, [this]() { Q_EMIT setSelectionMode(true); });
+    connect(view, &DolphinView::selectionModeChangeRequested,
+            this, [this](bool enabled) { Q_EMIT selectionModeChangeTriggered(enabled); });
     connect(view, &DolphinView::selectionChanged,
             this, &DolphinViewActionHandler::slotSelectionChanged);
     slotSelectionChanged(m_currentView->selectedItems());
@@ -86,7 +83,7 @@ DolphinView* DolphinViewActionHandler::currentView()
     return m_currentView;
 }
 
-void DolphinViewActionHandler::createActions()
+void DolphinViewActionHandler::createActions(SelectionMode::ActionTextHelper *actionTextHelper)
 {
     // This action doesn't appear in the GUI, it's for the shortcut only.
     // KNewFileMenu takes care of the GUI stuff.
@@ -166,6 +163,14 @@ void DolphinViewActionHandler::createActions()
     m_actionCollection->setDefaultShortcuts(copyPathAction, {Qt::CTRL | Qt::ALT | Qt::Key_C});
     connect(copyPathAction, &QAction::triggered, this, &DolphinViewActionHandler::slotCopyPath);
 
+    if (actionTextHelper) {
+        // The "…" at the end make clear that they won't trigger their respective actions directly.
+        actionTextHelper->registerTextWhenNothingIsSelected(trashAction, i18nc("@action:inmenu File", "Move to Trash…"));
+        actionTextHelper->registerTextWhenNothingIsSelected(deleteAction, i18nc("@action:inmenu File", "Delete…"));
+        actionTextHelper->registerTextWhenNothingIsSelected(duplicateAction, i18nc("@action:inmenu File", "Duplicate Here…"));
+        actionTextHelper->registerTextWhenNothingIsSelected(copyPathAction, i18nc("@action:incontextmenu", "Copy Location…"));
+    }
+
     // This menu makes sure that users who don't know how to open a context menu and haven't
     // figured out how to enable the menu bar can still perform basic file manipulation.
     // This only works if they know how to select a file.
@@ -428,32 +433,33 @@ void DolphinViewActionHandler::slotViewModeActionTriggered(QAction* action)
 void DolphinViewActionHandler::slotRename()
 {
     if (m_currentView->selectedItemsCount() == 0) {
-        Q_EMIT setSelectionMode(true, SelectionModeBottomBar::Contents::RenameContents);
+        Q_EMIT selectionModeChangeTriggered(true, SelectionMode::BottomBar::Contents::RenameContents);
     } else {
         Q_EMIT actionBeingHandled();
         m_currentView->renameSelectedItems();
+        // We don't exit selectionMode here because users might want to rename more items.
     }
 }
 
 void DolphinViewActionHandler::slotTrashActivated()
 {
     if (m_currentView->selectedItemsCount() == 0) {
-        Q_EMIT setSelectionMode(true, SelectionModeBottomBar::Contents::MoveToTrashContents);
+        Q_EMIT selectionModeChangeTriggered(true, SelectionMode::BottomBar::Contents::MoveToTrashContents);
     } else {
         Q_EMIT actionBeingHandled();
         m_currentView->trashSelectedItems();
-        Q_EMIT setSelectionMode(false);
+        Q_EMIT selectionModeChangeTriggered(false);
     }
 }
 
 void DolphinViewActionHandler::slotDeleteItems()
 {
     if (m_currentView->selectedItemsCount() == 0) {
-        Q_EMIT setSelectionMode(true, SelectionModeBottomBar::Contents::DeleteContents);
+        Q_EMIT selectionModeChangeTriggered(true, SelectionMode::BottomBar::Contents::DeleteContents);
     } else {
         Q_EMIT actionBeingHandled();
         m_currentView->deleteSelectedItems();
-        Q_EMIT setSelectionMode(false);
+        Q_EMIT selectionModeChangeTriggered(false);
     }
 }
 
@@ -754,11 +760,11 @@ void DolphinViewActionHandler::slotAdjustViewProperties()
 void DolphinViewActionHandler::slotDuplicate()
 {
     if (m_currentView->selectedItemsCount() == 0) {
-        Q_EMIT setSelectionMode(true, SelectionModeBottomBar::Contents::DuplicateContents);
+        Q_EMIT selectionModeChangeTriggered(true, SelectionMode::BottomBar::Contents::DuplicateContents);
     } else {
         Q_EMIT actionBeingHandled();
         m_currentView->duplicateSelectedItems();
-        Q_EMIT setSelectionMode(false);
+        Q_EMIT selectionModeChangeTriggered(false);
     }
 }
 
@@ -782,10 +788,10 @@ void DolphinViewActionHandler::slotProperties()
 void DolphinViewActionHandler::slotCopyPath()
 {
     if (m_currentView->selectedItemsCount() == 0) {
-        Q_EMIT setSelectionMode(true, SelectionModeBottomBar::Contents::CopyLocationContents);
+        Q_EMIT selectionModeChangeTriggered(true, SelectionMode::BottomBar::Contents::CopyLocationContents);
     } else {
         m_currentView->copyPathToClipboard();
-        Q_EMIT setSelectionMode(false);
+        Q_EMIT selectionModeChangeTriggered(false);
     }
 }