Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions panels/dock/taskmanager/package/AppItem.qml
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,17 @@ Item {
Loader {
id: contextMenuLoader
active: false
property bool trashEmpty: true
sourceComponent: LP.Menu {
id: contextMenu
Instantiator {
id: menuItemInstantiator
model: JSON.parse(menus)
delegate: LP.MenuItem {
text: modelData.name
enabled: (root.itemId === "dde-trash" && modelData.id === "clean-trash")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

当数据为空的时候,能不能不要“清空”这一菜单项?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

单子上面说是要设置为灰色,不能点击,

? !contextMenuLoader.trashEmpty
: true
onTriggered: {
TaskManager.requestNewInstance(root.modelIndex, modelData.id);
}
Expand Down Expand Up @@ -319,6 +323,7 @@ Item {
onClicked: function (mouse) {
let index = root.modelIndex;
if (mouse.button === Qt.RightButton) {
contextMenuLoader.trashEmpty = TaskManager.isTrashEmpty()
contextMenuLoader.active = true
MenuHelper.openMenu(contextMenuLoader.item)
} else {
Expand Down
33 changes: 24 additions & 9 deletions panels/dock/taskmanager/taskmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <QStringLiteral>
#include <QUrl>
#include <QStandardPaths>
#include <QProcess>

#include <appletbridge.h>
#include <DSGApplication>
Expand Down Expand Up @@ -436,16 +437,30 @@ void TaskManager::saveDockElementsOrder(const QStringList &appIds)

QString TaskManager::getTrashTipText()
{
int fileCount = 0;
QString trashPath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/Trash/files";
QDir trashDir(trashPath);
if (trashDir.exists()) {
QStringList entries = trashDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
fileCount = entries.size();
}
const auto count = queryTrashCount();
return tr("%1 files").arg(count);
}

bool TaskManager::isTrashEmpty() const
{
return queryTrashCount() == 0;
}

return tr("%1 files").arg(fileCount);
int TaskManager::queryTrashCount() const
{
int count = 0;

QProcess gio;
gio.start("gio", QStringList() << "trash" << "--list");
if (gio.waitForFinished(1000) && gio.exitStatus() == QProcess::NormalExit && gio.exitCode() == 0) {
const QByteArray &out = gio.readAllStandardOutput();
const QList<QByteArray> lines = out.split('\n');
for (const QByteArray &l : lines) {
if (!l.trimmed().isEmpty()) count++;
}
return count;
}
return count;
}

void TaskManager::modifyOpacityChanged()
Expand Down
2 changes: 2 additions & 0 deletions panels/dock/taskmanager/taskmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class TaskManager : public DS_NAMESPACE::DContainment, public AbstractTaskManage
Q_INVOKABLE void saveDockElementsOrder(const QStringList &appIds);
Q_INVOKABLE QString getTrashTipText();

Q_INVOKABLE bool isTrashEmpty() const;
Q_SIGNALS:
void dataModelChanged();
void windowSplitChanged();
Expand All @@ -114,6 +115,7 @@ private Q_SLOTS:
DockGlobalElementModel *m_dockGlobalElementModel = nullptr;
DockItemModel *m_itemModel = nullptr;
HoverPreviewProxyModel *m_hoverPreviewModel = nullptr;
int queryTrashCount() const;
};

}
Expand Down