filedialog: add filters and buttons
This commit is contained in:
parent
73cf10ea96
commit
75964fe608
4 changed files with 114 additions and 5 deletions
93
widgets/filedialog/DialogButtons.qml
Normal file
93
widgets/filedialog/DialogButtons.qml
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
import ".."
|
||||
import qs.services
|
||||
import qs.config
|
||||
import QtQuick.Layouts
|
||||
|
||||
StyledRect {
|
||||
id: root
|
||||
|
||||
required property var dialog
|
||||
required property FolderContents folder
|
||||
|
||||
implicitHeight: inner.implicitHeight + Appearance.padding.normal * 2
|
||||
|
||||
color: Colours.palette.m3surfaceContainer
|
||||
|
||||
RowLayout {
|
||||
id: inner
|
||||
|
||||
anchors.fill: parent
|
||||
anchors.margins: Appearance.padding.normal
|
||||
|
||||
spacing: Appearance.spacing.small
|
||||
|
||||
StyledText {
|
||||
text: qsTr("Filter:")
|
||||
}
|
||||
|
||||
StyledRect {
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
Layout.rightMargin: Appearance.spacing.normal
|
||||
|
||||
color: Colours.palette.m3surfaceContainerHigh
|
||||
radius: Appearance.rounding.small
|
||||
|
||||
StyledText {
|
||||
anchors.fill: parent
|
||||
anchors.margins: Appearance.padding.normal
|
||||
|
||||
text: `${root.dialog.filterLabel} (${root.dialog.filters})`
|
||||
}
|
||||
}
|
||||
|
||||
StyledRect {
|
||||
color: Colours.palette.m3surfaceContainerHigh
|
||||
radius: Appearance.rounding.small
|
||||
|
||||
implicitWidth: cancelText.implicitWidth + Appearance.padding.normal * 2
|
||||
implicitHeight: cancelText.implicitHeight + Appearance.padding.normal * 2
|
||||
|
||||
StateLayer {
|
||||
disabled: !root.dialog.selectionValid
|
||||
|
||||
function onClicked(): void {
|
||||
root.dialog.accepted(root.folder.currentItem.filePath);
|
||||
}
|
||||
}
|
||||
|
||||
StyledText {
|
||||
id: selectText
|
||||
|
||||
anchors.centerIn: parent
|
||||
anchors.margins: Appearance.padding.normal
|
||||
|
||||
text: qsTr("Select")
|
||||
color: root.dialog.selectionValid ? Colours.palette.m3onSurface : Colours.palette.m3outline
|
||||
}
|
||||
}
|
||||
|
||||
StyledRect {
|
||||
color: Colours.palette.m3surfaceContainerHigh
|
||||
radius: Appearance.rounding.small
|
||||
|
||||
implicitWidth: cancelText.implicitWidth + Appearance.padding.normal * 2
|
||||
implicitHeight: cancelText.implicitHeight + Appearance.padding.normal * 2
|
||||
|
||||
StateLayer {
|
||||
function onClicked(): void {
|
||||
root.dialog.rejected();
|
||||
}
|
||||
}
|
||||
|
||||
StyledText {
|
||||
id: cancelText
|
||||
|
||||
anchors.centerIn: parent
|
||||
anchors.margins: Appearance.padding.normal
|
||||
|
||||
text: qsTr("Cancel")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -8,14 +8,23 @@ FloatingWindow {
|
|||
id: root
|
||||
|
||||
property list<string> cwd: ["Home"]
|
||||
property string filterLabel: "All files"
|
||||
property list<string> filters: ["*"]
|
||||
|
||||
readonly property bool selectionValid: {
|
||||
const item = folderContents.currentItem;
|
||||
return item && !item.fileIsDir && (filters.includes("*") || filters.includes(item.fileSuffix));
|
||||
}
|
||||
|
||||
signal accepted(path: string)
|
||||
signal rejected
|
||||
|
||||
implicitWidth: 1000
|
||||
implicitHeight: 600
|
||||
color: Colours.palette.m3surface
|
||||
|
||||
onAccepted: visible = false
|
||||
onRejected: visible = false
|
||||
|
||||
RowLayout {
|
||||
anchors.fill: parent
|
||||
|
|
@ -39,10 +48,18 @@ FloatingWindow {
|
|||
}
|
||||
|
||||
FolderContents {
|
||||
id: folderContents
|
||||
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
dialog: root
|
||||
}
|
||||
|
||||
DialogButtons {
|
||||
Layout.fillWidth: true
|
||||
dialog: root
|
||||
folder: folderContents
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ Item {
|
|||
id: root
|
||||
|
||||
required property var dialog
|
||||
property alias currentItem: view.currentItem
|
||||
|
||||
StyledRect {
|
||||
anchors.fill: parent
|
||||
|
|
@ -82,11 +83,11 @@ Item {
|
|||
Keys.onEscapePressed: currentIndex = -1
|
||||
|
||||
Keys.onReturnPressed: {
|
||||
if (currentItem)
|
||||
if (root.dialog.selectionValid)
|
||||
root.dialog.accepted(currentItem.filePath);
|
||||
}
|
||||
Keys.onEnterPressed: {
|
||||
if (currentItem)
|
||||
if (root.dialog.selectionValid)
|
||||
root.dialog.accepted(currentItem.filePath);
|
||||
}
|
||||
|
||||
|
|
@ -127,7 +128,7 @@ Item {
|
|||
onDoubleClicked: {
|
||||
if (item.fileIsDir)
|
||||
root.dialog.cwd.push(item.fileName);
|
||||
else
|
||||
else if (root.dialog.selectionValid)
|
||||
root.dialog.accepted(item.filePath);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@ pragma ComponentBehavior: Bound
|
|||
import ".."
|
||||
import qs.services
|
||||
import qs.config
|
||||
import Quickshell
|
||||
import Quickshell.Widgets
|
||||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue