]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/views/dolphinviewactionhandler.cpp
Use cmakedefine01
[dolphin.git] / src / views / dolphinviewactionhandler.cpp
index 25b7f82cb69e6b7efb3cb0e2e011544b431d1a3f..f59daab424865e07fe9d6067ec46b0dc03e388f7 100644 (file)
@@ -1,40 +1,31 @@
-/***************************************************************************
- *   Copyright (C) 2008 by David Faure <faure@kde.org>                     *
- *   Copyright (C) 2012 by Peter Penz <peter.penz19@gmail.com>             *
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- *   This program is distributed in the hope that it will be useful,       *
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
- *   GNU General Public License for more details.                          *
- *                                                                         *
- *   You should have received a copy of the GNU General Public License     *
- *   along with this program; if not, write to the                         *
- *   Free Software Foundation, Inc.,                                       *
- *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
- ***************************************************************************/
+/*
+ * SPDX-FileCopyrightText: 2008 David Faure <faure@kde.org>
+ * SPDX-FileCopyrightText: 2012 Peter Penz <peter.penz19@gmail.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
 
 #include "dolphinviewactionhandler.h"
 
 #include "dolphindebug.h"
+#include "kitemviews/kfileitemlisttostring.h"
 #include "kitemviews/kfileitemmodel.h"
 #include "settings/viewpropertiesdialog.h"
 #include "views/zoomlevelinfo.h"
+#include "kconfig_version.h"
 
-#ifdef HAVE_BALOO
+#if HAVE_BALOO
 #include <Baloo/IndexerConfig>
 #endif
 #include <KActionCollection>
 #include <KActionMenu>
+#include <KFileItemListProperties>
 #include <KLocalizedString>
 #include <KNewFileMenu>
 #include <KPropertiesDialog>
 #include <KProtocolManager>
 
+#include <QActionGroup>
 #include <QMenu>
 #include <QPointer>
 
@@ -67,6 +58,8 @@ void DolphinViewActionHandler::setCurrentView(DolphinView* view)
             this, &DolphinViewActionHandler::slotSortOrderChanged);
     connect(view, &DolphinView::sortFoldersFirstChanged,
             this, &DolphinViewActionHandler::slotSortFoldersFirstChanged);
+    connect(view, &DolphinView::sortHiddenLastChanged,
+            this, &DolphinViewActionHandler::slotSortHiddenLastChanged);
     connect(view, &DolphinView::visibleRolesChanged,
             this, &DolphinViewActionHandler::slotVisibleRolesChanged);
     connect(view, &DolphinView::groupedSortingChanged,
@@ -79,6 +72,9 @@ void DolphinViewActionHandler::setCurrentView(DolphinView* view)
             this, &DolphinViewActionHandler::slotZoomLevelChanged);
     connect(view, &DolphinView::writeStateChanged,
             this, &DolphinViewActionHandler::slotWriteStateChanged);
+    connect(view, &DolphinView::selectionChanged,
+            this, &DolphinViewActionHandler::slotSelectionChanged);
+    slotSelectionChanged(m_currentView->selectedItems());
 }
 
 DolphinView* DolphinViewActionHandler::currentView()
@@ -92,7 +88,7 @@ void DolphinViewActionHandler::createActions()
     // KNewFileMenu takes care of the GUI stuff.
     QAction* newDirAction = m_actionCollection->addAction(QStringLiteral("create_dir"));
     newDirAction->setText(i18nc("@action", "Create Folder..."));
-    m_actionCollection->setDefaultShortcut(newDirAction, Qt::Key_F10);
+    m_actionCollection->setDefaultShortcuts(newDirAction, KStandardShortcut::createFolder());
     newDirAction->setIcon(QIcon::fromTheme(QStringLiteral("folder-new")));
     newDirAction->setEnabled(false);    // Will be enabled in slotWriteStateChanged(bool) if the current URL is writable
     connect(newDirAction, &QAction::triggered, this, &DolphinViewActionHandler::createDirectoryTriggered);
@@ -136,6 +132,13 @@ void DolphinViewActionHandler::createActions()
     deleteWithTrashShortcut->setEnabled(false);
     connect(deleteWithTrashShortcut, &QAction::triggered, this, &DolphinViewActionHandler::slotDeleteItems);
 
+    QAction* duplicateAction = m_actionCollection->addAction(QStringLiteral("duplicate"));
+    duplicateAction->setText(i18nc("@action:inmenu File", "Duplicate Here"));
+    duplicateAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-duplicate")));
+    m_actionCollection->setDefaultShortcut(duplicateAction, Qt::CTRL | Qt::Key_D);
+    duplicateAction->setEnabled(false);
+    connect(duplicateAction, &QAction::triggered, this, &DolphinViewActionHandler::slotDuplicate);
+
     QAction *propertiesAction = m_actionCollection->addAction( QStringLiteral("properties") );
     // Well, it's the File menu in dolphinmainwindow and the Edit menu in dolphinpart... :)
     propertiesAction->setText( i18nc("@action:inmenu File", "Properties") );
@@ -146,9 +149,39 @@ void DolphinViewActionHandler::createActions()
         "You can configure advanced options there like managing "
         "read- and write-permissions."));
     propertiesAction->setIcon(QIcon::fromTheme(QStringLiteral("document-properties")));
-    m_actionCollection->setDefaultShortcuts(propertiesAction, {Qt::ALT + Qt::Key_Return, Qt::ALT + Qt::Key_Enter});
+    m_actionCollection->setDefaultShortcuts(propertiesAction, {Qt::ALT | Qt::Key_Return, Qt::ALT | Qt::Key_Enter});
     connect(propertiesAction, &QAction::triggered, this, &DolphinViewActionHandler::slotProperties);
 
+    QAction *copyPathAction = m_actionCollection->addAction( QStringLiteral("copy_location") );
+    copyPathAction->setText(i18nc("@action:incontextmenu", "Copy Location"));
+    copyPathAction->setWhatsThis(i18nc("@info:whatsthis copy_location",
+                                          "This will copy the path of the first selected item into the clipboard."
+                                ));
+
+    copyPathAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy-path")));
+    m_actionCollection->setDefaultShortcuts(copyPathAction, {Qt::CTRL | Qt::ALT | Qt::Key_C});
+    connect(copyPathAction, &QAction::triggered, this, &DolphinViewActionHandler::slotCopyPath);
+
+    // 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.
+    // The text when nothing is selected at least implies that a selection can /somehow/ be made.
+    // This menu is by default only used in the hamburger menu but created here so users can put
+    // it on their toolbar.
+    KActionMenu *basicActionsMenu = m_actionCollection->add<KActionMenu>(QStringLiteral("basic_actions"), this);
+    // The text is set later depending on the selection in the currently active view.
+    basicActionsMenu->setPopupMode(QToolButton::InstantPopup);
+    basicActionsMenu->addAction(m_actionCollection->action(KStandardAction::name(KStandardAction::Cut)));
+    basicActionsMenu->addAction(m_actionCollection->action(KStandardAction::name(KStandardAction::Copy)));
+    basicActionsMenu->addAction(m_actionCollection->action(KStandardAction::name(KStandardAction::Paste)));
+    basicActionsMenu->addSeparator();
+    basicActionsMenu->addAction(m_actionCollection->action(KStandardAction::name(KStandardAction::RenameFile)));
+    basicActionsMenu->addAction(m_actionCollection->action(KStandardAction::name(KStandardAction::MoveToTrash)));
+    basicActionsMenu->addSeparator();
+    basicActionsMenu->addAction(m_actionCollection->action(QStringLiteral("properties")));
+    basicActionsMenu->addSeparator(); // We add one more separator because we sometimes add contextual
+                                      // actions in slotSelectionChanged() after the static ones above.
+
     // View menu
     KToggleAction* iconsAction = iconsModeAction();
     KToggleAction* compactAction = compactModeAction();
@@ -181,7 +214,7 @@ void DolphinViewActionHandler::createActions()
     viewModeActions->addAction(compactAction);
     viewModeActions->addAction(detailsAction);
     viewModeActions->setToolBarMode(KSelectAction::MenuMode);
-    connect(viewModeActions, QOverload<QAction*>::of(&KSelectAction::triggered), this, &DolphinViewActionHandler::slotViewModeActionTriggered);
+    connect(viewModeActions, &KSelectAction::triggered, this, &DolphinViewActionHandler::slotViewModeActionTriggered);
 
     QAction* zoomInAction = KStandardAction::zoomIn(this,
                             &DolphinViewActionHandler::zoomIn,
@@ -193,7 +226,7 @@ void DolphinViewActionHandler::createActions()
     zoomResetAction->setToolTip(i18n("Zoom To Default"));
     zoomResetAction->setWhatsThis(i18nc("@info:whatsthis zoom reset", "This resets the icon size to default."));
     zoomResetAction->setIcon(QIcon::fromTheme(QStringLiteral("zoom-original")));
-    m_actionCollection->setDefaultShortcuts(zoomResetAction, {Qt::CTRL + Qt::Key_0});
+    m_actionCollection->setDefaultShortcuts(zoomResetAction, {Qt::CTRL | Qt::Key_0});
     connect(zoomResetAction, &QAction::triggered, this, &DolphinViewActionHandler::zoomReset);
 
     QAction* zoomOutAction = KStandardAction::zoomOut(this,
@@ -201,6 +234,14 @@ void DolphinViewActionHandler::createActions()
                              m_actionCollection);
     zoomOutAction->setWhatsThis(i18nc("@info:whatsthis zoom out", "This reduces the icon size."));
 
+    KActionMenu* zoomMenu = m_actionCollection->add<KActionMenu>(QStringLiteral("zoom"));
+    zoomMenu->setText(i18nc("@action:inmenu menu of zoom actions", "Zoom"));
+    zoomMenu->setIcon(QIcon::fromTheme(QStringLiteral("zoom")));
+    zoomMenu->setPopupMode(QToolButton::InstantPopup);
+    zoomMenu->addAction(zoomInAction);
+    zoomMenu->addAction(zoomResetAction);
+    zoomMenu->addAction(zoomOutAction);
+
     KToggleAction* showPreview = m_actionCollection->add<KToggleAction>(QStringLiteral("show_preview"));
     showPreview->setText(i18nc("@action:intoolbar", "Show Previews"));
     showPreview->setToolTip(i18nc("@info", "Show preview of files and folders"));
@@ -215,15 +256,20 @@ void DolphinViewActionHandler::createActions()
     sortFoldersFirst->setText(i18nc("@action:inmenu Sort", "Folders First"));
     connect(sortFoldersFirst, &KToggleAction::triggered, this, &DolphinViewActionHandler::toggleSortFoldersFirst);
 
+    KToggleAction* sortHiddenLast = m_actionCollection->add<KToggleAction>(QStringLiteral("hidden_last"));
+    sortHiddenLast->setText(i18nc("@action:inmenu Sort", "Hidden Files Last"));
+    connect(sortHiddenLast, &KToggleAction::triggered, this, &DolphinViewActionHandler::toggleSortHiddenLast);
+
     // View -> Sort By
     QActionGroup* sortByActionGroup = createFileItemRolesActionGroup(QStringLiteral("sort_by_"));
 
     KActionMenu* sortByActionMenu = m_actionCollection->add<KActionMenu>(QStringLiteral("sort"));
     sortByActionMenu->setIcon(QIcon::fromTheme(QStringLiteral("view-sort")));
     sortByActionMenu->setText(i18nc("@action:inmenu View", "Sort By"));
-    sortByActionMenu->setDelayed(false);
+    sortByActionMenu->setPopupMode(QToolButton::InstantPopup);
 
-    foreach (QAction* action, sortByActionGroup->actions()) {
+    const auto sortByActionGroupActions = sortByActionGroup->actions();
+    for (QAction* action : sortByActionGroupActions) {
         sortByActionMenu->addAction(action);
     }
 
@@ -248,6 +294,7 @@ void DolphinViewActionHandler::createActions()
     sortByActionMenu->addAction(descendingAction);
     sortByActionMenu->addSeparator();
     sortByActionMenu->addAction(sortFoldersFirst);
+    sortByActionMenu->addAction(sortHiddenLast);
 
     // View -> Additional Information
     QActionGroup* visibleRolesGroup = createFileItemRolesActionGroup(QStringLiteral("show_"));
@@ -255,9 +302,10 @@ void DolphinViewActionHandler::createActions()
     KActionMenu* visibleRolesMenu = m_actionCollection->add<KActionMenu>(QStringLiteral("additional_info"));
     visibleRolesMenu->setText(i18nc("@action:inmenu View", "Show Additional Information"));
     visibleRolesMenu->setIcon(QIcon::fromTheme(QStringLiteral("documentinfo")));
-    visibleRolesMenu->setDelayed(false);
+    visibleRolesMenu->setPopupMode(QToolButton::InstantPopup);
 
-    foreach (QAction* action, visibleRolesGroup->actions()) {
+    const auto visibleRolesGroupActions = visibleRolesGroup->actions();
+    for (QAction* action : visibleRolesGroupActions) {
         visibleRolesMenu->addAction(action);
     }
 
@@ -268,19 +316,19 @@ void DolphinViewActionHandler::createActions()
     connect(showInGroups, &KToggleAction::triggered, this, &DolphinViewActionHandler::toggleGroupedSorting);
 
     KToggleAction* showHiddenFiles = m_actionCollection->add<KToggleAction>(QStringLiteral("show_hidden_files"));
+    showHiddenFiles->setIcon(QIcon::fromTheme(QStringLiteral("view-visible")));
     showHiddenFiles->setText(i18nc("@action:inmenu View", "Show Hidden Files"));
-    showHiddenFiles->setToolTip(i18nc("@info", "Visibility of hidden files and folders"));
     showHiddenFiles->setWhatsThis(xi18nc("@info:whatsthis", "<para>When "
         "this is enabled <emphasis>hidden</emphasis> files and folders "
         "are visible. They will be displayed semi-transparent.</para>"
         "<para>Hidden items only differ from other ones in that their "
         "name starts with a \".\". In general there is no need for "
         "users to access them which is why they are hidden.</para>"));
-    m_actionCollection->setDefaultShortcuts(showHiddenFiles, {Qt::ALT + Qt::Key_Period, Qt::CTRL + Qt::Key_H, Qt::Key_F8});
+    m_actionCollection->setDefaultShortcuts(showHiddenFiles, KStandardShortcut::showHideHiddenFiles());
     connect(showHiddenFiles, &KToggleAction::triggered, this, &DolphinViewActionHandler::toggleShowHiddenFiles);
 
     QAction* adjustViewProps = m_actionCollection->addAction(QStringLiteral("view_properties"));
-    adjustViewProps->setText(i18nc("@action:inmenu View", "Adjust View Properties..."));
+    adjustViewProps->setText(i18nc("@action:inmenu View", "Adjust View Display Style..."));
     adjustViewProps->setIcon(QIcon::fromTheme(QStringLiteral("view-choose")));
     adjustViewProps->setWhatsThis(i18nc("@info:whatsthis", "This opens a window "
         "in which all folder view properties can be adjusted."));
@@ -307,13 +355,13 @@ QActionGroup* DolphinViewActionHandler::createFileItemRolesActionGroup(const QSt
     QActionGroup* groupMenuGroup = nullptr;
 
     bool indexingEnabled = false;
-#ifdef HAVE_BALOO
+#if HAVE_BALOO
     Baloo::IndexerConfig config;
     indexingEnabled = config.fileIndexingEnabled();
 #endif
 
     const QList<KFileItemModel::RoleInfo> rolesInfo = KFileItemModel::rolesInformation();
-    foreach (const KFileItemModel::RoleInfo& info, rolesInfo) {
+    for (const KFileItemModel::RoleInfo& info : rolesInfo) {
         if (!isSortGroup && info.role == "text") {
             // It should not be possible to hide the "text" role
             continue;
@@ -375,31 +423,31 @@ void DolphinViewActionHandler::slotViewModeActionTriggered(QAction* action)
 
 void DolphinViewActionHandler::slotRename()
 {
-    emit actionBeingHandled();
+    Q_EMIT actionBeingHandled();
     m_currentView->renameSelectedItems();
 }
 
 void DolphinViewActionHandler::slotTrashActivated()
 {
-    emit actionBeingHandled();
+    Q_EMIT actionBeingHandled();
     m_currentView->trashSelectedItems();
 }
 
 void DolphinViewActionHandler::slotDeleteItems()
 {
-    emit actionBeingHandled();
+    Q_EMIT actionBeingHandled();
     m_currentView->deleteSelectedItems();
 }
 
 void DolphinViewActionHandler::togglePreview(bool show)
 {
-    emit actionBeingHandled();
+    Q_EMIT actionBeingHandled();
     m_currentView->setPreviewsShown(show);
 }
 
 void DolphinViewActionHandler::slotPreviewsShownChanged(bool shown)
 {
-    Q_UNUSED(shown);
+    Q_UNUSED(shown)
     // It is not enough to update the 'Show Preview' action, also
     // the 'Zoom In', 'Zoom Out' and 'Zoom Reset' actions must be adapted.
     updateViewActions();
@@ -441,6 +489,7 @@ void DolphinViewActionHandler::updateViewActions()
 
     slotSortOrderChanged(m_currentView->sortOrder());
     slotSortFoldersFirstChanged(m_currentView->sortFoldersFirst());
+    slotSortHiddenLastChanged(m_currentView->sortHiddenLast());
     slotVisibleRolesChanged(m_currentView->visibleRoles(), QList<QByteArray>());
     slotGroupedSortingChanged(m_currentView->groupedSorting());
     slotSortRoleChanged(m_currentView->sortRole());
@@ -476,6 +525,12 @@ void DolphinViewActionHandler::toggleSortFoldersFirst()
     m_currentView->setSortFoldersFirst(!sortFirst);
 }
 
+void DolphinViewActionHandler::toggleSortHiddenLast()
+{
+    const bool sortHiddenLast = m_currentView->sortHiddenLast();
+    m_currentView->setSortHiddenLast(!sortHiddenLast);
+}
+
 void DolphinViewActionHandler::slotSortOrderChanged(Qt::SortOrder order)
 {
     QAction* descending = m_actionCollection->action(QStringLiteral("descending"));
@@ -490,9 +545,14 @@ void DolphinViewActionHandler::slotSortFoldersFirstChanged(bool foldersFirst)
     m_actionCollection->action(QStringLiteral("folders_first"))->setChecked(foldersFirst);
 }
 
+void DolphinViewActionHandler::slotSortHiddenLastChanged(bool hiddenLast)
+{
+    m_actionCollection->action(QStringLiteral("hidden_last"))->setChecked(hiddenLast);
+}
+
 void DolphinViewActionHandler::toggleVisibleRole(QAction* action)
 {
-    emit actionBeingHandled();
+    Q_EMIT actionBeingHandled();
 
     const QByteArray toggledRole = action->data().toByteArray();
 
@@ -515,9 +575,9 @@ void DolphinViewActionHandler::toggleVisibleRole(QAction* action)
 void DolphinViewActionHandler::slotVisibleRolesChanged(const QList<QByteArray>& current,
                                                        const QList<QByteArray>& previous)
 {
-    Q_UNUSED(previous);
+    Q_UNUSED(previous)
 
-    const QSet<QByteArray> checkedRoles = current.toSet();
+    const auto checkedRoles = QSet<QByteArray>(current.constBegin(), current.constEnd());
     QHashIterator<QByteArray, KToggleAction*> it(m_visibleRoles);
     while (it.hasNext()) {
         it.next();
@@ -540,7 +600,7 @@ void DolphinViewActionHandler::slotGroupedSortingChanged(bool groupedSorting)
 
 void DolphinViewActionHandler::toggleShowHiddenFiles(bool show)
 {
-    emit actionBeingHandled();
+    Q_EMIT actionBeingHandled();
     m_currentView->setHiddenFilesShown(show);
 }
 
@@ -548,14 +608,6 @@ 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("view-visible") && iconName != QLatin1String("view-hidden")) {
-        return;
-    }
-
-    showHiddenFilesAction->setIcon(QIcon::fromTheme(shown ? QStringLiteral("view-visible") : QStringLiteral("view-hidden")));
 }
 
 void DolphinViewActionHandler::slotWriteStateChanged(bool isFolderWritable)
@@ -569,7 +621,7 @@ KToggleAction* DolphinViewActionHandler::iconsModeAction()
     KToggleAction* iconsView = m_actionCollection->add<KToggleAction>(QStringLiteral("icons"));
     iconsView->setText(i18nc("@action:inmenu View Mode", "Icons"));
     iconsView->setToolTip(i18nc("@info", "Icons view mode"));
-    m_actionCollection->setDefaultShortcut(iconsView, Qt::CTRL + Qt::Key_1);
+    m_actionCollection->setDefaultShortcut(iconsView, Qt::CTRL | Qt::Key_1);
     iconsView->setIcon(QIcon::fromTheme(QStringLiteral("view-list-icons")));
     iconsView->setData(QVariant::fromValue(DolphinView::IconsView));
     return iconsView;
@@ -580,7 +632,7 @@ KToggleAction* DolphinViewActionHandler::compactModeAction()
     KToggleAction* iconsView = m_actionCollection->add<KToggleAction>(QStringLiteral("compact"));
     iconsView->setText(i18nc("@action:inmenu View Mode", "Compact"));
     iconsView->setToolTip(i18nc("@info", "Compact view mode"));
-    m_actionCollection->setDefaultShortcut(iconsView, Qt::CTRL + Qt::Key_2);
+    m_actionCollection->setDefaultShortcut(iconsView, Qt::CTRL | Qt::Key_2);
     iconsView->setIcon(QIcon::fromTheme(QStringLiteral("view-list-details"))); // TODO: discuss with Oxygen-team the wrong (?) name
     iconsView->setData(QVariant::fromValue(DolphinView::CompactView));
     return iconsView;
@@ -591,7 +643,7 @@ KToggleAction* DolphinViewActionHandler::detailsModeAction()
     KToggleAction* detailsView = m_actionCollection->add<KToggleAction>(QStringLiteral("details"));
     detailsView->setText(i18nc("@action:inmenu View Mode", "Details"));
     detailsView->setToolTip(i18nc("@info", "Details view mode"));
-    m_actionCollection->setDefaultShortcut(detailsView, Qt::CTRL + Qt::Key_3);
+    m_actionCollection->setDefaultShortcut(detailsView, Qt::CTRL | Qt::Key_3);
     detailsView->setIcon(QIcon::fromTheme(QStringLiteral("view-list-tree")));
     detailsView->setData(QVariant::fromValue(DolphinView::DetailsView));
     return detailsView;
@@ -612,18 +664,18 @@ void DolphinViewActionHandler::slotSortRoleChanged(const QByteArray& role)
     QAction* descending = m_actionCollection->action(QStringLiteral("descending"));
     QAction* ascending = m_actionCollection->action(QStringLiteral("ascending"));
 
-    if (role == "text" || role == "type" || role == "tags" || role == "comment") {
+    if (role == "text" || role == "type" || role == "extension" || role == "tags" || role == "comment") {
         descending->setText(i18nc("Sort descending", "Z-A"));
         ascending->setText(i18nc("Sort ascending", "A-Z"));
     } else if (role == "size") {
-        descending->setText(i18nc("Sort descending", "Largest first"));
-        ascending->setText(i18nc("Sort ascending", "Smallest first"));
+        descending->setText(i18nc("Sort descending", "Largest First"));
+        ascending->setText(i18nc("Sort ascending", "Smallest First"));
     } else if (role == "modificationtime" || role == "creationtime" || role == "accesstime") {
-        descending->setText(i18nc("Sort descending", "Newest first"));
-        ascending->setText(i18nc("Sort ascending", "Oldest first"));
+        descending->setText(i18nc("Sort descending", "Newest First"));
+        ascending->setText(i18nc("Sort ascending", "Oldest First"));
     } else if (role == "rating") {
-        descending->setText(i18nc("Sort descending", "Highest first"));
-        ascending->setText(i18nc("Sort ascending", "Lowest first"));
+        descending->setText(i18nc("Sort descending", "Highest First"));
+        ascending->setText(i18nc("Sort ascending", "Lowest First"));
     } else {
         descending->setText(i18nc("Sort descending", "Descending"));
         ascending->setText(i18nc("Sort ascending", "Ascending"));
@@ -634,7 +686,7 @@ void DolphinViewActionHandler::slotSortRoleChanged(const QByteArray& role)
 
 void DolphinViewActionHandler::slotZoomLevelChanged(int current, int previous)
 {
-    Q_UNUSED(previous);
+    Q_UNUSED(previous)
 
     QAction* zoomInAction = m_actionCollection->action(KStandardAction::name(KStandardAction::ZoomIn));
     if (zoomInAction) {
@@ -658,7 +710,8 @@ void DolphinViewActionHandler::slotSortTriggered(QAction* action)
     for (QAction *groupAction : qAsConst(m_sortByActions)) {
         KActionMenu* actionMenu = qobject_cast<KActionMenu*>(groupAction);
         if (actionMenu) {
-            foreach (QAction* subAction, actionMenu->menu()->actions()) {
+            const auto actions = actionMenu->menu()->actions();
+            for (QAction* subAction : actions) {
                 subAction->setChecked(false);
             }
         } else if (groupAction->actionGroup()) {
@@ -674,12 +727,18 @@ void DolphinViewActionHandler::slotSortTriggered(QAction* action)
 
 void DolphinViewActionHandler::slotAdjustViewProperties()
 {
-    emit actionBeingHandled();
+    Q_EMIT actionBeingHandled();
     QPointer<ViewPropertiesDialog> dialog = new ViewPropertiesDialog(m_currentView);
     dialog->exec();
     delete dialog;
 }
 
+void DolphinViewActionHandler::slotDuplicate()
+{
+    Q_EMIT actionBeingHandled();
+    m_currentView->duplicateSelectedItems();
+}
+
 void DolphinViewActionHandler::slotProperties()
 {
     KPropertiesDialog* dialog = nullptr;
@@ -696,3 +755,49 @@ void DolphinViewActionHandler::slotProperties()
     dialog->raise();
     dialog->activateWindow();
 }
+
+void DolphinViewActionHandler::slotCopyPath()
+{
+    m_currentView->copyPathToClipboard();
+}
+
+void DolphinViewActionHandler::slotSelectionChanged(const KFileItemList& selection)
+{
+    QString basicActionsMenuText;
+    if (selection.isEmpty()) {
+        basicActionsMenuText =
+            i18nc("@action:inmenu menu with actions like copy, paste, rename. The user's selection is empty when this text is shown.",
+                  "Actions for Current View");
+    } else {
+        QFontMetrics fontMetrics = QMenu().fontMetrics();
+        // i18n: @action:inmenu menu with actions like copy, paste, rename.
+        // %1 is a textual representation of the currently selected files or folders. This can be the name of
+        // the file/files like "file1" or "file1, file2 and file3" or an aggregate like "8 Selected Folders".
+        // If this sort of word puzzle can not be correctly translated in your language, translate it as "NULL" (without the quotes)
+        // and a fallback will be used.
+        basicActionsMenuText = i18n("Actions for %1", fileItemListToString(selection, fontMetrics.averageCharWidth() * 40, fontMetrics, ItemsState::Selected));
+    }
+
+    if (basicActionsMenuText == QStringLiteral("NULL")) {
+        const KFileItemListProperties properties(selection);
+        basicActionsMenuText =
+            i18ncp("@action:inmenu menu with actions like copy, paste, rename. %1 is the amount of selected files/folders.",
+                    "Actions for One Selected Item", "Actions for %1 Selected Items", selection.count());
+    }
+
+    QAction *basicActionsMenu = m_actionCollection->action(QStringLiteral("basic_actions"));
+    basicActionsMenu->setText(basicActionsMenuText);
+
+    // Add or remove contextual actions
+    while (!basicActionsMenu->menu()->actions().constLast()->isSeparator()) {
+        basicActionsMenu->menu()->removeAction(basicActionsMenu->menu()->actions().last());
+    }
+    if (selection.count() == 1) {
+        if (selection.first().isLink()) {
+            basicActionsMenu->menu()->addAction(m_actionCollection->action(QStringLiteral("show_target")));
+        }
+        if (selection.first().isDir()) {
+            basicActionsMenu->menu()->addAction(m_actionCollection->action(QStringLiteral("add_to_places")));
+        }
+    }
+}