From cffa47cf6e5d22bc3986ffe8ebd03badb5e34fb4 Mon Sep 17 00:00:00 2001 From: cutefishd Date: Thu, 1 Apr 2021 10:25:20 +0800 Subject: [PATCH] Support delete keypress --- debian/control | 1 + model/foldermodel.cpp | 14 ++++++++++++++ model/foldermodel.h | 3 +++ qml/FolderGridItem.qml | 3 +-- qml/FolderPage.qml | 2 ++ 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/debian/control b/debian/control index 449f6ad..6038d45 100644 --- a/debian/control +++ b/debian/control @@ -26,6 +26,7 @@ Depends: qml-module-qtquick-controls2, qml-module-qtqml, qml-module-qtquick-window2, qml-module-qtquick-shapes, + qml-module-qtquick-dialogs, ${misc:Depends}, ${shlibs:Depends} Description: CutefishOS File Manager diff --git a/model/foldermodel.cpp b/model/foldermodel.cpp index 0328d2b..c777cf7 100644 --- a/model/foldermodel.cpp +++ b/model/foldermodel.cpp @@ -424,6 +424,11 @@ QString FolderModel::statusText() return tr("%1 items").arg(m_dirModel->rowCount()); } +int FolderModel::selectionCound() const +{ + return m_selectionModel->selectedIndexes().size(); +} + QString FolderModel::homePath() const { return QStandardPaths::writableLocation(QStandardPaths::HomeLocation); @@ -722,6 +727,14 @@ void FolderModel::emptyTrash() } } +void FolderModel::keyDeletePress() +{ + if (!m_selectionModel->hasSelection()) + return; + + resolvedUrl().scheme() == "trash" ? deleteSelected() : moveSelectedToTrash(); +} + void FolderModel::setDragHotSpotScrollOffset(int x, int y) { m_dragHotSpotScrollOffset.setX(x); @@ -898,6 +911,7 @@ void FolderModel::selectionChanged(const QItemSelection &selected, const QItemSe // 选中状态信息 emit statusTextChanged(); + emit selectionCoundChanged(); } void FolderModel::dragSelectedInternal(int x, int y) diff --git a/model/foldermodel.h b/model/foldermodel.h index 2760e3b..3f7c507 100644 --- a/model/foldermodel.h +++ b/model/foldermodel.h @@ -104,6 +104,7 @@ public: KFileItem rootItem() const; QString statusText(); + int selectionCound() const; Q_INVOKABLE QString homePath() const; Q_INVOKABLE QString desktopPath() const; @@ -137,6 +138,7 @@ public: Q_INVOKABLE void deleteSelected(); Q_INVOKABLE void moveSelectedToTrash(); Q_INVOKABLE void emptyTrash(); + Q_INVOKABLE void keyDeletePress(); Q_INVOKABLE void setDragHotSpotScrollOffset(int x, int y); Q_INVOKABLE void addItemDragImage(int row, int x, int y, int width, int height, const QVariant &image); @@ -164,6 +166,7 @@ signals: void viewAdapterChanged(); void statusTextChanged(); void isDesktopChanged(); + void selectionCoundChanged(); private slots: void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected); diff --git a/qml/FolderGridItem.qml b/qml/FolderGridItem.qml index 2cfef75..cdd9321 100644 --- a/qml/FolderGridItem.qml +++ b/qml/FolderGridItem.qml @@ -96,8 +96,7 @@ Item { anchors.topMargin: Meui.Units.smallSpacing maximumLineCount: 2 horizontalAlignment: Text.AlignHCenter - width: Math.round(Math.min(_label.implicitWidth + Meui.Units.smallSpacing, - parent.width - Meui.Units.largeSpacing * 2)) + width: parent.width - Meui.Units.largeSpacing * 2 textFormat: Text.PlainText elide: Qt.ElideRight wrapMode: Text.Wrap diff --git a/qml/FolderPage.qml b/qml/FolderPage.qml index 0b4a0f7..d259aa4 100644 --- a/qml/FolderPage.qml +++ b/qml/FolderPage.qml @@ -215,6 +215,8 @@ Item { folderModel.selectAll() else if (event.key === Qt.Key_Backspace) folderModel.up() + else if (event.key === Qt.Key_Delete) + folderModel.keyDeletePress() } }