feat(trash): support move to trash
This commit is contained in:
parent
36fa1781ea
commit
c189b0fb19
4 changed files with 28 additions and 2 deletions
|
@ -57,6 +57,7 @@ Item {
|
|||
signal clicked(var mouse)
|
||||
signal rightClicked(var mouse)
|
||||
signal doubleClicked(var mouse)
|
||||
signal dropped(var drop)
|
||||
|
||||
Drag.active: mouseArea.drag.active && control.draggable
|
||||
Drag.dragType: Drag.Automatic
|
||||
|
@ -94,6 +95,7 @@ Item {
|
|||
id: iconDropArea
|
||||
anchors.fill: icon
|
||||
enabled: draggable
|
||||
onDropped: control.dropped(drop)
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
|
|
11
qml/main.qml
11
qml/main.qml
|
@ -142,14 +142,21 @@ Item {
|
|||
|
||||
dropArea.enabled: true
|
||||
|
||||
onDropped: {
|
||||
if (drop.hasUrls) {
|
||||
trash.moveToTrash(drop.urls)
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
anchors.margins: FishUI.Units.smallSpacing / 2
|
||||
color: "transparent"
|
||||
border.color: FishUI.Theme.textColor
|
||||
radius: height * 0.3
|
||||
border.width: 1
|
||||
opacity: trashItem.dropArea.containsDrag ? 0.8 : 0
|
||||
border.width: 1 / FishUI.Units.devicePixelRatio
|
||||
border.pixelAligned: FishUI.Units.devicePixelRatio > 1 ? false : true
|
||||
opacity: trashItem.dropArea.containsDrag ? 0.5 : 0
|
||||
|
||||
Behavior on opacity {
|
||||
NumberAnimation {
|
||||
|
|
|
@ -17,8 +17,11 @@
|
|||
*/
|
||||
|
||||
#include "trashmanager.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QProcess>
|
||||
#include <QDir>
|
||||
#include <QUrl>
|
||||
|
||||
const QString TrashDir = QDir::homePath() + "/.local/share/Trash";
|
||||
const QDir::Filters ItemsShouldCount = QDir::AllEntries | QDir::Hidden | QDir::System | QDir::NoDotAndDotDot;
|
||||
|
@ -32,6 +35,19 @@ TrashManager::TrashManager(QObject *parent)
|
|||
connect(m_filesWatcher, &QFileSystemWatcher::directoryChanged, this, &TrashManager::onDirectoryChanged, Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
void TrashManager::moveToTrash(QList<QUrl> urls)
|
||||
{
|
||||
QStringList paths;
|
||||
|
||||
for (const QUrl &url : urls) {
|
||||
if (!url.isLocalFile())
|
||||
continue;
|
||||
paths.append(url.toLocalFile());
|
||||
}
|
||||
|
||||
QProcess::startDetached("cutefish-filemanager", QStringList() << "--move-to-trash" << paths);
|
||||
}
|
||||
|
||||
void TrashManager::emptyTrash()
|
||||
{
|
||||
QProcess::startDetached("cutefish-filemanager", QStringList() << "-e");
|
||||
|
|
|
@ -31,6 +31,7 @@ class TrashManager : public QObject
|
|||
public:
|
||||
explicit TrashManager(QObject *parent = nullptr);
|
||||
|
||||
Q_INVOKABLE void moveToTrash(QList<QUrl> urls);
|
||||
Q_INVOKABLE void openTrash();
|
||||
Q_INVOKABLE void emptyTrash();
|
||||
|
||||
|
|
Loading…
Reference in a new issue