┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/views
diff options
context:
space:
mode:
Diffstat (limited to 'src/views')
-rw-r--r--src/views/dolphinview.cpp25
-rw-r--r--src/views/dolphinview.h20
-rw-r--r--src/views/dolphinviewactionhandler.cpp50
-rw-r--r--src/views/dolphinviewactionhandler.h4
4 files changed, 84 insertions, 15 deletions
diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp
index 0e97b8561..56867dd13 100644
--- a/src/views/dolphinview.cpp
+++ b/src/views/dolphinview.cpp
@@ -20,6 +20,7 @@
#include "kitemviews/kitemlistselectionmanager.h"
#include "kitemviews/private/kitemlistroleeditor.h"
#include "settings/viewmodes/viewmodesettings.h"
+#include "selectionmode/singleclickselectionproxystyle.h"
#include "versioncontrol/versioncontrolobserver.h"
#include "viewproperties.h"
#include "views/tooltips/tooltipmanager.h"
@@ -172,6 +173,7 @@ DolphinView::DolphinView(const QUrl& url, QWidget* parent) :
connect(controller, &KItemListController::increaseZoom, this, &DolphinView::slotIncreaseZoom);
connect(controller, &KItemListController::decreaseZoom, this, &DolphinView::slotDecreaseZoom);
connect(controller, &KItemListController::swipeUp, this, &DolphinView::slotSwipeUp);
+ connect(controller, &KItemListController::selectionModeRequested, this, &DolphinView::selectionModeRequested);
connect(m_model, &KFileItemModel::directoryLoadingStarted, this, &DolphinView::slotDirectoryLoadingStarted);
connect(m_model, &KFileItemModel::directoryLoadingCompleted, this, &DolphinView::slotDirectoryLoadingCompleted);
@@ -262,7 +264,7 @@ bool DolphinView::isActive() const
return m_active;
}
-void DolphinView::setMode(Mode mode)
+void DolphinView::setViewMode(Mode mode)
{
if (mode != m_mode) {
ViewProperties props(viewPropertiesUrl());
@@ -276,11 +278,30 @@ void DolphinView::setMode(Mode mode)
}
}
-DolphinView::Mode DolphinView::mode() const
+DolphinView::Mode DolphinView::viewMode() const
{
return m_mode;
}
+void DolphinView::setSelectionMode(const bool enabled)
+{
+ if (enabled) {
+ m_proxyStyle = std::make_unique<SingleClickSelectionProxyStyle>();
+ setStyle(m_proxyStyle.get());
+ m_view->setStyle(m_proxyStyle.get());
+ } else {
+ setStyle(QApplication::style());
+ m_view->setStyle(QApplication::style());
+ }
+ m_container->controller()->setSelectionMode(enabled);
+}
+
+bool DolphinView::selectionMode() const
+{
+ return m_container->controller()->selectionMode();
+}
+
+
void DolphinView::setPreviewsShown(bool show)
{
if (previewsShown() == show) {
diff --git a/src/views/dolphinview.h b/src/views/dolphinview.h
index d1ecf74ba..37af97137 100644
--- a/src/views/dolphinview.h
+++ b/src/views/dolphinview.h
@@ -23,6 +23,8 @@
#include <QUrl>
#include <QWidget>
+#include <memory>
+
typedef KIO::FileUndoManager::CommandType CommandType;
class QVBoxLayout;
class DolphinItemListView;
@@ -36,6 +38,7 @@ class ViewProperties;
class QLabel;
class QGraphicsSceneDragDropEvent;
class QHelpEvent;
+class QProxyStyle;
class QRegularExpression;
/**
@@ -106,8 +109,11 @@ public:
* (GeneralSettings::globalViewProps() returns false), then the
* changed view mode will be stored automatically.
*/
- void setMode(Mode mode);
- Mode mode() const;
+ void setViewMode(Mode mode);
+ Mode viewMode() const;
+
+ void setSelectionMode(bool enabled);
+ bool selectionMode() const;
/**
* Turns on the file preview for the all files of the current directory,
@@ -600,6 +606,13 @@ Q_SIGNALS:
void goForwardRequested();
/**
+ * Is emitted when the selection mode is requested for the current view.
+ * This typically happens on press and hold.
+ * @see KItemListController::longPress()
+ */
+ void selectionModeRequested();
+
+ /**
* Is emitted when the user wants to move the focus to another view.
*/
void toggleActiveViewRequested();
@@ -916,6 +929,9 @@ private:
QLabel* m_placeholderLabel;
QTimer* m_showLoadingPlaceholderTimer;
+ /// Used for selection mode. @see setSelectionMode()
+ std::unique_ptr<QProxyStyle> m_proxyStyle;
+
// For unit tests
friend class TestBase;
friend class DolphinDetailsViewTest;
diff --git a/src/views/dolphinviewactionhandler.cpp b/src/views/dolphinviewactionhandler.cpp
index f59daab42..a66d1f6dd 100644
--- a/src/views/dolphinviewactionhandler.cpp
+++ b/src/views/dolphinviewactionhandler.cpp
@@ -29,6 +29,8 @@
#include <QMenu>
#include <QPointer>
+#include <iostream>
+
DolphinViewActionHandler::DolphinViewActionHandler(KActionCollection* collection, QObject* parent) :
QObject(parent),
m_actionCollection(collection),
@@ -72,6 +74,8 @@ void DolphinViewActionHandler::setCurrentView(DolphinView* view)
this, &DolphinViewActionHandler::slotZoomLevelChanged);
connect(view, &DolphinView::writeStateChanged,
this, &DolphinViewActionHandler::slotWriteStateChanged);
+ connect(view, &DolphinView::selectionModeRequested,
+ this, [this]() { Q_EMIT setSelectionMode(true); });
connect(view, &DolphinView::selectionChanged,
this, &DolphinViewActionHandler::slotSelectionChanged);
slotSelectionChanged(m_currentView->selectedItems());
@@ -415,7 +419,7 @@ QActionGroup* DolphinViewActionHandler::createFileItemRolesActionGroup(const QSt
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());
@@ -423,20 +427,34 @@ void DolphinViewActionHandler::slotViewModeActionTriggered(QAction* action)
void DolphinViewActionHandler::slotRename()
{
- Q_EMIT actionBeingHandled();
- m_currentView->renameSelectedItems();
+ if (m_currentView->selectedItemsCount() == 0) {
+ Q_EMIT setSelectionMode(true, SelectionModeBottomBar::Contents::RenameContents);
+ } else {
+ Q_EMIT actionBeingHandled();
+ m_currentView->renameSelectedItems();
+ }
}
void DolphinViewActionHandler::slotTrashActivated()
{
- Q_EMIT actionBeingHandled();
- m_currentView->trashSelectedItems();
+ if (m_currentView->selectedItemsCount() == 0) {
+ Q_EMIT setSelectionMode(true, SelectionModeBottomBar::Contents::MoveToTrashContents);
+ } else {
+ Q_EMIT actionBeingHandled();
+ m_currentView->trashSelectedItems();
+ Q_EMIT setSelectionMode(false);
+ }
}
void DolphinViewActionHandler::slotDeleteItems()
{
- Q_EMIT actionBeingHandled();
- m_currentView->deleteSelectedItems();
+ if (m_currentView->selectedItemsCount() == 0) {
+ Q_EMIT setSelectionMode(true, SelectionModeBottomBar::Contents::DeleteContents);
+ } else {
+ Q_EMIT actionBeingHandled();
+ m_currentView->deleteSelectedItems();
+ Q_EMIT setSelectionMode(false);
+ }
}
void DolphinViewActionHandler::togglePreview(bool show)
@@ -455,7 +473,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:
@@ -735,8 +753,13 @@ void DolphinViewActionHandler::slotAdjustViewProperties()
void DolphinViewActionHandler::slotDuplicate()
{
- Q_EMIT actionBeingHandled();
- m_currentView->duplicateSelectedItems();
+ if (m_currentView->selectedItemsCount() == 0) {
+ Q_EMIT setSelectionMode(true, SelectionModeBottomBar::Contents::DuplicateContents);
+ } else {
+ Q_EMIT actionBeingHandled();
+ m_currentView->duplicateSelectedItems();
+ Q_EMIT setSelectionMode(false);
+ }
}
void DolphinViewActionHandler::slotProperties()
@@ -758,7 +781,12 @@ void DolphinViewActionHandler::slotProperties()
void DolphinViewActionHandler::slotCopyPath()
{
- m_currentView->copyPathToClipboard();
+ if (m_currentView->selectedItemsCount() == 0) {
+ Q_EMIT setSelectionMode(true, SelectionModeBottomBar::Contents::CopyLocationContents);
+ } else {
+ m_currentView->copyPathToClipboard();
+ Q_EMIT setSelectionMode(false);
+ }
}
void DolphinViewActionHandler::slotSelectionChanged(const KFileItemList& selection)
diff --git a/src/views/dolphinviewactionhandler.h b/src/views/dolphinviewactionhandler.h
index 6e9b4a432..f35512a5f 100644
--- a/src/views/dolphinviewactionhandler.h
+++ b/src/views/dolphinviewactionhandler.h
@@ -10,6 +10,7 @@
#define DOLPHINVIEWACTIONHANDLER_H
#include "dolphin_export.h"
+#include "selectionmode/selectionmodebottombar.h"
#include "views/dolphinview.h"
#include <QObject>
@@ -83,6 +84,9 @@ Q_SIGNALS:
*/
void createDirectoryTriggered();
+ /** Used to request selection mode */
+ void setSelectionMode(bool enabled, SelectionModeBottomBar::Contents bottomBarContents = SelectionModeBottomBar::Contents::GeneralContents);
+
private Q_SLOTS:
/**
* Emitted when the user requested a change of view mode