filedialog: navigation
This commit is contained in:
parent
7c991dee0a
commit
2c8f76ba09
3 changed files with 25 additions and 16 deletions
|
|
@ -6,7 +6,9 @@ import QtQuick.Layouts
|
||||||
FloatingWindow {
|
FloatingWindow {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
property list<string> cwd: ["Home", "Downloads"]
|
property list<string> cwd: ["Home"]
|
||||||
|
|
||||||
|
signal accepted(path: string)
|
||||||
|
|
||||||
implicitWidth: 1000
|
implicitWidth: 1000
|
||||||
implicitHeight: 600
|
implicitHeight: 600
|
||||||
|
|
@ -26,14 +28,13 @@ FloatingWindow {
|
||||||
|
|
||||||
HeaderBar {
|
HeaderBar {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
cwd: root.cwd
|
dialog: root
|
||||||
}
|
}
|
||||||
|
|
||||||
FolderContents {
|
FolderContents {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.fillHeight: true
|
Layout.fillHeight: true
|
||||||
|
dialog: root
|
||||||
cwd: root.cwd
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ import Qt.labs.folderlistmodel
|
||||||
GridView {
|
GridView {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
required property list<string> cwd
|
required property var dialog
|
||||||
|
|
||||||
property var mimes: ({})
|
property var mimes: ({})
|
||||||
|
|
||||||
|
|
@ -24,12 +24,13 @@ GridView {
|
||||||
model: FolderListModel {
|
model: FolderListModel {
|
||||||
folder: {
|
folder: {
|
||||||
let url = "file://";
|
let url = "file://";
|
||||||
if (root.cwd[0] === "Home")
|
if (root.dialog.cwd[0] === "Home")
|
||||||
url += `${Paths.strip(Paths.home)}/${root.cwd.slice(1).join("/")}`;
|
url += `${Paths.strip(Paths.home)}/${root.dialog.cwd.slice(1).join("/")}`;
|
||||||
else
|
else
|
||||||
url += root.cwd.join("/");
|
url += root.dialog.cwd.join("/");
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
onFolderChanged: root.currentIndex = -1
|
||||||
}
|
}
|
||||||
|
|
||||||
delegate: StyledRect {
|
delegate: StyledRect {
|
||||||
|
|
@ -37,6 +38,7 @@ GridView {
|
||||||
|
|
||||||
required property int index
|
required property int index
|
||||||
required property string fileName
|
required property string fileName
|
||||||
|
required property string filePath
|
||||||
required property url fileUrl
|
required property url fileUrl
|
||||||
required property string fileSuffix
|
required property string fileSuffix
|
||||||
required property bool fileIsDir
|
required property bool fileIsDir
|
||||||
|
|
@ -53,7 +55,13 @@ GridView {
|
||||||
|
|
||||||
StateLayer {
|
StateLayer {
|
||||||
color: root.currentItem === item ? Colours.palette.m3onPrimary : Colours.palette.m3onSurface
|
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 {
|
function onClicked(): void {
|
||||||
root.currentIndex = item.index;
|
root.currentIndex = item.index;
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import QtQuick.Layouts
|
||||||
RowLayout {
|
RowLayout {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
required property list<string> cwd
|
required property var dialog
|
||||||
|
|
||||||
spacing: Appearance.spacing.small
|
spacing: Appearance.spacing.small
|
||||||
|
|
||||||
|
|
@ -21,7 +21,7 @@ RowLayout {
|
||||||
radius: Appearance.rounding.small
|
radius: Appearance.rounding.small
|
||||||
|
|
||||||
function onClicked(): void {
|
function onClicked(): void {
|
||||||
root.cwd.pop();
|
root.dialog.cwd.pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -51,7 +51,7 @@ RowLayout {
|
||||||
spacing: Appearance.spacing.small
|
spacing: Appearance.spacing.small
|
||||||
|
|
||||||
Repeater {
|
Repeater {
|
||||||
model: root.cwd
|
model: root.dialog.cwd
|
||||||
|
|
||||||
RowLayout {
|
RowLayout {
|
||||||
id: folder
|
id: folder
|
||||||
|
|
@ -78,13 +78,13 @@ RowLayout {
|
||||||
|
|
||||||
Loader {
|
Loader {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
active: folder.index < root.cwd.length - 1
|
active: folder.index < root.dialog.cwd.length - 1
|
||||||
asynchronous: true
|
asynchronous: true
|
||||||
sourceComponent: StateLayer {
|
sourceComponent: StateLayer {
|
||||||
radius: Appearance.rounding.small
|
radius: Appearance.rounding.small
|
||||||
|
|
||||||
function onClicked(): void {
|
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
|
asynchronous: true
|
||||||
sourceComponent: MaterialIcon {
|
sourceComponent: MaterialIcon {
|
||||||
text: "home"
|
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
|
fill: 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -113,7 +113,7 @@ RowLayout {
|
||||||
anchors.leftMargin: homeIcon.active ? Appearance.padding.small : 0
|
anchors.leftMargin: homeIcon.active ? Appearance.padding.small : 0
|
||||||
|
|
||||||
text: folder.modelData
|
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
|
font.bold: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue