1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-04-30 09:32:05 -04:00

dock: add trash bin button (#2277)

* dock: add trash bin button

- icon reflects content- filled/empty
- multiple file manager support with nautilus as default, builtin as
fallback
- settingsspec at dock tab
- context menu

* fix: remove support for builtin filebrowser

needs specific adaptors at FB adhering the trash freedesktop spec

* fix: suppress auto-hide dock with trash context menu open

* feat: allow for custom file manager command

* feat: switch runner to proc.runcommand with toasts on command failures
This commit is contained in:
Kangheng Liu
2026-04-27 09:55:00 -04:00
committed by GitHub
parent e805f6b5ac
commit 536e654b5e
9 changed files with 763 additions and 5 deletions

View File

@@ -0,0 +1,92 @@
pragma Singleton
import QtQuick
import Qt.labs.folderlistmodel
import Quickshell
import Quickshell.Io
import qs.Common
Singleton {
id: root
readonly property string _homeDir: Quickshell.env("HOME") || ""
readonly property string _xdgDataHome: Quickshell.env("XDG_DATA_HOME") || (_homeDir + "/.local/share")
readonly property string trashFilesDir: _xdgDataHome + "/Trash/files"
readonly property int count: trashModel.count
readonly property bool isEmpty: count === 0
property var availableFileManagers: []
signal emptyTrashConfirmRequested(int itemCount)
FolderListModel {
id: trashModel
folder: "file://" + root.trashFilesDir
showDirs: true
showFiles: true
showHidden: true
showDotAndDotDot: false
sortField: FolderListModel.Name
nameFilters: ["*"]
}
Process {
id: detectProc
running: false
command: ["sh", "-c", "for fm in nautilus thunar dolphin; do command -v $fm >/dev/null 2>&1 && echo $fm; done"]
stdout: StdioCollector {
onStreamFinished: {
const detected = (text || "").split("\n").map(s => s.trim()).filter(s => s.length > 0);
detected.push("custom");
root.availableFileManagers = detected;
}
}
}
Component.onCompleted: {
detectProc.running = true;
}
function openTrash() {
const choice = SettingsData.dockTrashFileManager || "nautilus";
if (choice === "custom") {
const cmd = (SettingsData.dockTrashCustomCommand || "").trim();
if (!cmd) {
ToastService.showInfo(I18n.tr("Cannot open trash: no custom command set"), I18n.tr("Configure one in Settings → Dock → Trash."));
return;
}
Proc.runCommand(null, ["sh", "-c", cmd], (output, exitCode) => {
if (exitCode !== 0) {
ToastService.showError(I18n.tr("Trash command failed (exit %1)").arg(exitCode), I18n.tr("Check your custom command in Settings → Dock → Trash."));
}
}, 0, Proc.noTimeout);
return;
}
if (availableFileManagers.indexOf(choice) < 0) {
ToastService.showInfo(I18n.tr("Cannot open trash: '%1' is not installed").arg(choice), I18n.tr("Pick a different file manager in Settings → Dock → Trash."));
return;
}
switch (choice) {
case "nautilus":
Quickshell.execDetached(["nautilus", "trash:///"]);
break;
case "thunar":
Quickshell.execDetached(["thunar", "trash:///"]);
break;
case "dolphin":
Quickshell.execDetached(["dolphin", "trash:///"]);
break;
}
}
function requestEmptyTrash() {
if (isEmpty)
return;
emptyTrashConfirmRequested(count);
}
function emptyTrash() {
Quickshell.execDetached(["gio", "trash", "--empty"]);
}
}