X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/bb67def173f31819bb9a696627f9af71c7037dcd..f0d201dcf1fb46e172e950c6f1767c5e8e6b9495:/src/views/dolphinviewactionhandler.cpp diff --git a/src/views/dolphinviewactionhandler.cpp b/src/views/dolphinviewactionhandler.cpp index c9bab5f82..fc88f5c17 100644 --- a/src/views/dolphinviewactionhandler.cpp +++ b/src/views/dolphinviewactionhandler.cpp @@ -7,13 +7,13 @@ #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" -#ifdef HAVE_BALOO +#if HAVE_BALOO #include #endif #include @@ -28,7 +28,7 @@ #include #include -DolphinViewActionHandler::DolphinViewActionHandler(KActionCollection* collection, QObject* parent) : +DolphinViewActionHandler::DolphinViewActionHandler(KActionCollection* collection, SelectionMode::ActionTextHelper* actionTextHelper, QObject* parent) : QObject(parent), m_actionCollection(collection), m_currentView(nullptr), @@ -36,7 +36,7 @@ DolphinViewActionHandler::DolphinViewActionHandler(KActionCollection* collection m_visibleRoles() { Q_ASSERT(m_actionCollection); - createActions(); + createActions(actionTextHelper); } void DolphinViewActionHandler::setCurrentView(DolphinView* view) @@ -57,6 +57,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, @@ -69,6 +71,8 @@ void DolphinViewActionHandler::setCurrentView(DolphinView* view) this, &DolphinViewActionHandler::slotZoomLevelChanged); connect(view, &DolphinView::writeStateChanged, this, &DolphinViewActionHandler::slotWriteStateChanged); + connect(view, &DolphinView::selectionModeChangeRequested, + this, [this](bool enabled) { Q_EMIT selectionModeChangeTriggered(enabled); }); connect(view, &DolphinView::selectionChanged, this, &DolphinViewActionHandler::slotSelectionChanged); slotSelectionChanged(m_currentView->selectedItems()); @@ -79,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. @@ -155,10 +159,18 @@ void DolphinViewActionHandler::createActions() "This will copy the path of the first selected item into the clipboard." )); - copyPathAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy"))); + 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); + 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. @@ -211,7 +223,7 @@ void DolphinViewActionHandler::createActions() viewModeActions->addAction(compactAction); viewModeActions->addAction(detailsAction); viewModeActions->setToolBarMode(KSelectAction::MenuMode); - connect(viewModeActions, QOverload::of(&KSelectAction::triggered), this, &DolphinViewActionHandler::slotViewModeActionTriggered); + connect(viewModeActions, &KSelectAction::triggered, this, &DolphinViewActionHandler::slotViewModeActionTriggered); QAction* zoomInAction = KStandardAction::zoomIn(this, &DolphinViewActionHandler::zoomIn, @@ -253,6 +265,10 @@ void DolphinViewActionHandler::createActions() sortFoldersFirst->setText(i18nc("@action:inmenu Sort", "Folders First")); connect(sortFoldersFirst, &KToggleAction::triggered, this, &DolphinViewActionHandler::toggleSortFoldersFirst); + KToggleAction* sortHiddenLast = m_actionCollection->add(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_")); @@ -287,6 +303,7 @@ void DolphinViewActionHandler::createActions() sortByActionMenu->addAction(descendingAction); sortByActionMenu->addSeparator(); sortByActionMenu->addAction(sortFoldersFirst); + sortByActionMenu->addAction(sortHiddenLast); // View -> Additional Information QActionGroup* visibleRolesGroup = createFileItemRolesActionGroup(QStringLiteral("show_")); @@ -347,7 +364,7 @@ QActionGroup* DolphinViewActionHandler::createFileItemRolesActionGroup(const QSt QActionGroup* groupMenuGroup = nullptr; bool indexingEnabled = false; -#ifdef HAVE_BALOO +#if HAVE_BALOO Baloo::IndexerConfig config; indexingEnabled = config.fileIndexingEnabled(); #endif @@ -407,7 +424,7 @@ QActionGroup* DolphinViewActionHandler::createFileItemRolesActionGroup(const QSt void DolphinViewActionHandler::slotViewModeActionTriggered(QAction* action) { const DolphinView::Mode mode = action->data().value(); - m_currentView->setMode(mode); + m_currentView->setViewMode(mode); QAction* viewModeMenu = m_actionCollection->action(QStringLiteral("view_mode")); viewModeMenu->setIcon(action->icon()); @@ -415,20 +432,35 @@ void DolphinViewActionHandler::slotViewModeActionTriggered(QAction* action) void DolphinViewActionHandler::slotRename() { - Q_EMIT actionBeingHandled(); - m_currentView->renameSelectedItems(); + if (m_currentView->selectedItemsCount() == 0) { + 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() { - Q_EMIT actionBeingHandled(); - m_currentView->trashSelectedItems(); + if (m_currentView->selectedItemsCount() == 0) { + Q_EMIT selectionModeChangeTriggered(true, SelectionMode::BottomBar::Contents::MoveToTrashContents); + } else { + Q_EMIT actionBeingHandled(); + m_currentView->trashSelectedItems(); + Q_EMIT selectionModeChangeTriggered(false); + } } void DolphinViewActionHandler::slotDeleteItems() { - Q_EMIT actionBeingHandled(); - m_currentView->deleteSelectedItems(); + if (m_currentView->selectedItemsCount() == 0) { + Q_EMIT selectionModeChangeTriggered(true, SelectionMode::BottomBar::Contents::DeleteContents); + } else { + Q_EMIT actionBeingHandled(); + m_currentView->deleteSelectedItems(); + Q_EMIT selectionModeChangeTriggered(false); + } } void DolphinViewActionHandler::togglePreview(bool show) @@ -447,7 +479,7 @@ void DolphinViewActionHandler::slotPreviewsShownChanged(bool shown) QString DolphinViewActionHandler::currentViewModeActionName() const { - switch (m_currentView->mode()) { + switch (m_currentView->viewMode()) { case DolphinView::IconsView: return QStringLiteral("icons"); case DolphinView::DetailsView: @@ -481,6 +513,7 @@ void DolphinViewActionHandler::updateViewActions() slotSortOrderChanged(m_currentView->sortOrder()); slotSortFoldersFirstChanged(m_currentView->sortFoldersFirst()); + slotSortHiddenLastChanged(m_currentView->sortHiddenLast()); slotVisibleRolesChanged(m_currentView->visibleRoles(), QList()); slotGroupedSortingChanged(m_currentView->groupedSorting()); slotSortRoleChanged(m_currentView->sortRole()); @@ -516,6 +549,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")); @@ -530,6 +569,11 @@ 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) { Q_EMIT actionBeingHandled(); @@ -644,7 +688,7 @@ 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") { @@ -715,8 +759,13 @@ void DolphinViewActionHandler::slotAdjustViewProperties() void DolphinViewActionHandler::slotDuplicate() { - Q_EMIT actionBeingHandled(); - m_currentView->duplicateSelectedItems(); + if (m_currentView->selectedItemsCount() == 0) { + Q_EMIT selectionModeChangeTriggered(true, SelectionMode::BottomBar::Contents::DuplicateContents); + } else { + Q_EMIT actionBeingHandled(); + m_currentView->duplicateSelectedItems(); + Q_EMIT selectionModeChangeTriggered(false); + } } void DolphinViewActionHandler::slotProperties() @@ -738,55 +787,36 @@ void DolphinViewActionHandler::slotProperties() void DolphinViewActionHandler::slotCopyPath() { - m_currentView->copyPathToClipboard(); + if (m_currentView->selectedItemsCount() == 0) { + Q_EMIT selectionModeChangeTriggered(true, SelectionMode::BottomBar::Contents::CopyLocationContents); + } else { + m_currentView->copyPathToClipboard(); + Q_EMIT selectionModeChangeTriggered(false); + } } void DolphinViewActionHandler::slotSelectionChanged(const KFileItemList& selection) { QString basicActionsMenuText; - switch (selection.count()) { - case 0: + 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"); - break; - case 1: - basicActionsMenuText = - i18nc("@action:inmenu menu with actions like copy, paste, rename. %1 is the name of the singular selected file/folder.", - "Actions for \"%1\"", selection.first().name()); - break; - case 2: - basicActionsMenuText = - i18nc("@action:inmenu menu with actions like copy, paste, rename. %1 and %2 are names of files/folders.", - "Actions for \"%1\" and \"%2\"", selection.first().name(), selection.last().name()); - break; - case 3: - basicActionsMenuText = - i18nc("@action:inmenu menu with actions like copy, paste, rename. %1, %2 and %3 are names of files/folders.", - "Actions for \"%1\", \"%2\" and \"%3\"", - selection.first().name(), selection.at(1).name(), selection.last().name()); - break; - default: - basicActionsMenuText = QString(); - break; + } 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)); } - // At some point the added clarity from the text starts being less important than the menu width. - if (basicActionsMenuText.isEmpty() || basicActionsMenuText.length() > 40) { + if (basicActionsMenuText == QStringLiteral("NULL")) { const KFileItemListProperties properties(selection); - if (properties.isFile()) { - basicActionsMenuText = - i18ncp("@action:inmenu menu with actions like copy, paste, rename. %1 is the amount of selected files/folders.", - "Actions for One Selected File", "Actions for %1 Selected Files", selection.count()); - } else if (properties.isDirectory()) { - basicActionsMenuText = - i18ncp("@action:inmenu menu with actions like copy, paste, rename. %1 is the amount of selected files/folders.", - "Actions for One Selected Folder", "Actions for %1 Selected Folders", selection.count()); - } else { - 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()); - } + 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"));