filedialog: better mime detection
Required file Also show folders first
This commit is contained in:
parent
2c8f76ba09
commit
0f0471fa60
2 changed files with 16 additions and 22 deletions
|
|
@ -21,6 +21,7 @@
|
||||||
hyprland,
|
hyprland,
|
||||||
coreutils,
|
coreutils,
|
||||||
findutils,
|
findutils,
|
||||||
|
file,
|
||||||
material-symbols,
|
material-symbols,
|
||||||
gcc,
|
gcc,
|
||||||
quickshell,
|
quickshell,
|
||||||
|
|
@ -48,6 +49,7 @@
|
||||||
hyprland
|
hyprland
|
||||||
coreutils
|
coreutils
|
||||||
findutils
|
findutils
|
||||||
|
file
|
||||||
]
|
]
|
||||||
++ lib.optional withCli caelestia-cli;
|
++ lib.optional withCli caelestia-cli;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,13 +15,13 @@ GridView {
|
||||||
|
|
||||||
required property var dialog
|
required property var dialog
|
||||||
|
|
||||||
property var mimes: ({})
|
|
||||||
|
|
||||||
clip: true
|
clip: true
|
||||||
focus: true
|
focus: true
|
||||||
|
currentIndex: -1
|
||||||
Keys.onEscapePressed: root.currentIndex = -1
|
Keys.onEscapePressed: root.currentIndex = -1
|
||||||
|
|
||||||
model: FolderListModel {
|
model: FolderListModel {
|
||||||
|
showDirsFirst: true
|
||||||
folder: {
|
folder: {
|
||||||
let url = "file://";
|
let url = "file://";
|
||||||
if (root.dialog.cwd[0] === "Home")
|
if (root.dialog.cwd[0] === "Home")
|
||||||
|
|
@ -77,18 +77,22 @@ GridView {
|
||||||
|
|
||||||
asynchronous: true
|
asynchronous: true
|
||||||
implicitSize: Sizes.itemWidth - Appearance.padding.normal * 2
|
implicitSize: Sizes.itemWidth - Appearance.padding.normal * 2
|
||||||
source: {
|
source: Quickshell.iconPath(item.fileIsDir ? "inode-directory" : "application-x-zerosize")
|
||||||
const mime = root.mimes[item.fileSuffix];
|
|
||||||
|
|
||||||
if (mime?.startsWith("image-"))
|
|
||||||
return item.fileUrl;
|
|
||||||
|
|
||||||
return Quickshell.iconPath(item.fileIsDir ? "inode-directory" : root.mimes[item.fileSuffix] ?? "application-x-zerosize", "image-missing");
|
|
||||||
}
|
|
||||||
onStatusChanged: {
|
onStatusChanged: {
|
||||||
if (status === Image.Error)
|
if (status === Image.Error)
|
||||||
source = Quickshell.iconPath("error");
|
source = Quickshell.iconPath("error");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Process {
|
||||||
|
running: !item.fileIsDir
|
||||||
|
command: ["file", "--mime", "-b", item.filePath]
|
||||||
|
stdout: StdioCollector {
|
||||||
|
onStreamFinished: {
|
||||||
|
const mime = text.split(";")[0].replace("/", "-");
|
||||||
|
icon.source = mime.startsWith("image-") ? item.fileUrl : Quickshell.iconPath(mime, "image-missing");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
StyledText {
|
StyledText {
|
||||||
|
|
@ -115,16 +119,4 @@ GridView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FileView {
|
|
||||||
path: "/etc/mime.types"
|
|
||||||
onLoaded: {
|
|
||||||
root.mimes = text().split("\n").filter(l => !l.startsWith("#")).reduce((mimes, line) => {
|
|
||||||
const [type, ext] = line.split(/\s+/);
|
|
||||||
if (ext)
|
|
||||||
mimes[ext] = type.replace("/", "-");
|
|
||||||
return mimes;
|
|
||||||
}, {});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue