]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/views/dolphinviewactionhandler.cpp
Don't overload the word "Properties" to mean multiple things
[dolphin.git] / src / views / dolphinviewactionhandler.cpp
index 6169ec2c1d572d085b364e36040065b6e06f1feb..ef9f317ee16d20e3399d6e46b41d1bd33d0ef4b2 100644 (file)
@@ -163,7 +163,7 @@ void DolphinViewActionHandler::createActions()
         "</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>"
+        "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 "
@@ -188,13 +188,21 @@ void DolphinViewActionHandler::createActions()
                             m_actionCollection);
     zoomInAction->setWhatsThis(i18nc("@info:whatsthis zoom in", "This increases the icon size."));
 
+    QAction* zoomResetAction = m_actionCollection->addAction(QStringLiteral("view_zoom_reset"));
+    zoomResetAction->setText(i18nc("@action:inmenu View", "Reset Zoom Level"));
+    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});
+    connect(zoomResetAction, &QAction::triggered, this, &DolphinViewActionHandler::zoomReset);
+
     QAction* zoomOutAction = KStandardAction::zoomOut(this,
                              &DolphinViewActionHandler::zoomOut,
                              m_actionCollection);
-    zoomOutAction->setWhatsThis(i18nc("@info:whatsthis zoom in", "This reduces the icon size."));
+    zoomOutAction->setWhatsThis(i18nc("@info:whatsthis zoom out", "This reduces the icon size."));
 
     KToggleAction* showPreview = m_actionCollection->add<KToggleAction>(QStringLiteral("show_preview"));
-    showPreview->setText(i18nc("@action:intoolbar", "Preview"));
+    showPreview->setText(i18nc("@action:intoolbar", "Show Previews"));
     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 "
@@ -203,10 +211,6 @@ void DolphinViewActionHandler::createActions()
     showPreview->setIcon(QIcon::fromTheme(QStringLiteral("view-preview")));
     connect(showPreview, &KToggleAction::triggered, this, &DolphinViewActionHandler::togglePreview);
 
-    KToggleAction* sortDescending = m_actionCollection->add<KToggleAction>(QStringLiteral("descending"));
-    sortDescending->setText(i18nc("@action:inmenu Sort", "Descending"));
-    connect(sortDescending, &KToggleAction::triggered, this, &DolphinViewActionHandler::toggleSortOrder);
-
     KToggleAction* sortFoldersFirst = m_actionCollection->add<KToggleAction>(QStringLiteral("folders_first"));
     sortFoldersFirst->setText(i18nc("@action:inmenu Sort", "Folders First"));
     connect(sortFoldersFirst, &KToggleAction::triggered, this, &DolphinViewActionHandler::toggleSortFoldersFirst);
@@ -222,15 +226,35 @@ void DolphinViewActionHandler::createActions()
     foreach (QAction* action, sortByActionGroup->actions()) {
         sortByActionMenu->addAction(action);
     }
+
+    sortByActionMenu->addSeparator();
+
+    QActionGroup* group = new QActionGroup(sortByActionMenu);
+    group->setExclusive(true);
+
+    KToggleAction* ascendingAction = m_actionCollection->add<KToggleAction>(QStringLiteral("ascending"));
+    ascendingAction->setActionGroup(group);
+    connect(ascendingAction, &QAction::triggered, this, [this] {
+        m_currentView->setSortOrder(Qt::AscendingOrder);
+    });
+
+    KToggleAction* descendingAction = m_actionCollection->add<KToggleAction>(QStringLiteral("descending"));
+    descendingAction->setActionGroup(group);
+    connect(descendingAction, &QAction::triggered, this, [this] {
+        m_currentView->setSortOrder(Qt::DescendingOrder);
+    });
+
+    sortByActionMenu->addAction(ascendingAction);
+    sortByActionMenu->addAction(descendingAction);
     sortByActionMenu->addSeparator();
-    sortByActionMenu->addAction(sortDescending);
     sortByActionMenu->addAction(sortFoldersFirst);
 
     // View -> Additional Information
     QActionGroup* visibleRolesGroup = createFileItemRolesActionGroup(QStringLiteral("show_"));
 
     KActionMenu* visibleRolesMenu = m_actionCollection->add<KActionMenu>(QStringLiteral("additional_info"));
