X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/64e40c1d934247fc9e1c2fa00761b2cb8d70a146..b4e80645e8e39ef7fcc1545136bad06ab3dd5f3e:/src/views/dolphinviewactionhandler.cpp diff --git a/src/views/dolphinviewactionhandler.cpp b/src/views/dolphinviewactionhandler.cpp index 397ff5d5e..14600c133 100644 --- a/src/views/dolphinviewactionhandler.cpp +++ b/src/views/dolphinviewactionhandler.cpp @@ -12,6 +12,7 @@ #include "selectionmode/actiontexthelper.h" #include "settings/viewpropertiesdialog.h" #include "views/zoomlevelinfo.h" +#include "views/zoomwidgetaction.h" #if HAVE_BALOO #include @@ -33,6 +34,7 @@ DolphinViewActionHandler::DolphinViewActionHandler(KActionCollection *collection , m_actionCollection(collection) , m_currentView(nullptr) , m_sortByActions() + , m_groupByActions() , m_visibleRoles() { Q_ASSERT(m_actionCollection); @@ -58,8 +60,11 @@ void DolphinViewActionHandler::setCurrentView(DolphinView *view) connect(view, &DolphinView::groupedSortingChanged, this, &DolphinViewActionHandler::slotGroupedSortingChanged); connect(view, &DolphinView::hiddenFilesShownChanged, this, &DolphinViewActionHandler::slotHiddenFilesShownChanged); connect(view, &DolphinView::sortRoleChanged, this, &DolphinViewActionHandler::slotSortRoleChanged); + connect(view, &DolphinView::groupRoleChanged, this, &DolphinViewActionHandler::slotGroupRoleChanged); + connect(view, &DolphinView::groupOrderChanged, this, &DolphinViewActionHandler::slotGroupOrderChanged); connect(view, &DolphinView::zoomLevelChanged, this, &DolphinViewActionHandler::slotZoomLevelChanged); connect(view, &DolphinView::writeStateChanged, this, &DolphinViewActionHandler::slotWriteStateChanged); + slotWriteStateChanged(view->isFolderWritable()); connect(view, &DolphinView::selectionModeChangeRequested, this, [this](bool enabled) { Q_EMIT selectionModeChangeTriggered(enabled); }); @@ -83,13 +88,19 @@ void DolphinViewActionHandler::createActions(SelectionMode::ActionTextHelper *ac newDirAction->setEnabled(false); // Will be enabled in slotWriteStateChanged(bool) if the current URL is writable connect(newDirAction, &QAction::triggered, this, &DolphinViewActionHandler::createDirectoryTriggered); + QAction *newFileAction = m_actionCollection->addAction(QStringLiteral("create_file")); + newFileAction->setText(i18nc("@action", "Create File…")); + newFileAction->setIcon(QIcon::fromTheme(QStringLiteral("document-new"))); + newFileAction->setEnabled(false); // Will be enabled in slotWriteStateChanged(bool) if the current URL is writable + connect(newFileAction, &QAction::triggered, this, &DolphinViewActionHandler::createFileTriggered); + // File menu auto renameAction = KStandardAction::renameFile(this, &DolphinViewActionHandler::slotRename, m_actionCollection); renameAction->setWhatsThis(xi18nc("@info:whatsthis", "This renames the " "items in your current selection.Renaming multiple items " - "at once amounts to their new names differing only in a number.")); + "at once results in their new names differing only in a number.")); auto trashAction = KStandardAction::moveToTrash(this, &DolphinViewActionHandler::slotTrashActivated, m_actionCollection); auto trashShortcuts = trashAction->shortcuts(); @@ -101,8 +112,8 @@ void DolphinViewActionHandler::createActions(SelectionMode::ActionTextHelper *ac trashAction->setWhatsThis(xi18nc("@info:whatsthis", "This moves the " "items in your current selection to the Trash" - ".The trash is a temporary storage where " - "items can be deleted from if disk space is needed.")); + ".The trash is a temporary storage location where " + "items can be deleted later if disk space is needed.")); auto deleteAction = KStandardAction::deleteFile(this, &DolphinViewActionHandler::slotDeleteItems, m_actionCollection); auto deleteShortcuts = deleteAction->shortcuts(); @@ -113,8 +124,8 @@ void DolphinViewActionHandler::createActions(SelectionMode::ActionTextHelper *ac } deleteAction->setWhatsThis(xi18nc("@info:whatsthis", "This deletes " - "the items in your current selection completely. They can " - "not be recovered by normal means.")); + "the items in your current selection permanently. They " + "cannot 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 @@ -198,7 +209,7 @@ void DolphinViewActionHandler::createActions(SelectionMode::ActionTextHelper *ac compactAction->setWhatsThis(xi18nc("@info:whatsthis Compact view mode", "This switches to a compact view mode that lists the folders " "and files in columns with the names beside the icons." - "This helps to keep the overview in folders with many items.")); + "This helps to give you an overview in folders with many items.")); detailsAction->setWhatsThis(xi18nc("@info:whatsthis Details view mode", "This switches to a list view mode that focuses on folder " "and file details.Click on a detail in the column " @@ -206,16 +217,29 @@ void DolphinViewActionHandler::createActions(SelectionMode::ActionTextHelper *ac "way around. To select which details should be displayed click " "the header with the right mouse button.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.")); + "location by clicking the region to the left of it. This way you can " + "view the contents of multiple folders in the same list.")); KSelectAction *viewModeActions = m_actionCollection->add(QStringLiteral("view_mode")); - viewModeActions->setText(i18nc("@action:intoolbar", "View Mode")); + viewModeActions->setText(i18nc("@action:intoolbar", "Change View Mode")); + viewModeActions->setWhatsThis(xi18nc("@info:whatsthis View Mode Toolbutton", "This cycles through all view modes.")); viewModeActions->addAction(iconsAction); viewModeActions->addAction(compactAction); viewModeActions->addAction(detailsAction); viewModeActions->setToolBarMode(KSelectAction::MenuMode); + viewModeActions->setToolButtonPopupMode(QToolButton::ToolButtonPopupMode::MenuButtonPopup); connect(viewModeActions, &KSelectAction::actionTriggered, this, &DolphinViewActionHandler::slotViewModeActionTriggered); + connect(viewModeActions, &KSelectAction::triggered, this, [this, viewModeActions, iconsAction, compactAction, detailsAction]() { + // Loop through the actions when button is clicked + const auto currentAction = viewModeActions->currentAction(); + if (currentAction == iconsAction) { + slotViewModeActionTriggered(compactAction); + } else if (currentAction == compactAction) { + slotViewModeActionTriggered(detailsAction); + } else if (currentAction == detailsAction) { + slotViewModeActionTriggered(iconsAction); + } + }); QAction *zoomInAction = KStandardAction::zoomIn(this, &DolphinViewActionHandler::zoomIn, m_actionCollection); zoomInAction->setWhatsThis(i18nc("@info:whatsthis zoom in", "This increases the icon size.")); @@ -231,13 +255,8 @@ void DolphinViewActionHandler::createActions(SelectionMode::ActionTextHelper *ac QAction *zoomOutAction = KStandardAction::zoomOut(this, &DolphinViewActionHandler::zoomOut, m_actionCollection); zoomOutAction->setWhatsThis(i18nc("@info:whatsthis zoom out", "This reduces the icon size.")); - KActionMenu *zoomMenu = m_actionCollection->add(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); + ZoomWidgetAction *zoomWidgetAction = new ZoomWidgetAction(zoomInAction, zoomResetAction, zoomOutAction, m_actionCollection); + m_actionCollection->addAction(QStringLiteral("zoom"), zoomWidgetAction); KToggleAction *showPreview = m_actionCollection->add(QStringLiteral("show_preview")); showPreview->setText(i18nc("@action:intoolbar", "Show Previews")); @@ -248,6 +267,7 @@ void DolphinViewActionHandler::createActions(SelectionMode::ActionTextHelper *ac "contents.For example the icons of images become scaled " "down versions of the images.")); showPreview->setIcon(QIcon::fromTheme(QStringLiteral("view-preview"))); + m_actionCollection->setDefaultShortcut(showPreview, QKeySequence(Qt::Key_F12)); connect(showPreview, &KToggleAction::triggered, this, &DolphinViewActionHandler::togglePreview); KToggleAction *sortFoldersFirst = m_actionCollection->add(QStringLiteral("folders_first")); @@ -273,27 +293,60 @@ void DolphinViewActionHandler::createActions(SelectionMode::ActionTextHelper *ac sortByActionMenu->addSeparator(); - QActionGroup *group = new QActionGroup(sortByActionMenu); - group->setExclusive(true); + QActionGroup *groupForSort = new QActionGroup(sortByActionMenu); + groupForSort->setExclusive(true); - KToggleAction *ascendingAction = m_actionCollection->add(QStringLiteral("ascending")); - ascendingAction->setActionGroup(group); - connect(ascendingAction, &QAction::triggered, this, [this] { + KToggleAction *sortAscendingAction = m_actionCollection->add(QStringLiteral("sort_ascending")); + sortAscendingAction->setActionGroup(groupForSort); + connect(sortAscendingAction, &QAction::triggered, this, [this] { m_currentView->setSortOrder(Qt::AscendingOrder); }); - KToggleAction *descendingAction = m_actionCollection->add(QStringLiteral("descending")); - descendingAction->setActionGroup(group); - connect(descendingAction, &QAction::triggered, this, [this] { + KToggleAction *sortDescendingAction = m_actionCollection->add(QStringLiteral("sort_descending")); + sortDescendingAction->setActionGroup(groupForSort); + connect(sortDescendingAction, &QAction::triggered, this, [this] { m_currentView->setSortOrder(Qt::DescendingOrder); }); - sortByActionMenu->addAction(ascendingAction); - sortByActionMenu->addAction(descendingAction); + sortByActionMenu->addAction(sortAscendingAction); + sortByActionMenu->addAction(sortDescendingAction); sortByActionMenu->addSeparator(); sortByActionMenu->addAction(sortFoldersFirst); sortByActionMenu->addAction(sortHiddenLast); + // View -> Group By + QActionGroup *groupByActionGroup = createFileItemRolesActionGroup(QStringLiteral("group_by_")); + + KActionMenu *groupByActionMenu = m_actionCollection->add(QStringLiteral("group")); + groupByActionMenu->setIcon(QIcon::fromTheme(QStringLiteral("view-group"))); + groupByActionMenu->setText(i18nc("@action:inmenu View", "Group By")); + groupByActionMenu->setPopupMode(QToolButton::InstantPopup); + + const auto groupByActionGroupActions = groupByActionGroup->actions(); + for (QAction *action : groupByActionGroupActions) { + groupByActionMenu->addAction(action); + } + + groupByActionMenu->addSeparator(); + + QActionGroup *groupForGroup = new QActionGroup(groupByActionMenu); + groupForGroup->setExclusive(true); + + KToggleAction *groupAscendingAction = m_actionCollection->add(QStringLiteral("group_ascending")); + groupAscendingAction->setActionGroup(groupForGroup); + connect(groupAscendingAction, &QAction::triggered, this, [this] { + m_currentView->setGroupOrder(Qt::AscendingOrder); + }); + + KToggleAction *groupDescendingAction = m_actionCollection->add(QStringLiteral("group_descending")); + groupDescendingAction->setActionGroup(groupForGroup); + connect(groupDescendingAction, &QAction::triggered, this, [this] { + m_currentView->setGroupOrder(Qt::DescendingOrder); + }); + + groupByActionMenu->addAction(groupAscendingAction); + groupByActionMenu->addAction(groupDescendingAction); + // View -> Additional Information QActionGroup *visibleRolesGroup = createFileItemRolesActionGroup(QStringLiteral("show_")); @@ -318,11 +371,15 @@ void DolphinViewActionHandler::createActions(SelectionMode::ActionTextHelper *ac showHiddenFiles->setText(i18nc("@action:inmenu View", "Show Hidden Files")); showHiddenFiles->setWhatsThis(xi18nc("@info:whatsthis", "When " - "this is enabled hidden files and folders " + "this is enabled, hidden files and folders " "are visible. They will be displayed semi-transparent." - "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.")); + "Hidden items only differ from normal ones in that their " + "name starts with a dot (\".\"). Typically, there is no need for " + "users to access them, which is why they are hidden." + "Items can also be hidden if their names are listed in a text file " + "named \".hidden\". Files with the \"application/x-trash\" MIME type, " + "such as backup files, can also be hidden by enabling that setting in " + "Configure Dolphin > View > General.")); m_actionCollection->setDefaultShortcuts(showHiddenFiles, KStandardShortcut::showHideHiddenFiles()); connect(showHiddenFiles, &KToggleAction::triggered, this, &DolphinViewActionHandler::toggleShowHiddenFiles); @@ -333,17 +390,40 @@ void DolphinViewActionHandler::createActions(SelectionMode::ActionTextHelper *ac "This opens a window " "in which all folder view properties can be adjusted.")); connect(adjustViewProps, &QAction::triggered, this, &DolphinViewActionHandler::slotAdjustViewProperties); + + // View settings: the dropdown menu contains various view-related actions + KActionMenu *viewSettings = m_actionCollection->add(QStringLiteral("view_settings")); + viewSettings->setText(i18nc("@action:intoolbar", "View Settings")); + viewSettings->setWhatsThis( + xi18nc("@info:whatsthis View Settings Toolbutton", "This cycles through all view modes. The dropdown menu contains various view-related actions.")); + const auto actions = viewModeActions->actions(); + for (QAction *action : actions) { + viewSettings->addAction(action); + } + viewSettings->addSeparator(); + viewSettings->addAction(zoomWidgetAction); + viewSettings->addAction(sortByActionMenu); + viewSettings->addAction(visibleRolesMenu); + viewSettings->addAction(showPreview); + viewSettings->addAction(showInGroups); + viewSettings->addAction(showHiddenFiles); + viewSettings->addAction(adjustViewProps); + viewSettings->setPopupMode(QToolButton::ToolButtonPopupMode::MenuButtonPopup); + connect(viewSettings, &KActionMenu::triggered, viewModeActions, &KSelectAction::triggered); } QActionGroup *DolphinViewActionHandler::createFileItemRolesActionGroup(const QString &groupPrefix) { const bool isSortGroup = (groupPrefix == QLatin1String("sort_by_")); - Q_ASSERT(isSortGroup || groupPrefix == QLatin1String("show_")); + const bool isGroupGroup = (groupPrefix == QLatin1String("group_by_")); + Q_ASSERT(isSortGroup || isGroupGroup || groupPrefix == QLatin1String("show_")); QActionGroup *rolesActionGroup = new QActionGroup(m_actionCollection); - rolesActionGroup->setExclusive(isSortGroup); + rolesActionGroup->setExclusive(isSortGroup || isGroupGroup); if (isSortGroup) { connect(rolesActionGroup, &QActionGroup::triggered, this, &DolphinViewActionHandler::slotSortTriggered); + } else if (isGroupGroup) { + connect(rolesActionGroup, &QActionGroup::triggered, this, &DolphinViewActionHandler::slotGroupTriggered); } else { connect(rolesActionGroup, &QActionGroup::triggered, this, &DolphinViewActionHandler::toggleVisibleRole); } @@ -358,9 +438,13 @@ QActionGroup *DolphinViewActionHandler::createFileItemRolesActionGroup(const QSt indexingEnabled = config.fileIndexingEnabled(); #endif - const QList rolesInfo = KFileItemModel::rolesInformation(); + QList rolesInfo = KFileItemModel::rolesInformation(); + if (isGroupGroup) { + rolesInfo += KFileItemModel::extraGroupingInformation(); + } + for (const KFileItemModel::RoleInfo &info : rolesInfo) { - if (!isSortGroup && info.role == "text") { + if (!isSortGroup && !isGroupGroup && info.role == "text") { // It should not be possible to hide the "text" role continue; } @@ -378,9 +462,11 @@ QActionGroup *DolphinViewActionHandler::createFileItemRolesActionGroup(const QSt groupMenu->setActionGroup(rolesActionGroup); groupMenuGroup = new QActionGroup(groupMenu); - groupMenuGroup->setExclusive(isSortGroup); + groupMenuGroup->setExclusive(isSortGroup || isGroupGroup); if (isSortGroup) { connect(groupMenuGroup, &QActionGroup::triggered, this, &DolphinViewActionHandler::slotSortTriggered); + } else if (isGroupGroup) { + connect(groupMenuGroup, &QActionGroup::triggered, this, &DolphinViewActionHandler::slotGroupTriggered); } else { connect(groupMenuGroup, &QActionGroup::triggered, this, &DolphinViewActionHandler::toggleVisibleRole); } @@ -398,6 +484,8 @@ QActionGroup *DolphinViewActionHandler::createFileItemRolesActionGroup(const QSt if (isSortGroup) { m_sortByActions.insert(info.role, action); + } else if (isGroupGroup) { + m_groupByActions.insert(info.role, action); } else { m_visibleRoles.insert(info.role, action); } @@ -413,6 +501,9 @@ void DolphinViewActionHandler::slotViewModeActionTriggered(QAction *action) QAction *viewModeMenu = m_actionCollection->action(QStringLiteral("view_mode")); viewModeMenu->setIcon(action->icon()); + + QAction *viewSettingsAction = m_actionCollection->action(QStringLiteral("view_settings")); + viewSettingsAction->setIcon(action->icon()); } void DolphinViewActionHandler::slotRename() @@ -491,6 +582,9 @@ void DolphinViewActionHandler::updateViewActions() QAction *viewModeMenu = m_actionCollection->action(QStringLiteral("view_mode")); viewModeMenu->setIcon(viewModeAction->icon()); + + QAction *viewSettingsAction = m_actionCollection->action(QStringLiteral("view_settings")); + viewSettingsAction->setIcon(viewModeAction->icon()); } QAction *showPreviewAction = m_actionCollection->action(QStringLiteral("show_preview")); @@ -502,6 +596,8 @@ void DolphinViewActionHandler::updateViewActions() slotVisibleRolesChanged(m_currentView->visibleRoles(), QList()); slotGroupedSortingChanged(m_currentView->groupedSorting()); slotSortRoleChanged(m_currentView->sortRole()); + slotGroupRoleChanged(m_currentView->groupRole()); + slotGroupOrderChanged(m_currentView->groupOrder()); slotZoomLevelChanged(m_currentView->zoomLevel(), -1); // Updates the "show_hidden_files" action state and icon @@ -542,13 +638,22 @@ void DolphinViewActionHandler::toggleSortHiddenLast() void DolphinViewActionHandler::slotSortOrderChanged(Qt::SortOrder order) { - QAction *descending = m_actionCollection->action(QStringLiteral("descending")); - QAction *ascending = m_actionCollection->action(QStringLiteral("ascending")); + QAction *descending = m_actionCollection->action(QStringLiteral("sort_descending")); + QAction *ascending = m_actionCollection->action(QStringLiteral("sort_ascending")); const bool sortDescending = (order == Qt::DescendingOrder); descending->setChecked(sortDescending); ascending->setChecked(!sortDescending); } +void DolphinViewActionHandler::slotGroupOrderChanged(Qt::SortOrder order) +{ + QAction *descending = m_actionCollection->action(QStringLiteral("group_descending")); + QAction *ascending = m_actionCollection->action(QStringLiteral("group_ascending")); + const bool groupDescending = (order == Qt::DescendingOrder); + descending->setChecked(groupDescending); + ascending->setChecked(!groupDescending); +} + void DolphinViewActionHandler::slotSortFoldersFirstChanged(bool foldersFirst) { m_actionCollection->action(QStringLiteral("folders_first"))->setChecked(foldersFirst); @@ -620,7 +725,9 @@ void DolphinViewActionHandler::slotHiddenFilesShownChanged(bool shown) void DolphinViewActionHandler::slotWriteStateChanged(bool isFolderWritable) { - m_actionCollection->action(QStringLiteral("create_dir"))->setEnabled(isFolderWritable && KProtocolManager::supportsMakeDir(currentView()->url())); + const bool supportsMakeDir = KProtocolManager::supportsMakeDir(currentView()->url()); + m_actionCollection->action(QStringLiteral("create_dir"))->setEnabled(isFolderWritable && supportsMakeDir); + m_actionCollection->action(QStringLiteral("create_file"))->setEnabled(isFolderWritable); } KToggleAction *DolphinViewActionHandler::iconsModeAction() @@ -668,8 +775,8 @@ void DolphinViewActionHandler::slotSortRoleChanged(const QByteArray &role) } } - QAction *descending = m_actionCollection->action(QStringLiteral("descending")); - QAction *ascending = m_actionCollection->action(QStringLiteral("ascending")); + QAction *descending = m_actionCollection->action(QStringLiteral("sort_descending")); + QAction *ascending = m_actionCollection->action(QStringLiteral("sort_ascending")); if (role == "text" || role == "type" || role == "extension" || role == "tags" || role == "comment") { descending->setText(i18nc("Sort descending", "Z-A")); @@ -691,6 +798,50 @@ void DolphinViewActionHandler::slotSortRoleChanged(const QByteArray &role) slotSortOrderChanged(m_currentView->sortOrder()); } +void DolphinViewActionHandler::slotGroupRoleChanged(const QByteArray &role) +{ + KToggleAction *action = m_groupByActions.value(role); + if (action) { + action->setChecked(true); + + if (!action->icon().isNull()) { + QAction *groupByMenu = m_actionCollection->action(QStringLiteral("group")); + groupByMenu->setIcon(action->icon()); + } + } + + QAction *descending = m_actionCollection->action(QStringLiteral("group_descending")); + QAction *ascending = m_actionCollection->action(QStringLiteral("group_ascending")); + + if (role == "text" || role == "type" || role == "extension" || role == "tags" || role == "comment") { + descending->setText(i18nc("Group descending", "Z-A")); + ascending->setText(i18nc("Group ascending", "A-Z")); + } else if (role == "size") { + descending->setText(i18nc("Group descending", "Largest First")); + ascending->setText(i18nc("Group ascending", "Smallest First")); + } else if (role == "modificationtime" || role == "creationtime" || role == "accesstime") { + descending->setText(i18nc("Group descending", "Newest First")); + ascending->setText(i18nc("Group ascending", "Oldest First")); + } else if (role == "rating") { + descending->setText(i18nc("Group descending", "Highest First")); + ascending->setText(i18nc("Group ascending", "Lowest First")); + } else { + descending->setText(i18nc("Group descending", "Descending")); + ascending->setText(i18nc("Group ascending", "Ascending")); + } + + // Disable group order selector if grouping behavior does not support it + if (role == "none" || role == "followSort") { + descending->setEnabled(false); + ascending->setEnabled(false); + } else { + descending->setEnabled(true); + ascending->setEnabled(true); + } + + slotGroupOrderChanged(m_currentView->groupOrder()); +} + void DolphinViewActionHandler::slotZoomLevelChanged(int current, int previous) { Q_UNUSED(previous) @@ -732,6 +883,32 @@ void DolphinViewActionHandler::slotSortTriggered(QAction *action) m_currentView->setSortRole(role); } +void DolphinViewActionHandler::slotGroupTriggered(QAction *action) +{ + // The radiobuttons of the "Group By"-menu are split between the main-menu + // 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, except the ascending/ + // descending actions + for (QAction *groupAction : std::as_const(m_groupByActions)) { + KActionMenu *actionMenu = qobject_cast(groupAction); + if (actionMenu) { + const auto actions = actionMenu->menu()->actions(); + for (QAction *subAction : actions) { + subAction->setChecked(false); + } + } else if (groupAction->actionGroup()) { + groupAction->setChecked(false); + } + } + action->setChecked(true); + + // Apply the activated sort-role to the view + const QByteArray role = action->data().toByteArray(); + m_currentView->setGroupRole(role); +} + void DolphinViewActionHandler::slotAdjustViewProperties() { Q_EMIT actionBeingHandled();