#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 <Baloo/IndexerConfig>
#endif
#include <KActionCollection>
#include <QMenu>
#include <QPointer>
-DolphinViewActionHandler::DolphinViewActionHandler(KActionCollection* collection, QObject* parent) :
+DolphinViewActionHandler::DolphinViewActionHandler(KActionCollection* collection, SelectionMode::ActionTextHelper* actionTextHelper, QObject* parent) :
QObject(parent),
m_actionCollection(collection),
m_currentView(nullptr),
m_visibleRoles()
{
Q_ASSERT(m_actionCollection);
- createActions();
+ createActions(actionTextHelper);
}
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());
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.
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.
QActionGroup* groupMenuGroup = nullptr;
bool indexingEnabled = false;
-#ifdef HAVE_BALOO
+#if HAVE_BALOO
Baloo::IndexerConfig config;
indexingEnabled = config.fileIndexingEnabled();
#endif
void DolphinViewActionHandler::slotViewModeActionTriggered(QAction* action)
{
const DolphinView::Mode mode = action->data().value<DolphinView::Mode>();
- m_currentView->setMode(mode);
+ m_currentView->setViewMode(mode);
QAction* viewModeMenu = m_actionCollection->action(QStringLiteral("view_mode"));
viewModeMenu->setIcon(action->icon());
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)
QString DolphinViewActionHandler::currentViewModeActionName() const
{
- switch (m_currentView->mode()) {
+ switch (m_currentView->viewMode()) {
case DolphinView::IconsView:
return QStringLiteral("icons");
case DolphinView::DetailsView:
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") {
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()
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)