-    visibleRolesMenu->setText(i18nc("@action:inmenu View", "Additional Information"));
+    visibleRolesMenu->setText(i18nc("@action:inmenu View", "Show Additional Information"));
+    visibleRolesMenu->setIcon(QIcon::fromTheme(QStringLiteral("documentinfo")));
     visibleRolesMenu->setDelayed(false);
 
     foreach (QAction* action, visibleRolesGroup->actions()) {
@@ -244,7 +268,7 @@ void DolphinViewActionHandler::createActions()
     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->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 "
@@ -256,7 +280,8 @@ void DolphinViewActionHandler::createActions()
     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."));
     connect(adjustViewProps, &QAction::triggered, this, &DolphinViewActionHandler::slotAdjustViewProperties);
@@ -265,7 +290,7 @@ void DolphinViewActionHandler::createActions()
 QActionGroup* DolphinViewActionHandler::createFileItemRolesActionGroup(const QString& groupPrefix)
 {
     const bool isSortGroup = (groupPrefix == QLatin1String("sort_by_"));
-    Q_ASSERT(isSortGroup || (!isSortGroup && groupPrefix == QLatin1String("show_")));
+    Q_ASSERT(isSortGroup || groupPrefix == QLatin1String("show_"));
 
     QActionGroup* rolesActionGroup = new QActionGroup(m_actionCollection);
     rolesActionGroup->setExclusive(isSortGroup);
@@ -374,9 +399,9 @@ void DolphinViewActionHandler::togglePreview(bool 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' and 'Zoom Out' actions must be adapted.
+    // the 'Zoom In', 'Zoom Out' and 'Zoom Reset' actions must be adapted.
     updateViewActions();
 }
 
@@ -439,12 +464,10 @@ void DolphinViewActionHandler::zoomOut()
     updateViewActions();
 }
 
-void DolphinViewActionHandler::toggleSortOrder()
+void DolphinViewActionHandler::zoomReset()
 {
-    const Qt::SortOrder order = (m_currentView->sortOrder() == Qt::AscendingOrder) ?
-                                Qt::DescendingOrder :
-                                Qt::AscendingOrder;
-    m_currentView->setSortOrder(order);
+    m_currentView->resetZoomLevel();
+    updateViewActions();
 }
 
 void DolphinViewActionHandler::toggleSortFoldersFirst()
@@ -456,8 +479,10 @@ void DolphinViewActionHandler::toggleSortFoldersFirst()
 void DolphinViewActionHandler::slotSortOrderChanged(Qt::SortOrder order)
 {
     QAction* descending = m_actionCollection->action(QStringLiteral("descending"));
+    QAction* ascending = m_actionCollection->action(QStringLiteral("ascending"));
     const bool sortDescending = (order == Qt::DescendingOrder);
     descending->setChecked(sortDescending);
+    ascending->setChecked(!sortDescending);
 }
 
 void DolphinViewActionHandler::slotSortFoldersFirstChanged(bool foldersFirst)
@@ -490,7 +515,7 @@ 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();
     QHashIterator<QByteArray, KToggleAction*> it(m_visibleRoles);
@@ -526,11 +551,11 @@ void DolphinViewActionHandler::slotHiddenFilesShownChanged(bool shown)
 
     // #374508: don't overwrite custom icons.
     const QString iconName = showHiddenFilesAction->icon().name();
-    if (!iconName.isEmpty() && iconName != QLatin1String("visibility") && iconName != QLatin1String("hint")) {
+    if (!iconName.isEmpty() && iconName != QLatin1String("view-visible") && iconName != QLatin1String("view-hidden")) {
         return;
     }
 
-    showHiddenFilesAction->setIcon(QIcon::fromTheme(shown ? QStringLiteral("visibility") : QStringLiteral("hint")));
+    showHiddenFilesAction->setIcon(QIcon::fromTheme(shown ? QStringLiteral("view-visible") : QStringLiteral("view-hidden")));
 }
 
 void DolphinViewActionHandler::slotWriteStateChanged(bool isFolderWritable)
@@ -583,11 +608,33 @@ void DolphinViewActionHandler::slotSortRoleChanged(const QByteArray& role)
             sortByMenu->setIcon(action->icon());
         }
     }
+
+    QAction* descending = m_actionCollection->action(QStringLiteral("descending"));
+    QAction* ascending = m_actionCollection->action(QStringLiteral("ascending"));
+
+    if (role == "text" || role == "type" || 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"));
+    } else if (role == "modificationtime" || role == "creationtime" || role == "accesstime") {
+        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"));
+    } else {
+        descending->setText(i18nc("Sort descending", "Descending"));
+        ascending->setText(i18nc("Sort ascending", "Ascending"));
+    }
+
+    slotSortOrderChanged(m_currentView->sortOrder());
 }
 
 void DolphinViewActionHandler::slotZoomLevelChanged(int current, int previous)
 {
-    Q_UNUSED(previous);
+    Q_UNUSED(previous)
 
     QAction* zoomInAction = m_actionCollection->action(KStandardAction::name(KStandardAction::ZoomIn));
     if (zoomInAction) {
@@ -606,9 +653,9 @@ void DolphinViewActionHandler::slotSortTriggered(QAction* action)
     // and several sub-menus. Because of this they don't have a common
     // action-group that assures an exclusive toggle-state between the main-menu
     // actions and the sub-menu-actions. If an action gets checked, it must
-    // be assured that all other actions get unchecked.
-    QAction* sortByMenu =  m_actionCollection->action(QStringLiteral("sort"));
-    foreach (QAction* groupAction, sortByMenu->menu()->actions()) {
+    // be assured that all other actions get unchecked, except the ascending/
+    // descending actions
+    for (QAction *groupAction : qAsConst(m_sortByActions)) {
         KActionMenu* actionMenu = qobject_cast<KActionMenu*>(groupAction);
         if (actionMenu) {
             foreach (QAction* subAction, actionMenu->menu()->actions()) {