/*SPDX-FileCopyrightText: 2014-2015 Eike Hein <hein@kde.org>SPDX-License-Identifier: GPL-2.0-or-later*/pragma ComponentBehavior: Boundimport QtQuickimport QtQmlimport org.kde.plasma.plasmoidimport org.kde.plasma.core as PlasmaCoreimport org.kde.plasma.components as PlasmaComponentsimport org.kde.config // for KAuthorizedimport org.kde.kirigami as Kirigamiimport org.kde.private.desktopcontainment.folder as FolderFocusScope {id: folderViewLayerComponent// these need to be passed in from main, but required properties with Loaders are awkward/*required*/ property bool inPanel/*required*/ property bool useListViewModeproperty var sharedActions: ["newMenu", "paste", "undo", "emptyTrash"]property Component folderViewDialogComponent: Qt.createComponent("FolderViewDialog.qml", Qt.Asynchronous, root)property FolderView view: folderViewproperty Item label: nullproperty int labelHeight: Kirigami.Units.iconSizes.sizeForLabels + (Kirigami.Units.smallSpacing * 2)property alias model: folderView.modelproperty alias overflowing: folderView.overflowingproperty alias flow: folderView.flowreadonly property bool lockedByKiosk: !KAuthorized.authorize("editable_desktop_icons")focus: truefunction updateContextualActions() {folderView.model.updateActions();for (let i = 0, len = sharedActions.length; i < len; i++) {const actionName = sharedActions[i];const appletAction = Plasmoid.internalAction(actionName);if (appletAction) {const modelAction = folderView.model.action(actionName);appletAction.text = modelAction.text;appletAction.enabled = modelAction.enabled;appletAction.visible = modelAction.visible;}}}function cancelRename() {folderView.cancelRename();}function goHome() {if (folderView.url !== Plasmoid.configuration.url) {folderView.url = Qt.binding(() => Plasmoid.configuration.url);folderView.history = [];folderView.historyChanged();}}Binding {target: Plasmoidproperty: "title"value: labelGenerator.displayLabelrestoreMode: Binding.RestoreBinding}Folder.LabelGenerator {id: labelGeneratorfolderModel: folderView.modelrtl: (Application.layoutDirection === Qt.RightToLeft)labelMode: Plasmoid.configuration.labelMode || (Plasmoid.isContainment ? 0 : 1)labelText: Plasmoid.configuration.labelText}Folder.ViewPropertiesMenu {id: viewPropertiesMenushowLayoutActions: !folderViewLayerComponent.inPanelshowLockAction: Plasmoid.isContainmentshowIconSizeActions: !folderViewLayerComponent.useListViewModelockedEnabled: !folderViewLayerComponent.lockedByKioskonArrangementChanged: {Plasmoid.configuration.arrangement = arrangement;}onAlignmentChanged: {Plasmoid.configuration.alignment = alignment;}onPreviewsChanged: {Plasmoid.configuration.previews = previews;}onLockedChanged: {if (!folderViewLayerComponent.lockedByKiosk) {Plasmoid.configuration.locked = locked;}}onSortModeChanged: {Plasmoid.configuration.sortMode = sortMode;}onSortDescChanged: {Plasmoid.configuration.sortDesc = sortDesc;}onSortDirsFirstChanged: {Plasmoid.configuration.sortDirsFirst = sortDirsFirst;}onIconSizeChanged: {Plasmoid.configuration.iconSize = iconSize;}Component.onCompleted: {arrangement = Plasmoid.configuration.arrangement;alignment = Plasmoid.configuration.alignment;previews = Plasmoid.configuration.previews;locked = Plasmoid.configuration.locked || folderViewLayerComponent.lockedByKiosk;sortMode = Plasmoid.configuration.sortMode;sortDesc = Plasmoid.configuration.sortDesc;sortDirsFirst = Plasmoid.configuration.sortDirsFirst;iconSize = Plasmoid.configuration.iconSize;}}PlasmaComponents.Label {anchors.fill: parenttext: folderView.errorStringtextFormat: Text.PlainTexthorizontalAlignment: Text.AlignHCenterverticalAlignment: Text.AlignVCenterwrapMode: Text.Wrap}Connections {target: rootfunction onExpandedChanged() {if (folderViewLayerComponent.inPanel) {if (root.expanded) {folderView.currentIndex = -1;folderView.forceActiveFocus();folderView.positionViewAtBeginning();} else {folderViewLayerComponent.goHome();folderView.currentIndex = -1;folderView.model.clearSelection();folderView.cancelRename();}}}}Connections {target: Plasmoid.configurationfunction onArrangementChanged() {viewPropertiesMenu.arrangement = Plasmoid.configuration.arrangement;}function onAlignmentChanged() {viewPropertiesMenu.alignment = Plasmoid.configuration.alignment;}function onLockedChanged() {viewPropertiesMenu.locked = Plasmoid.configuration.locked;}function onSortModeChanged() {folderView.sortMode = Plasmoid.configuration.sortMode;viewPropertiesMenu.sortMode = Plasmoid.configuration.sortMode;}function onSortDescChanged() {viewPropertiesMenu.sortDesc = Plasmoid.configuration.sortDesc;}function onSortDirsFirstChanged() {viewPropertiesMenu.sortDirsFirst = Plasmoid.configuration.sortDirsFirst;}function onIconSizeChanged() {viewPropertiesMenu.iconSize = Plasmoid.configuration.iconSize;}}FolderView {id: folderViewanchors.left: parent.leftanchors.top: parent.topanchors.topMargin: folderViewLayerComponent.label !== null ? folderViewLayerComponent.label.height : 0anchors.right: parent.rightanchors.bottom: parent.bottomfocus: trueisRootView: Plasmoid.isContainmentpositionerApplet: Plasmoidurl: Plasmoid.configuration.urllocked: (Plasmoid.configuration.locked || !Plasmoid.isContainment || folderViewLayerComponent.lockedByKiosk)filterMode: Plasmoid.configuration.filterModefilterPattern: Plasmoid.configuration.filterPatternfilterMimeTypes: Plasmoid.configuration.filterMimeTypesshowHiddenFiles: Plasmoid.configuration.showHiddenFilesflow: (Plasmoid.configuration.arrangement === 0) ? GridView.FlowLeftToRight : GridView.FlowTopToBottomlayoutDirection: (Plasmoid.configuration.alignment === 0) ? Qt.LeftToRight : Qt.RightToLeftonSortModeChanged: {Plasmoid.configuration.sortMode = sortMode;}Component.onCompleted: {folderView.sortMode = Plasmoid.configuration.sortMode;}}Component {id: labelComponentItem {id: label// If we bind height to visible, it will be invisible initially (since "visible"// propagates recursively) and that confuses the Label, hence the temp property.readonly property bool active: (Plasmoid.configuration.labelMode !== 0)readonly property bool showPin: folderViewLayerComponent.inPanel && root.compactRepresentationItem && root.compactRepresentationItem.visiblewidth: parent.widthheight: active ? folderViewLayerComponent.labelHeight : 0visible: activeproperty Item windowPin: nullproperty Item homeButton: nullonVisibleChanged: {if (folderViewLayerComponent.inPanel && !visible) {root.hideOnWindowDeactivate = true;}}onShowPinChanged: {if (!windowPin && showPin) {windowPin = windowPinComponent.createObject(label);} else if (windowPin) {windowPin.destroy();windowPin = null;}}Connections {target: folderViewfunction onUrlChanged() {if (!label.homeButton && folderView.url !== Plasmoid.configuration.url) {label.homeButton = homeButtonComponent.createObject(label);} else if (label.homeButton && folderView.url === Plasmoid.configuration.url) {label.homeButton.destroy();}}}PlasmaComponents.Label {id: textanchors {left: label.homeButton ? label.homeButton.right : parent.leftright: label.windowPin ? label.windowPin.left : parent.rightmargins: Kirigami.Units.smallSpacing}height: parent.heighthorizontalAlignment: Text.AlignHCenterverticalAlignment: Text.AlignTopelide: Text.ElideMiddletext: labelGenerator.displayLabeltextFormat: Text.PlainTextfont.underline: labelMouseArea.containsMouse}MouseArea {id: labelMouseAreaanchors {top: text.tophorizontalCenter: text.horizontalCenter}width: text.contentWidthheight: text.contentHeighthoverEnabled: truecursorShape: Qt.PointingHandCursoronClicked: {Folder.AppLauncher.openUrl(folderView.url)}}Component {id: windowPinComponentPlasmaComponents.ToolButton {id: windowPinanchors.right: parent.rightvisible: label.showPinwidth: folderViewLayerComponent.inPanel ? Math.round(Kirigami.Units.gridUnit * 1.25) : 0height: widthcheckable: trueicon.name: "window-pin"onCheckedChanged: root.hideOnWindowDeactivate = !checked}}Component {id: homeButtonComponentPlasmaComponents.ToolButton {id: homeButtonanchors.left: parent.leftvisible: folderViewLayerComponent.inPanel && folderView.url !== Plasmoid.configuration.urlwidth: folderViewLayerComponent.inPanel ? Math.round(Kirigami.Units.gridUnit * 1.25) : 0height: widthicon.name: "go-home"onClicked: folderViewLayerComponent.goHome()}}}}PlasmaCore.Action {id: viewPropertiesActiontext: i18nc("@item:inmenu opens submenu with view options like sorting", "Icons")icon.name: "view-list-icons"menu: viewPropertiesMenu.menu}PlasmaCore.Action {id: actionSeparatorisSeparator: true}Component.onCompleted: {if (!Plasmoid.isContainment) {label = labelComponent.createObject(folderViewLayerComponent);}for (let i = 0, len = sharedActions.length; i < len; i++) {const actionName = sharedActions[i];const modelAction = folderView.model.action(actionName);Plasmoid.contextualActions.push(modelAction)if (actionName === "emptyTrash") {Plasmoid.contextualActions.push(viewPropertiesAction)}}Plasmoid.contextualActions.push(actionSeparator);Plasmoid.contextualActionsAboutToShow.connect(updateContextualActions);Plasmoid.contextualActionsAboutToShow.connect(folderView.model.clearSelection);}}