summaryrefslogtreecommitdiff
path: root/raveos-hyprland-theme/theme-data/dms/Modals/FileBrowser/FileBrowserContent.qml
blob: 8b96742da98ad46cdfeb61a33420f37d319ce7ef (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
import Qt.labs.folderlistmodel
import QtCore
import QtQuick
import QtQuick.Controls
import qs.Common
import qs.Widgets

FocusScope {
    id: root

    LayoutMirroring.enabled: I18n.isRtl
    LayoutMirroring.childrenInherit: true

    property string homeDir: StandardPaths.writableLocation(StandardPaths.HomeLocation)
    property string docsDir: StandardPaths.writableLocation(StandardPaths.DocumentsLocation)
    property string musicDir: StandardPaths.writableLocation(StandardPaths.MusicLocation)
    property string videosDir: StandardPaths.writableLocation(StandardPaths.MoviesLocation)
    property string picsDir: StandardPaths.writableLocation(StandardPaths.PicturesLocation)
    property string downloadDir: StandardPaths.writableLocation(StandardPaths.DownloadLocation)
    property string desktopDir: StandardPaths.writableLocation(StandardPaths.DesktopLocation)
    property string currentPath: ""
    property var fileExtensions: ["*.*"]
    property alias filterExtensions: root.fileExtensions
    property string browserTitle: "Select File"
    property string browserIcon: "folder_open"
    property string browserType: "generic"
    property bool showHiddenFiles: false
    property int selectedIndex: -1
    property bool keyboardNavigationActive: false
    property bool backButtonFocused: false
    property bool saveMode: false
    property string defaultFileName: ""
    property int keyboardSelectionIndex: -1
    property bool keyboardSelectionRequested: false
    property bool showKeyboardHints: false
    property bool showFileInfo: false
    property string selectedFilePath: ""
    property string selectedFileName: ""
    property bool selectedFileIsDir: false
    property bool showOverwriteConfirmation: false
    property string pendingFilePath: ""
    property bool showSidebar: true
    property string viewMode: "grid"
    property string sortBy: "name"
    property bool sortAscending: true
    property int iconSizeIndex: 1
    property var iconSizes: [80, 120, 160, 200]
    property bool pathEditMode: false
    property bool pathInputHasFocus: false
    property int actualGridColumns: 5
    property bool _initialized: false
    property bool closeOnEscape: true
    property var windowControls: null

    signal fileSelected(string path)
    signal closeRequested

    function encodeFileUrl(path) {
        if (!path)
            return "";
        return "file://" + path.split('/').map(s => encodeURIComponent(s)).join('/');
    }

    function initialize() {
        loadSettings();
        currentPath = getLastPath();
        _initialized = true;
    }

    function reset() {
        currentPath = getLastPath();
        selectedIndex = -1;
        keyboardNavigationActive = false;
        backButtonFocused = false;
    }

    function loadSettings() {
        const type = browserType || "default";
        const settings = CacheData.fileBrowserSettings[type];
        const isImageBrowser = ["wallpaper", "profile"].includes(browserType);

        if (settings) {
            viewMode = settings.viewMode || (isImageBrowser ? "grid" : "list");
            sortBy = settings.sortBy || "name";
            sortAscending = settings.sortAscending !== undefined ? settings.sortAscending : true;
            iconSizeIndex = settings.iconSizeIndex !== undefined ? settings.iconSizeIndex : 1;
            showSidebar = settings.showSidebar !== undefined ? settings.showSidebar : true;
        } else {
            viewMode = isImageBrowser ? "grid" : "list";
        }
    }

    function saveSettings() {
        if (!_initialized)
            return;
        const type = browserType || "default";
        let settings = CacheData.fileBrowserSettings;
        if (!settings[type]) {
            settings[type] = {};
        }
        settings[type].viewMode = viewMode;
        settings[type].sortBy = sortBy;
        settings[type].sortAscending = sortAscending;
        settings[type].iconSizeIndex = iconSizeIndex;
        settings[type].showSidebar = showSidebar;
        settings[type].lastPath = currentPath;
        CacheData.fileBrowserSettings = settings;

        if (browserType === "wallpaper") {
            CacheData.wallpaperLastPath = currentPath;
        } else if (browserType === "profile") {
            CacheData.profileLastPath = currentPath;
        }

        CacheData.saveCache();
    }

    onViewModeChanged: saveSettings()
    onSortByChanged: saveSettings()
    onSortAscendingChanged: saveSettings()
    onIconSizeIndexChanged: saveSettings()
    onShowSidebarChanged: saveSettings()

    function isImageFile(fileName) {
        if (!fileName)
            return false;
        const ext = fileName.toLowerCase().split('.').pop();
        return ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp', 'svg'].includes(ext);
    }

    function getLastPath() {
        const type = browserType || "default";
        const settings = CacheData.fileBrowserSettings[type];
        const lastPath = settings?.lastPath || "";
        return (lastPath && lastPath !== "") ? lastPath : homeDir;
    }

    function saveLastPath(path) {
        const type = browserType || "default";
        let settings = CacheData.fileBrowserSettings;
        if (!settings[type]) {
            settings[type] = {};
        }
        settings[type].lastPath = path;
        CacheData.fileBrowserSettings = settings;
        CacheData.saveCache();

        if (browserType === "wallpaper") {
            CacheData.wallpaperLastPath = path;
        } else if (browserType === "profile") {
            CacheData.profileLastPath = path;
        }
    }

    function setSelectedFileData(path, name, isDir) {
        selectedFilePath = path;
        selectedFileName = name;
        selectedFileIsDir = isDir;
    }

    function navigateUp() {
        const path = currentPath;
        if (path === homeDir)
            return;
        const lastSlash = path.lastIndexOf('/');
        if (lastSlash <= 0)
            return;
        const newPath = path.substring(0, lastSlash);
        if (newPath.length < homeDir.length) {
            currentPath = homeDir;
            saveLastPath(homeDir);
        } else {
            currentPath = newPath;
            saveLastPath(newPath);
        }
    }

    function navigateTo(path) {
        currentPath = path;
        saveLastPath(path);
        selectedIndex = -1;
        backButtonFocused = false;
    }

    function keyboardFileSelection(index) {
        if (index < 0)
            return;
        keyboardSelectionTimer.targetIndex = index;
        keyboardSelectionTimer.start();
    }

    function executeKeyboardSelection(index) {
        keyboardSelectionIndex = index;
        keyboardSelectionRequested = true;
    }

    function handleSaveFile(filePath) {
        var normalizedPath = filePath;
        if (!normalizedPath.startsWith("file://")) {
            normalizedPath = encodeFileUrl(filePath);
        }

        var exists = false;
        var fileName = filePath.split('/').pop();

        for (var i = 0; i < folderModel.count; i++) {
            if (folderModel.get(i, "fileName") === fileName && !folderModel.get(i, "fileIsDir")) {
                exists = true;
                break;
            }
        }

        if (exists) {
            pendingFilePath = normalizedPath;
            showOverwriteConfirmation = true;
        } else {
            fileSelected(normalizedPath);
            closeRequested();
        }
    }

    onCurrentPathChanged: {
        selectedFilePath = "";
        selectedFileName = "";
        selectedFileIsDir = false;
        saveSettings();
    }

    onSelectedIndexChanged: {
        if (selectedIndex >= 0 && folderModel && selectedIndex < folderModel.count) {
            selectedFilePath = "";
            selectedFileName = "";
            selectedFileIsDir = false;
        }
    }

    property var steamPaths: [StandardPaths.writableLocation(StandardPaths.HomeLocation) + "/.steam/steam/steamapps/workshop/content/431960", StandardPaths.writableLocation(StandardPaths.HomeLocation) + "/.local/share/Steam/steamapps/workshop/content/431960", StandardPaths.writableLocation(StandardPaths.HomeLocation) + "/.var/app/com.valvesoftware.Steam/.local/share/Steam/steamapps/workshop/content/431960", StandardPaths.writableLocation(StandardPaths.HomeLocation) + "/snap/steam/common/.local/share/Steam/steamapps/workshop/content/431960"]

    property var quickAccessLocations: [
        {
            "name": I18n.tr("Home"),
            "path": homeDir,
            "icon": "home"
        },
        {
            "name": I18n.tr("Documents"),
            "path": docsDir,
            "icon": "description"
        },
        {
            "name": I18n.tr("Downloads"),
            "path": downloadDir,
            "icon": "download"
        },
        {
            "name": I18n.tr("Pictures"),
            "path": picsDir,
            "icon": "image"
        },
        {
            "name": I18n.tr("Music"),
            "path": musicDir,
            "icon": "music_note"
        },
        {
            "name": I18n.tr("Videos"),
            "path": videosDir,
            "icon": "movie"
        },
        {
            "name": I18n.tr("Desktop"),
            "path": desktopDir,
            "icon": "computer"
        }
    ]

    FolderListModel {
        id: folderModel

        showDirsFirst: true
        showDotAndDotDot: false
        showHidden: root.showHiddenFiles
        caseSensitive: false
        nameFilters: fileExtensions
        showFiles: true
        showDirs: true
        folder: encodeFileUrl(currentPath || homeDir)
        sortField: {
            switch (sortBy) {
            case "name":
                return FolderListModel.Name;
            case "size":
                return FolderListModel.Size;
            case "modified":
                return FolderListModel.Time;
            case "type":
                return FolderListModel.Type;
            default:
                return FolderListModel.Name;
            }
        }
        sortReversed: !sortAscending
    }

    QtObject {
        id: keyboardController

        property int totalItems: folderModel.count
        property int gridColumns: viewMode === "list" ? 1 : Math.max(1, actualGridColumns)

        function handleKey(event) {
            if (event.key === Qt.Key_Escape && root.closeOnEscape) {
                closeRequested();
                event.accepted = true;
                return;
            }
            if (event.key === Qt.Key_F10) {
                showKeyboardHints = !showKeyboardHints;
                event.accepted = true;
                return;
            }
            if (event.key === Qt.Key_F1 || event.key === Qt.Key_I) {
                showFileInfo = !showFileInfo;
                event.accepted = true;
                return;
            }
            if ((event.modifiers & Qt.AltModifier && event.key === Qt.Key_Left) || event.key === Qt.Key_Backspace) {
                if (currentPath !== homeDir) {
                    navigateUp();
                    event.accepted = true;
                }
                return;
            }
            if (!keyboardNavigationActive) {
                const isInitKey = event.key === Qt.Key_Tab || event.key === Qt.Key_Down || event.key === Qt.Key_Right || (event.key === Qt.Key_N && event.modifiers & Qt.ControlModifier) || (event.key === Qt.Key_J && event.modifiers & Qt.ControlModifier) || (event.key === Qt.Key_L && event.modifiers & Qt.ControlModifier);

                if (isInitKey) {
                    keyboardNavigationActive = true;
                    if (currentPath !== homeDir) {
                        backButtonFocused = true;
                        selectedIndex = -1;
                    } else {
                        backButtonFocused = false;
                        selectedIndex = 0;
                    }
                    event.accepted = true;
                }
                return;
            }
            switch (event.key) {
            case Qt.Key_Tab:
                if (backButtonFocused) {
                    backButtonFocused = false;
                    selectedIndex = 0;
                } else if (selectedIndex < totalItems - 1) {
                    selectedIndex++;
                } else if (currentPath !== homeDir) {
                    backButtonFocused = true;
                    selectedIndex = -1;
                } else {
                    selectedIndex = 0;
                }
                event.accepted = true;
                break;
            case Qt.Key_Backtab:
                if (backButtonFocused) {
                    backButtonFocused = false;
                    selectedIndex = totalItems - 1;
                } else if (selectedIndex > 0) {
                    selectedIndex--;
                } else if (currentPath !== homeDir) {
                    backButtonFocused = true;
                    selectedIndex = -1;
                } else {
                    selectedIndex = totalItems - 1;
                }
                event.accepted = true;
                break;
            case Qt.Key_N:
                if (event.modifiers & Qt.ControlModifier) {
                    if (backButtonFocused) {
                        backButtonFocused = false;
                        selectedIndex = 0;
                    } else if (selectedIndex < totalItems - 1) {
                        selectedIndex++;
                    }
                    event.accepted = true;
                }
                break;
            case Qt.Key_P:
                if (event.modifiers & Qt.ControlModifier) {
                    if (selectedIndex > 0) {
                        selectedIndex--;
                    } else if (currentPath !== homeDir) {
                        backButtonFocused = true;
                        selectedIndex = -1;
                    }
                    event.accepted = true;
                }
                break;
            case Qt.Key_J:
                if (event.modifiers & Qt.ControlModifier) {
                    if (selectedIndex < totalItems - 1) {
                        selectedIndex++;
                    }
                    event.accepted = true;
                }
                break;
            case Qt.Key_K:
                if (event.modifiers & Qt.ControlModifier) {
                    if (selectedIndex > 0) {
                        selectedIndex--;
                    } else if (currentPath !== homeDir) {
                        backButtonFocused = true;
                        selectedIndex = -1;
                    }
                    event.accepted = true;
                }
                break;
            case Qt.Key_H:
                if (event.modifiers & Qt.ControlModifier) {
                    if (!backButtonFocused && selectedIndex > 0) {
                        selectedIndex--;
                    } else if (currentPath !== homeDir) {
                        backButtonFocused = true;
                        selectedIndex = -1;
                    }
                    event.accepted = true;
                }
                break;
            case Qt.Key_L:
                if (event.modifiers & Qt.ControlModifier) {
                    if (backButtonFocused) {
                        backButtonFocused = false;
                        selectedIndex = 0;
                    } else if (selectedIndex < totalItems - 1) {
                        selectedIndex++;
                    }
                    event.accepted = true;
                }
                break;
            case Qt.Key_Left:
                if (pathInputHasFocus)
                    return;
                if (backButtonFocused)
                    return;
                if (selectedIndex > 0) {
                    selectedIndex--;
                } else if (currentPath !== homeDir) {
                    backButtonFocused = true;
                    selectedIndex = -1;
                }
                event.accepted = true;
                break;
            case Qt.Key_Right:
                if (pathInputHasFocus)
                    return;
                if (backButtonFocused) {
                    backButtonFocused = false;
                    selectedIndex = 0;
                } else if (selectedIndex < totalItems - 1) {
                    selectedIndex++;
                }
                event.accepted = true;
                break;
            case Qt.Key_Up:
                if (backButtonFocused) {
                    backButtonFocused = false;
                    if (gridColumns === 1) {
                        selectedIndex = 0;
                    } else {
                        var col = selectedIndex % gridColumns;
                        selectedIndex = Math.min(col, totalItems - 1);
                    }
                } else if (selectedIndex >= gridColumns) {
                    selectedIndex -= gridColumns;
                } else if (selectedIndex > 0 && gridColumns === 1) {
                    selectedIndex--;
                } else if (currentPath !== homeDir) {
                    backButtonFocused = true;
                    selectedIndex = -1;
                }
                event.accepted = true;
                break;
            case Qt.Key_Down:
                if (backButtonFocused) {
                    backButtonFocused = false;
                    selectedIndex = 0;
                } else if (gridColumns === 1) {
                    if (selectedIndex < totalItems - 1) {
                        selectedIndex++;
                    }
                } else {
                    var newIndex = selectedIndex + gridColumns;
                    if (newIndex < totalItems) {
                        selectedIndex = newIndex;
                    } else {
                        var lastRowStart = Math.floor((totalItems - 1) / gridColumns) * gridColumns;
                        var col = selectedIndex % gridColumns;
                        var targetIndex = lastRowStart + col;
                        if (targetIndex < totalItems && targetIndex > selectedIndex) {
                            selectedIndex = targetIndex;
                        }
                    }
                }
                event.accepted = true;
                break;
            case Qt.Key_Return:
            case Qt.Key_Enter:
            case Qt.Key_Space:
                if (backButtonFocused) {
                    navigateUp();
                } else if (selectedIndex >= 0 && selectedIndex < totalItems) {
                    root.keyboardFileSelection(selectedIndex);
                }
                event.accepted = true;
                break;
            }
        }
    }

    Timer {
        id: keyboardSelectionTimer

        property int targetIndex: -1

        interval: 1
        onTriggered: {
            executeKeyboardSelection(targetIndex);
        }
    }

    focus: true

    Keys.onPressed: event => {
        keyboardController.handleKey(event);
    }

    Column {
        anchors.fill: parent
        spacing: 0

        Item {
            width: parent.width
            height: 48

            MouseArea {
                anchors.fill: parent
                onPressed: if (windowControls)
                    windowControls.tryStartMove()
                onDoubleClicked: if (windowControls)
                    windowControls.tryToggleMaximize()
            }

            Row {
                spacing: Theme.spacingM
                anchors.verticalCenter: parent.verticalCenter
                anchors.left: parent.left
                anchors.leftMargin: Theme.spacingL

                DankIcon {
                    name: browserIcon
                    size: Theme.iconSizeLarge
                    color: Theme.primary
                    anchors.verticalCenter: parent.verticalCenter
                }

                StyledText {
                    text: browserTitle
                    font.pixelSize: Theme.fontSizeXLarge
                    color: Theme.surfaceText
                    font.weight: Font.Medium
                    anchors.verticalCenter: parent.verticalCenter
                }
            }

            Row {
                anchors.right: parent.right
                anchors.rightMargin: Theme.spacingM
                anchors.verticalCenter: parent.verticalCenter
                spacing: Theme.spacingS

                DankActionButton {
                    circular: false
                    iconName: showHiddenFiles ? "visibility_off" : "visibility"
                    iconSize: Theme.iconSize - 4
                    iconColor: showHiddenFiles ? Theme.primary : Theme.surfaceText
                    onClicked: showHiddenFiles = !showHiddenFiles
                }

                DankActionButton {
                    circular: false
                    iconName: viewMode === "grid" ? "view_list" : "grid_view"
                    iconSize: Theme.iconSize - 4
                    iconColor: Theme.surfaceText
                    onClicked: viewMode = viewMode === "grid" ? "list" : "grid"
                }

                DankActionButton {
                    circular: false
                    iconName: iconSizeIndex === 0 ? "photo_size_select_small" : iconSizeIndex === 1 ? "photo_size_select_large" : iconSizeIndex === 2 ? "photo_size_select_actual" : "zoom_in"
                    iconSize: Theme.iconSize - 4
                    iconColor: Theme.surfaceText
                    visible: viewMode === "grid"
                    onClicked: iconSizeIndex = (iconSizeIndex + 1) % iconSizes.length
                }

                DankActionButton {
                    circular: false
                    iconName: "info"
                    iconSize: Theme.iconSize - 4
                    iconColor: Theme.surfaceText
                    onClicked: root.showKeyboardHints = !root.showKeyboardHints
                }

                DankActionButton {
                    visible: windowControls?.supported ?? false
                    circular: false
                    iconName: windowControls?.targetWindow?.maximized ? "fullscreen_exit" : "fullscreen"
                    iconSize: Theme.iconSize - 4
                    iconColor: Theme.surfaceText
                    onClicked: if (windowControls)
                        windowControls.tryToggleMaximize()
                }

                DankActionButton {
                    circular: false
                    iconName: "close"
                    iconSize: Theme.iconSize - 4
                    iconColor: Theme.surfaceText
                    onClicked: root.closeRequested()
                }
            }
        }

        StyledRect {
            width: parent.width
            height: 1
            color: Theme.outline
        }

        Item {
            width: parent.width
            height: parent.height - 49

            Row {
                anchors.fill: parent
                spacing: 0

                Row {
                    width: showSidebar ? 201 : 0
                    height: parent.height
                    spacing: 0
                    visible: showSidebar

                    FileBrowserSidebar {
                        height: parent.height
                        quickAccessLocations: root.quickAccessLocations
                        currentPath: root.currentPath
                        onLocationSelected: path => navigateTo(path)
                    }

                    StyledRect {
                        width: 1
                        height: parent.height
                        color: Theme.outline
                    }
                }

                Column {
                    width: parent.width - (showSidebar ? 201 : 0)
                    height: parent.height
                    spacing: 0

                    FileBrowserNavigation {
                        width: parent.width
                        currentPath: root.currentPath
                        homeDir: root.homeDir
                        backButtonFocused: root.backButtonFocused
                        keyboardNavigationActive: root.keyboardNavigationActive
                        showSidebar: root.showSidebar
                        pathEditMode: root.pathEditMode
                        onNavigateUp: root.navigateUp()
                        onNavigateTo: path => root.navigateTo(path)
                        onPathInputFocusChanged: hasFocus => {
                            root.pathInputHasFocus = hasFocus;
                            if (hasFocus) {
                                root.pathEditMode = true;
                            }
                        }
                    }

                    StyledRect {
                        width: parent.width
                        height: 1
                        color: Theme.outline
                    }

                    Item {
                        id: gridContainer
                        width: parent.width
                        height: parent.height - 41
                        clip: true

                        property real gridCellWidth: iconSizes[iconSizeIndex] + 24
                        property real gridCellHeight: iconSizes[iconSizeIndex] + 56
                        property real availableGridWidth: width - Theme.spacingM * 2
                        property int gridColumns: Math.max(1, Math.floor(availableGridWidth / gridCellWidth))
                        property real gridLeftMargin: Theme.spacingM + Math.max(0, (availableGridWidth - (gridColumns * gridCellWidth)) / 2)

                        onGridColumnsChanged: {
                            root.actualGridColumns = gridColumns;
                        }
                        Component.onCompleted: {
                            root.actualGridColumns = gridColumns;
                        }

                        DankGridView {
                            id: fileGrid
                            anchors.fill: parent
                            anchors.leftMargin: gridContainer.gridLeftMargin
                            anchors.rightMargin: Theme.spacingM
                            anchors.topMargin: Theme.spacingS
                            anchors.bottomMargin: Theme.spacingS
                            visible: viewMode === "grid"
                            cellWidth: gridContainer.gridCellWidth
                            cellHeight: gridContainer.gridCellHeight
                            cacheBuffer: 260
                            model: folderModel
                            currentIndex: selectedIndex
                            onCurrentIndexChanged: {
                                if (keyboardNavigationActive && currentIndex >= 0)
                                    positionViewAtIndex(currentIndex, GridView.Contain);
                            }

                            ScrollBar.vertical: DankScrollbar {
                                id: gridScrollbar
                            }

                            ScrollBar.horizontal: DankScrollbar {
                                policy: ScrollBar.AlwaysOff
                            }

                            delegate: FileBrowserGridDelegate {
                                iconSizes: root.iconSizes
                                iconSizeIndex: root.iconSizeIndex
                                selectedIndex: root.selectedIndex
                                keyboardNavigationActive: root.keyboardNavigationActive
                                onItemClicked: (index, path, name, isDir) => {
                                    selectedIndex = index;
                                    setSelectedFileData(path, name, isDir);
                                    if (isDir) {
                                        navigateTo(path);
                                    } else {
                                        fileSelected(path);
                                        root.closeRequested();
                                    }
                                }
                                onItemSelected: (index, path, name, isDir) => {
                                    setSelectedFileData(path, name, isDir);
                                }

                                Connections {
                                    function onKeyboardSelectionRequestedChanged() {
                                        if (root.keyboardSelectionRequested && root.keyboardSelectionIndex === index) {
                                            root.keyboardSelectionRequested = false;
                                            selectedIndex = index;
                                            setSelectedFileData(filePath, fileName, fileIsDir);
                                            if (fileIsDir) {
                                                navigateTo(filePath);
                                            } else {
                                                fileSelected(filePath);
                                                root.closeRequested();
                                            }
                                        }
                                    }

                                    target: root
                                }
                            }
                        }

                        DankListView {
                            id: fileList
                            anchors.fill: parent
                            anchors.leftMargin: Theme.spacingM
                            anchors.rightMargin: Theme.spacingM
                            anchors.topMargin: Theme.spacingS
                            anchors.bottomMargin: Theme.spacingS
                            visible: viewMode === "list"
                            spacing: 2
                            model: folderModel
                            currentIndex: selectedIndex
                            onCurrentIndexChanged: {
                                if (keyboardNavigationActive && currentIndex >= 0)
                                    positionViewAtIndex(currentIndex, ListView.Contain);
                            }

                            ScrollBar.vertical: DankScrollbar {
                                id: listScrollbar
                            }

                            delegate: FileBrowserListDelegate {
                                width: fileList.width
                                selectedIndex: root.selectedIndex
                                keyboardNavigationActive: root.keyboardNavigationActive
                                onItemClicked: (index, path, name, isDir) => {
                                    selectedIndex = index;
                                    setSelectedFileData(path, name, isDir);
                                    if (isDir) {
                                        navigateTo(path);
                                    } else {
                                        fileSelected(path);
                                        root.closeRequested();
                                    }
                                }
                                onItemSelected: (index, path, name, isDir) => {
                                    setSelectedFileData(path, name, isDir);
                                }

                                Connections {
                                    function onKeyboardSelectionRequestedChanged() {
                                        if (root.keyboardSelectionRequested && root.keyboardSelectionIndex === index) {
                                            root.keyboardSelectionRequested = false;
                                            selectedIndex = index;
                                            setSelectedFileData(filePath, fileName, fileIsDir);
                                            if (fileIsDir) {
                                                navigateTo(filePath);
                                            } else {
                                                fileSelected(filePath);
                                                root.closeRequested();
                                            }
                                        }
                                    }

                                    target: root
                                }
                            }
                        }
                    }
                }
            }

            FileBrowserSaveRow {
                anchors.bottom: parent.bottom
                anchors.left: parent.left
                anchors.right: parent.right
                anchors.margins: Theme.spacingL
                saveMode: root.saveMode
                defaultFileName: root.defaultFileName
                currentPath: root.currentPath
                onSaveRequested: filePath => handleSaveFile(filePath)
            }

            KeyboardHints {
                id: keyboardHints

                anchors.bottom: parent.bottom
                anchors.left: parent.left
                anchors.right: parent.right
                anchors.margins: Theme.spacingL
                showHints: root.showKeyboardHints
            }

            FileInfo {
                id: fileInfo

                anchors.top: parent.top
                anchors.right: parent.right
                anchors.margins: Theme.spacingL
                width: 300
                showFileInfo: root.showFileInfo
                selectedIndex: root.selectedIndex
                sourceFolderModel: folderModel
                currentPath: root.currentPath
                currentFileName: root.selectedFileName
                currentFileIsDir: root.selectedFileIsDir
                currentFileExtension: {
                    if (root.selectedFileIsDir || !root.selectedFileName)
                        return "";

                    var lastDot = root.selectedFileName.lastIndexOf('.');
                    return lastDot > 0 ? root.selectedFileName.substring(lastDot + 1).toLowerCase() : "";
                }
            }

            FileBrowserSortMenu {
                id: sortMenu
                anchors.top: parent.top
                anchors.right: parent.right
                anchors.topMargin: 120
                anchors.rightMargin: Theme.spacingL
                sortBy: root.sortBy
                sortAscending: root.sortAscending
                onSortBySelected: value => {
                    root.sortBy = value;
                }
                onSortOrderSelected: ascending => {
                    root.sortAscending = ascending;
                }
            }
        }

        FileBrowserOverwriteDialog {
            anchors.fill: parent
            showDialog: showOverwriteConfirmation
            pendingFilePath: root.pendingFilePath
            onConfirmed: filePath => {
                showOverwriteConfirmation = false;
                fileSelected(filePath);
                pendingFilePath = "";
                Qt.callLater(() => root.closeRequested());
            }
            onCancelled: {
                showOverwriteConfirmation = false;
                pendingFilePath = "";
            }
        }
    }
}