filedialog: navigation

This commit is contained in:
2 * r + 2 * t 2025-07-19 23:04:32 +10:00
parent 7c991dee0a
commit 2c8f76ba09
3 changed files with 25 additions and 16 deletions

View file

@ -6,7 +6,9 @@ import QtQuick.Layouts
FloatingWindow {
id: root
property list<string> cwd: ["Home", "Downloads"]
property list<string> cwd: ["Home"]
signal accepted(path: string)
implicitWidth: 1000
implicitHeight: 600
@ -26,14 +28,13 @@ FloatingWindow {
HeaderBar {
Layout.fillWidth: true
cwd: root.cwd
dialog: root
}
FolderContents {
Layout.fillWidth: true
Layout.fillHeight: true
cwd: root.cwd
dialog: root
}
}
}

View file

@ -13,7 +13,7 @@ import Qt.labs.folderlistmodel
GridView {
id: root
required property list<string> cwd
required property var dialog
property var mimes: ({})
@ -24,12 +24,13 @@ GridView {
model: FolderListModel {
folder: {
let url = "file://";
if (root.cwd[0] === "Home")
url += `${Paths.strip(Paths.home)}/${root.cwd.slice(1).join("/")}`;
if (root.dialog.cwd[0] === "Home")
url += `${Paths.strip(Paths.home)}/${root.dialog.cwd.slice(1).join("/")}`;
else
url += root.cwd.join("/");
url += root.dialog.cwd.join("/");
return url;
}
onFolderChanged: root.currentIndex = -1
}
delegate: StyledRect {
@ -37,6 +38,7 @@ GridView {
required property int index
required property string fileName
required property string filePath
required property url fileUrl
required property string fileSuffix
required property bool fileIsDir
@ -53,7 +55,13 @@ GridView {
StateLayer {
color: root.currentItem === item ? Colours.palette.m3onPrimary : Colours.palette.m3onSurface
onDoubleClicked: console.log("double clicked", item)
onDoubleClicked: {
if (item.fileIsDir)
root.dialog.cwd.push(item.fileName);
else
root.dialog.accepted(item.filePath);
}
function onClicked(): void {
root.currentIndex = item.index;

View file

@ -9,7 +9,7 @@ import QtQuick.Layouts
RowLayout {
id: root
required property list<string> cwd
required property var dialog
spacing: Appearance.spacing.small
@ -21,7 +21,7 @@ RowLayout {
radius: Appearance.rounding.small
function onClicked(): void {
root.cwd.pop();
root.dialog.cwd.pop();
}
}
@ -51,7 +51,7 @@ RowLayout {
spacing: Appearance.spacing.small
Repeater {
model: root.cwd
model: root.dialog.cwd
RowLayout {
id: folder
@ -78,13 +78,13 @@ RowLayout {
Loader {
anchors.fill: parent
active: folder.index < root.cwd.length - 1
active: folder.index < root.dialog.cwd.length - 1
asynchronous: true
sourceComponent: StateLayer {
radius: Appearance.rounding.small
function onClicked(): void {
root.cwd = root.cwd.slice(0, folder.index);
root.dialog.cwd = root.dialog.cwd.slice(0, folder.index + 1);
}
}
}
@ -100,7 +100,7 @@ RowLayout {
asynchronous: true
sourceComponent: MaterialIcon {
text: "home"
color: root.cwd.length === 1 ? Colours.palette.m3onSurface : Colours.palette.m3onSurfaceVariant
color: root.dialog.cwd.length === 1 ? Colours.palette.m3onSurface : Colours.palette.m3onSurfaceVariant
fill: 1
}
}
@ -113,7 +113,7 @@ RowLayout {
anchors.leftMargin: homeIcon.active ? Appearance.padding.small : 0
text: folder.modelData
color: folder.index < root.cwd.length - 1 ? Colours.palette.m3onSurfaceVariant : Colours.palette.m3onSurface
color: folder.index < root.dialog.cwd.length - 1 ? Colours.palette.m3onSurfaceVariant : Colours.palette.m3onSurface
font.bold: true
}
}