summaryrefslogtreecommitdiff
path: root/components/filedialog
diff options
context:
space:
mode:
author2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-09-02 18:40:31 +1000
committer2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-09-02 18:40:31 +1000
commite70cb285acf53516b20c02ba167a801157576395 (patch)
tree17640552aa6cdf6ce4654ecbdd75a70570155599 /components/filedialog
parentplugin/fsm: add showHidden & dirs filter (diff)
downloadcaelestia-shell-e70cb285acf53516b20c02ba167a801157576395.tar.gz
caelestia-shell-e70cb285acf53516b20c02ba167a801157576395.tar.bz2
caelestia-shell-e70cb285acf53516b20c02ba167a801157576395.zip
internal: use FileSystemModel for FileDialog
Diffstat (limited to 'components/filedialog')
-rw-r--r--components/filedialog/CurrentItem.qml2
-rw-r--r--components/filedialog/DialogButtons.qml2
-rw-r--r--components/filedialog/FileDialog.qml4
-rw-r--r--components/filedialog/FolderContents.qml59
4 files changed, 23 insertions, 44 deletions
diff --git a/components/filedialog/CurrentItem.qml b/components/filedialog/CurrentItem.qml
index c06c91f..b051212 100644
--- a/components/filedialog/CurrentItem.qml
+++ b/components/filedialog/CurrentItem.qml
@@ -79,7 +79,7 @@ Item {
anchors.rightMargin: Appearance.padding.larger - Appearance.padding.small
anchors.bottomMargin: Appearance.padding.normal - Appearance.padding.small
- text: qsTr(`"%1" selected`).arg(root.currentItem?.fileName)
+ text: qsTr(`"%1" selected`).arg(root.currentItem?.modelData.name)
}
}
diff --git a/components/filedialog/DialogButtons.qml b/components/filedialog/DialogButtons.qml
index c5b11dc..bde9ac2 100644
--- a/components/filedialog/DialogButtons.qml
+++ b/components/filedialog/DialogButtons.qml
@@ -52,7 +52,7 @@ StyledRect {
disabled: !root.dialog.selectionValid
function onClicked(): void {
- root.dialog.accepted(root.folder.currentItem.filePath);
+ root.dialog.accepted(root.folder.currentItem.modelData.path);
}
}
diff --git a/components/filedialog/FileDialog.qml b/components/filedialog/FileDialog.qml
index 0deff32..ed6b193 100644
--- a/components/filedialog/FileDialog.qml
+++ b/components/filedialog/FileDialog.qml
@@ -36,8 +36,8 @@ LazyLoader {
property list<string> filters: loader.filters
readonly property bool selectionValid: {
- const item = folderContents.currentItem;
- return item && !item.fileIsDir && (filters.includes("*") || filters.includes(item.fileSuffix));
+ const file = folderContents.currentItem?.modelData;
+ return file && !file.isDir && (filters.includes("*") || filters.includes(file.suffix));
}
function accepted(path: string): void {
diff --git a/components/filedialog/FolderContents.qml b/components/filedialog/FolderContents.qml
index afd2ed1..1a20647 100644
--- a/components/filedialog/FolderContents.qml
+++ b/components/filedialog/FolderContents.qml
@@ -6,13 +6,12 @@ import "../images"
import qs.services
import qs.config
import qs.utils
+import Caelestia
import Quickshell
-import Quickshell.Io
import QtQuick
import QtQuick.Layouts
import QtQuick.Effects
import QtQuick.Controls
-import Qt.labs.folderlistmodel
Item {
id: root
@@ -86,37 +85,30 @@ Item {
Keys.onReturnPressed: {
if (root.dialog.selectionValid)
- root.dialog.accepted(currentItem.filePath);
+ root.dialog.accepted(currentItem.modelData.path);
}
Keys.onEnterPressed: {
if (root.dialog.selectionValid)
- root.dialog.accepted(currentItem.filePath);
+ root.dialog.accepted(currentItem.modelData.path);
}
ScrollBar.vertical: StyledScrollBar {}
- model: FolderListModel {
- showDirsFirst: true
- folder: {
- let url = "file://";
+ model: FileSystemModel {
+ path: {
if (root.dialog.cwd[0] === "Home")
- url += `${Paths.strip(Paths.home)}/${root.dialog.cwd.slice(1).join("/")}`;
+ return `${Paths.strip(Paths.home)}/${root.dialog.cwd.slice(1).join("/")}`;
else
- url += root.dialog.cwd.join("/");
- return url;
+ return root.dialog.cwd.join("/");
}
- onFolderChanged: view.currentIndex = -1
+ onPathChanged: view.currentIndex = -1
}
delegate: StyledRect {
id: item
required property int index
- required property string fileName
- required property string filePath
- required property url fileUrl
- required property string fileSuffix
- required property bool fileIsDir
+ required property FileSystemEntry modelData
readonly property real nonAnimHeight: icon.implicitHeight + name.anchors.topMargin + name.implicitHeight + Appearance.padding.normal * 2
@@ -130,10 +122,10 @@ Item {
StateLayer {
onDoubleClicked: {
- if (item.fileIsDir)
- root.dialog.cwd.push(item.fileName);
+ if (item.modelData.isDir)
+ root.dialog.cwd.push(item.modelData.name);
else if (root.dialog.selectionValid)
- root.dialog.accepted(item.filePath);
+ root.dialog.accepted(item.modelData.path);
}
function onClicked(): void {
@@ -150,31 +142,18 @@ Item {
implicitSize: Sizes.itemWidth - Appearance.padding.normal * 2
source: {
- if (!item.fileIsDir)
- return Quickshell.iconPath("application-x-zerosize");
+ if (item.modelData.isImage)
+ return Qt.resolvedUrl(item.modelData.path);
- const name = item.fileName;
+ if (!item.modelData.isDir)
+ return Quickshell.iconPath(item.modelData.mimeType.replace("/", "-"), "application-x-zerosize");
+
+ const name = item.modelData.name;
if (root.dialog.cwd.length === 1 && ["Desktop", "Documents", "Downloads", "Music", "Pictures", "Public", "Templates", "Videos"].includes(name))
return Quickshell.iconPath(`folder-${name.toLowerCase()}`);
return Quickshell.iconPath("inode-directory");
}
-
- onStatusChanged: {
- if (status === Image.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 = Images.validImageTypes.some(t => mime === `image-${t}`) ? item.fileUrl : Quickshell.iconPath(mime, "image-missing");
- }
- }
- }
}
StyledText {
@@ -187,7 +166,7 @@ Item {
anchors.margins: Appearance.padding.normal
horizontalAlignment: Text.AlignHCenter
- text: item.fileName
+ text: item.modelData.name
elide: item.GridView.isCurrentItem ? Text.ElideNone : Text.ElideRight
wrapMode: item.GridView.isCurrentItem ? Text.WrapAtWordBoundaryOrAnywhere : Text.NoWrap
}