summaryrefslogtreecommitdiff
path: root/raveos-hyprland-theme/theme-data/DankMaterialShell/quickshell/Modals/FileBrowser/FileBrowserModal.qml
blob: c7686ca7d86d959604d31cf900a5039418a9d9cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import QtQuick
import Quickshell
import qs.Common
import qs.Widgets

FloatingWindow {
    id: fileBrowserModal

    property bool disablePopupTransparency: true
    property string browserTitle: "Select File"
    property string browserIcon: "folder_open"
    property string browserType: "generic"
    property var fileExtensions: ["*.*"]
    property alias filterExtensions: fileBrowserModal.fileExtensions
    property bool showHiddenFiles: false
    property bool saveMode: false
    property string defaultFileName: ""
    property var parentModal: null
    property bool shouldHaveFocus: visible
    property bool allowFocusOverride: false
    property bool shouldBeVisible: visible
    property bool allowStacking: true

    signal fileSelected(string path)
    signal dialogClosed

    function open() {
        visible = true;
    }

    function close() {
        visible = false;
    }

    objectName: "fileBrowserModal"
    title: "Files - " + browserTitle
    minimumSize: Qt.size(500, 400)
    implicitWidth: 800
    implicitHeight: 600
    color: Theme.surfaceContainer
    visible: false

    onVisibleChanged: {
        if (visible) {
            if (parentModal && "shouldHaveFocus" in parentModal) {
                parentModal.shouldHaveFocus = false;
                parentModal.allowFocusOverride = true;
            }
            Qt.callLater(() => {
                if (content) {
                    content.reset();
                    content.forceActiveFocus();
                }
            });
        } else {
            if (parentModal && "allowFocusOverride" in parentModal) {
                parentModal.allowFocusOverride = false;
                parentModal.shouldHaveFocus = Qt.binding(() => parentModal.shouldBeVisible);
            }
            dialogClosed();
        }
    }

    Loader {
        id: contentLoader
        anchors.fill: parent
        active: fileBrowserModal.visible
        sourceComponent: FileBrowserContent {
            id: content
            anchors.fill: parent
            focus: true
            closeOnEscape: false
            windowControls: fileBrowserModal.windowControlsRef

            browserTitle: fileBrowserModal.browserTitle
            browserIcon: fileBrowserModal.browserIcon
            browserType: fileBrowserModal.browserType
            fileExtensions: fileBrowserModal.fileExtensions
            showHiddenFiles: fileBrowserModal.showHiddenFiles
            saveMode: fileBrowserModal.saveMode
            defaultFileName: fileBrowserModal.defaultFileName

            Component.onCompleted: initialize()

            onFileSelected: path => fileBrowserModal.fileSelected(path)
            onCloseRequested: fileBrowserModal.close()
        }
    }

    property alias content: contentLoader.item
    property alias windowControlsRef: windowControls

    FloatingWindowControls {
        id: windowControls
        targetWindow: fileBrowserModal
    }
}