]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/views/dolphinviewactionhandler.cpp
Fix minor typos
[dolphin.git] / src / views / dolphinviewactionhandler.cpp
index 5c0b49cd206c371fd5dda83895dd93f9e1f37be2..6169ec2c1d572d085b364e36040065b6e06f1feb 100644 (file)
 
 #include "dolphinviewactionhandler.h"
 
-#include <config-baloo.h>
-
+#include "dolphindebug.h"
+#include "kitemviews/kfileitemmodel.h"
 #include "settings/viewpropertiesdialog.h"
-#include "views/dolphinview.h"
 #include "views/zoomlevelinfo.h"
 
-#include <QPointer>
-#include <QMenu>
-
+#ifdef HAVE_BALOO
+#include <Baloo/IndexerConfig>
+#endif
 #include <KActionCollection>
 #include <KActionMenu>
-#include <kitemviews/kfileitemmodel.h>
 #include <KLocalizedString>
 #include <KNewFileMenu>
-#include <KSelectAction>
-#include <KToggleAction>
 #include <KPropertiesDialog>
 #include <KProtocolManager>
-#include <QIcon>
 
-#include "dolphindebug.h"
-
-#ifdef HAVE_BALOO
-    #include <Baloo/IndexerConfig>
-#endif
+#include <QMenu>
+#include <QPointer>
 
 DolphinViewActionHandler::DolphinViewActionHandler(KActionCollection* collection, QObject* parent) :
     QObject(parent),
     m_actionCollection(collection),
-    m_currentView(0),
+    m_currentView(nullptr),
     m_sortByActions(),
     m_visibleRoles()
 {
@@ -62,7 +54,7 @@ void DolphinViewActionHandler::setCurrentView(DolphinView* view)
     Q_ASSERT(view);
 
     if (m_currentView) {
-        disconnect(m_currentView, 0, this, 0);
+        disconnect(m_currentView, nullptr, this, nullptr);
     }
 
     m_currentView = view;
@@ -103,43 +95,56 @@ void DolphinViewActionHandler::createActions()
     m_actionCollection->setDefaultShortcut(newDirAction, Qt::Key_F10);
     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::createDirectory);
+    connect(newDirAction, &QAction::triggered, this, &DolphinViewActionHandler::createDirectoryTriggered);
 
     // 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
+    auto renameAction = KStandardAction::renameFile(this, &DolphinViewActionHandler::slotRename, m_actionCollection);
+    renameAction->setWhatsThis(xi18nc("@info:whatsthis", "This renames the "
+        "items in your current selection.<nl/>Renaming multiple items "
+        "at once amounts to their new names differing only in a number."));
+
+    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);
+    }
+    trashAction->setWhatsThis(xi18nc("@info:whatsthis", "This moves the "
+        "items in your current selection to the <filename>Trash"
+        "</filename>.<nl/>The trash is a temporary storage where "
+        "items can be deleted from if disk space is needed."));
+
+    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);
+    }
+    deleteAction->setWhatsThis(xi18nc("@info:whatsthis", "This deletes "
+        "the items in your current selection completely. They can "
+        "not be recovered by normal means."));
+
+    // 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"));
     // The descriptive text is just for the shortcuts editor.
     deleteWithTrashShortcut->setText(i18nc("@action \"Move to Trash\" for non-local files, etc.", "Delete (using shortcut for Trash)"));
-    m_actionCollection->setDefaultShortcut(deleteWithTrashShortcut, QKeySequence::Delete);
+    m_actionCollection->setDefaultShortcuts(deleteWithTrashShortcut, KStandardShortcut::moveToTrash());
     deleteWithTrashShortcut->setEnabled(false);
     connect(deleteWithTrashShortcut, &QAction::triggered, this, &DolphinViewActionHandler::slotDeleteItems);
 
     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") );
+    propertiesAction->setWhatsThis(xi18nc("@info:whatsthis properties",
+        "This shows a complete list of properties of the currently "
+        "selected items in a new window.<nl/>If nothing is selected the "
+        "window will be about the currently viewed folder instead.<nl/>"
+        "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});
     connect(propertiesAction, &QAction::triggered, this, &DolphinViewActionHandler::slotProperties);
@@ -149,25 +154,52 @@ void DolphinViewActionHandler::createActions()
     KToggleAction* compactAction = compactModeAction();
     KToggleAction* detailsAction = detailsModeAction();
 
+    iconsAction->setWhatsThis(xi18nc("@info:whatsthis Icons view mode",
+        "<para>This switches to a view mode that focuses on the folder "
+        "and file icons. This mode makes it easy to distinguish folders "
+        "from files and to detect items with distinctive <emphasis>"
+        "file types</emphasis>.</para><para> This mode is handy to "
+        "browse through pictures when the <interface>Preview"
+        "</interface> option is enabled.</para>"));
+    compactAction->setWhatsThis(xi18nc("@info:whatsthis Compact view mode",
+        "<para>This switches to a compact view mode that lists the folders "
+        "and files in columns with the names beside the icons. <para></para>"
+        "This helps to keep the overview in folders with many items.</para>"));
+    detailsAction->setWhatsThis(xi18nc("@info:whatsthis Details view mode",
+        "<para>This switches to a list view mode that focuses on folder "
+        "and file details.</para><para>Click on a detail in the column "
+        "header to sort the items by it. Click again to sort the other "
+        "way around. To select which details should be displayed click "
+        "the header with the right mouse button.</para><para>You can "
+        "view the contents of a folder without leaving the current "
+        "location by clicking to the left of it. This way you can view "
+        "the contents of multiple folders in the same list.</para>"));
+
     KSelectAction* viewModeActions = m_actionCollection->add<KSelectAction>(QStringLiteral("view_mode"));
     viewModeActions->setText(i18nc("@action:intoolbar", "View Mode"));
     viewModeActions->addAction(iconsAction);
     viewModeActions->addAction(compactAction);
     viewModeActions->addAction(detailsAction);
     viewModeActions->setToolBarMode(KSelectAction::MenuMode);
-    connect(viewModeActions, static_cast<void(KSelectAction::*)(QAction*)>(&KSelectAction::triggered), this, &DolphinViewActionHandler::slotViewModeActionTriggered);
+    connect(viewModeActions, QOverload<QAction*>::of(&KSelectAction::triggered), this, &DolphinViewActionHandler::slotViewModeActionTriggered);
 
-    KStandardAction::zoomIn(this,
-                            SLOT(zoomIn()),
+    QAction* zoomInAction = KStandardAction::zoomIn(this,
+                            &DolphinViewActionHandler::zoomIn,
                             m_actionCollection);
+    zoomInAction->setWhatsThis(i18nc("@info:whatsthis zoom in", "This increases the icon size."));
 
-    KStandardAction::zoomOut(this,
-                             SLOT(zoomOut()),
+    QAction* zoomOutAction = KStandardAction::zoomOut(this,
+                             &DolphinViewActionHandler::zoomOut,
                              m_actionCollection);
+    zoomOutAction->setWhatsThis(i18nc("@info:whatsthis zoom in", "This reduces the icon size."));
 
     KToggleAction* showPreview = m_actionCollection->add<KToggleAction>(QStringLiteral("show_preview"));
     showPreview->setText(i18nc("@action:intoolbar", "Preview"));
     showPreview->setToolTip(i18nc("@info", "Show preview of files and folders"));
+    showPreview->setWhatsThis(xi18nc("@info:whatsthis", "When this is "
+        "enabled, the icons are based on the actual file or folder "
+        "contents.<nl/>For example the icons of images become scaled "
+        "down versions of the images."));
     showPreview->setIcon(QIcon::fromTheme(QStringLiteral("view-preview")));
     connect(showPreview, &KToggleAction::triggered, this, &DolphinViewActionHandler::togglePreview);
 
@@ -183,6 +215,7 @@ void DolphinViewActionHandler::createActions()
     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);
 
@@ -207,16 +240,25 @@ void DolphinViewActionHandler::createActions()
     KToggleAction* showInGroups = m_actionCollection->add<KToggleAction>(QStringLiteral("show_in_groups"));
     showInGroups->setIcon(QIcon::fromTheme(QStringLiteral("view-group")));
     showInGroups->setText(i18nc("@action:inmenu View", "Show in Groups"));
+    showInGroups->setWhatsThis(i18nc("@info:whatsthis", "This groups files and folders by their first letter."));
     connect(showInGroups, &KToggleAction::triggered, this, &DolphinViewActionHandler::toggleGroupedSorting);
 
     KToggleAction* showHiddenFiles = m_actionCollection->add<KToggleAction>(QStringLiteral("show_hidden_files"));
     showHiddenFiles->setText(i18nc("@action:inmenu View", "Hidden Files"));
     showHiddenFiles->setToolTip(i18nc("@info", "Visibility of hidden files and folders"));
-    m_actionCollection->setDefaultShortcuts(showHiddenFiles, {Qt::ALT + Qt::Key_Period, Qt::Key_F8});
+    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});
     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->setWhatsThis(i18nc("@info:whatsthis", "This opens a window "
+        "in which all folder view properties can be adjusted."));
     connect(adjustViewProps, &QAction::triggered, this, &DolphinViewActionHandler::slotAdjustViewProperties);
 }
 
@@ -236,8 +278,8 @@ QActionGroup* DolphinViewActionHandler::createFileItemRolesActionGroup(const QSt
     }
 
     QString groupName;
-    KActionMenu* groupMenu = 0;
-    QActionGroup* groupMenuGroup = 0;
+    KActionMenu* groupMenu = nullptr;
+    QActionGroup* groupMenuGroup = nullptr;
 
     bool indexingEnabled = false;
 #ifdef HAVE_BALOO
@@ -252,7 +294,7 @@ QActionGroup* DolphinViewActionHandler::createFileItemRolesActionGroup(const QSt
             continue;
         }
 
-        KToggleAction* action = 0;
+        KToggleAction* action = nullptr;
         const QString name = groupPrefix + info.role;
         if (info.group.isEmpty()) {
             action = m_actionCollection->add<KToggleAction>(name);
@@ -482,6 +524,12 @@ 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")));
 }
 
@@ -496,7 +544,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;
@@ -507,7 +555,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;
@@ -518,7 +566,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;
@@ -587,7 +635,7 @@ void DolphinViewActionHandler::slotAdjustViewProperties()
 
 void DolphinViewActionHandler::slotProperties()
 {
-    KPropertiesDialog* dialog = 0;
+    KPropertiesDialog* dialog = nullptr;
     const KFileItemList list = m_currentView->selectedItems();
     if (list.isEmpty()) {
         const QUrl url = m_currentView->url();