Skip to content

Commit 83021e8

Browse files
wjyrich18202781743
authored andcommitted
feat: add trash file drop support
Added functionality to handle file drops on the trash icon in the task manager 1. Implemented moveFilesToTrash method that converts URL paths to local files and moves them to system trash 2. Added file drop detection for "dde-trash" item ID with proper debug logging 3. Included necessary Qt headers for file operations (QFile, QFileInfo, QProcess, QUrl) 4. Added error handling for empty file paths with warning messages feat: 添加回收站文件拖放支持 在任务管理器中添加了对回收站图标的文件拖放处理功能 1. 实现了moveFilesToTrash方法,将URL路径转换为本地文件并移动到系统回收站 2. 添加了对"dde-trash"项目ID的文件拖放检测,包含适当的调试日志 3. 包含了文件操作所需的Qt头文件(QFile、QFileInfo、QProcess、QUrl) 4. 为空的文件路径添加了错误处理,包含警告消息 Pms: BUG-271091
1 parent 3c507cd commit 83021e8

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

panels/dock/taskmanager/taskmanager.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
#include <QGuiApplication>
2525
#include <QStringLiteral>
26+
#include <QUrl>
27+
#include <DTrashManager>
2628

2729
#include <appletbridge.h>
2830

@@ -269,6 +271,13 @@ void TaskManager::handleWindowAdded(QPointer<AbstractWindow> window)
269271

270272
void TaskManager::dropFilesOnItem(const QString& itemId, const QStringList& urls)
271273
{
274+
if (itemId == "dde-trash") {
275+
qCDebug(taskManagerLog) << "dropFilesOnItem: dde-trash - moving files to trash:" << urls;
276+
// 将文件移动到回收站
277+
moveFilesToTrash(urls);
278+
return;
279+
}
280+
272281
auto indexes = m_itemModel->match(m_itemModel->index(0, 0), TaskManager::ItemIdRole, itemId, 1, Qt::MatchExactly);
273282
if (indexes.isEmpty()) {
274283
return;
@@ -282,6 +291,20 @@ void TaskManager::dropFilesOnItem(const QString& itemId, const QStringList& urls
282291
m_itemModel->requestOpenUrls(indexes.first(), urlList);
283292
}
284293

294+
void TaskManager::moveFilesToTrash(const QStringList& urls)
295+
{
296+
// 将文件路径转换为本地路径并移动到回收站
297+
for (const QString& urlString : urls) {
298+
QUrl url(urlString);
299+
QString filePath = url.toLocalFile();
300+
if (DTrashManager::instance()->moveToTrash(filePath)) {
301+
qCDebug(taskManagerLog) << "Successfully moved to trash:" << filePath;
302+
} else {
303+
qCWarning(taskManagerLog) << "Failed to move to trash:" << filePath;
304+
}
305+
}
306+
}
307+
285308
void TaskManager::hideItemPreview()
286309
{
287310
m_windowMonitor->hideItemPreview();

panels/dock/taskmanager/taskmanager.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ class TaskManager : public DS_NAMESPACE::DContainment, public AbstractTaskManage
9797
Q_INVOKABLE void activateWindow(uint32_t windowID);
9898
Q_INVOKABLE void saveDockElementsOrder(const QStringList &appIds);
9999

100+
private:
101+
void moveFilesToTrash(const QStringList& urls);
102+
100103
Q_SIGNALS:
101104
void dataModelChanged();
102105
void windowSplitChanged();

0 commit comments

Comments
 (0)