2022-11-23 11:49:45 +02:00
|
|
|
// Copyright (C) 2022 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2022-10-07 19:49:52 +03:00
|
|
|
|
|
|
|
import QtQuick
|
|
|
|
import QtQuick.Controls
|
|
|
|
import StudioControls as StudioControls
|
|
|
|
import StudioTheme as StudioTheme
|
|
|
|
|
|
|
|
StudioControls.Menu {
|
2022-11-23 11:49:45 +02:00
|
|
|
id: root
|
|
|
|
|
|
|
|
required property Item assetsView
|
|
|
|
|
|
|
|
property bool _isDirectory: false
|
|
|
|
property var _fileIndex: null
|
|
|
|
property string _dirPath: ""
|
|
|
|
property string _dirName: ""
|
|
|
|
property var _onFolderCreated: null
|
|
|
|
property var _onFolderRenamed: null
|
|
|
|
property var _dirIndex: null
|
|
|
|
property string _allExpandedState: ""
|
|
|
|
property var _selectedAssetPathsList: null
|
2022-10-07 19:49:52 +03:00
|
|
|
|
|
|
|
closePolicy: Popup.CloseOnPressOutside | Popup.CloseOnEscape
|
|
|
|
|
2022-11-23 11:49:45 +02:00
|
|
|
function openContextMenuForRoot(rootModelIndex, dirPath, dirName, onFolderCreated)
|
|
|
|
{
|
|
|
|
root._onFolderCreated = onFolderCreated
|
|
|
|
root._fileIndex = ""
|
|
|
|
root._dirPath = dirPath
|
|
|
|
root._dirName = dirName
|
|
|
|
root._dirIndex = rootModelIndex
|
|
|
|
root._isDirectory = false
|
|
|
|
root.popup()
|
|
|
|
}
|
|
|
|
|
|
|
|
function openContextMenuForDir(dirModelIndex, dirPath, dirName, allExpandedState,
|
|
|
|
onFolderCreated, onFolderRenamed)
|
|
|
|
{
|
|
|
|
root._onFolderCreated = onFolderCreated
|
|
|
|
root._onFolderRenamed = onFolderRenamed
|
|
|
|
root._dirPath = dirPath
|
|
|
|
root._dirName = dirName
|
|
|
|
root._fileIndex = ""
|
|
|
|
root._dirIndex = dirModelIndex
|
|
|
|
root._isDirectory = true
|
|
|
|
root._allExpandedState = allExpandedState
|
|
|
|
root.popup()
|
|
|
|
}
|
|
|
|
|
|
|
|
function openContextMenuForFile(fileIndex, dirModelIndex, selectedAssetPathsList)
|
|
|
|
{
|
|
|
|
var numSelected = selectedAssetPathsList.filter(p => p).length
|
2022-10-07 19:49:52 +03:00
|
|
|
deleteFileItem.text = numSelected > 1 ? qsTr("Delete Files") : qsTr("Delete File")
|
2022-11-23 11:49:45 +02:00
|
|
|
|
|
|
|
root._selectedAssetPathsList = selectedAssetPathsList
|
|
|
|
root._fileIndex = fileIndex
|
|
|
|
root._dirIndex = dirModelIndex
|
|
|
|
root._dirPath = assetsModel.filePath(dirModelIndex)
|
|
|
|
root._isDirectory = false
|
|
|
|
root.popup()
|
2022-10-07 19:49:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
StudioControls.MenuItem {
|
|
|
|
text: qsTr("Expand All")
|
2022-11-23 11:49:45 +02:00
|
|
|
enabled: root._allExpandedState !== "all_expanded"
|
|
|
|
visible: root._isDirectory
|
2022-10-07 19:49:52 +03:00
|
|
|
height: visible ? implicitHeight : 0
|
2022-11-23 11:49:45 +02:00
|
|
|
onTriggered: root.assetsView.expandAll()
|
2022-10-07 19:49:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
StudioControls.MenuItem {
|
|
|
|
text: qsTr("Collapse All")
|
2022-11-23 11:49:45 +02:00
|
|
|
enabled: root._allExpandedState !== "all_collapsed"
|
|
|
|
visible: root._isDirectory
|
2022-10-07 19:49:52 +03:00
|
|
|
height: visible ? implicitHeight : 0
|
2022-11-23 11:49:45 +02:00
|
|
|
onTriggered: root.assetsView.collapseAll()
|
2022-10-07 19:49:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
StudioControls.MenuSeparator {
|
2022-11-23 11:49:45 +02:00
|
|
|
visible: root._isDirectory
|
2022-10-07 19:49:52 +03:00
|
|
|
height: visible ? StudioTheme.Values.border : 0
|
|
|
|
}
|
|
|
|
|
|
|
|
StudioControls.MenuItem {
|
|
|
|
id: deleteFileItem
|
|
|
|
text: qsTr("Delete File")
|
2022-11-23 11:49:45 +02:00
|
|
|
visible: root._fileIndex
|
2022-10-07 19:49:52 +03:00
|
|
|
height: deleteFileItem.visible ? deleteFileItem.implicitHeight : 0
|
2022-11-23 11:49:45 +02:00
|
|
|
onTriggered: assetsModel.deleteFiles(root._selectedAssetPathsList)
|
2022-10-07 19:49:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
StudioControls.MenuSeparator {
|
2022-11-23 11:49:45 +02:00
|
|
|
visible: root._fileIndex
|
2022-10-07 19:49:52 +03:00
|
|
|
height: visible ? StudioTheme.Values.border : 0
|
|
|
|
}
|
|
|
|
|
|
|
|
StudioControls.MenuItem {
|
|
|
|
text: qsTr("Rename Folder")
|
2022-11-23 11:49:45 +02:00
|
|
|
visible: root._isDirectory
|
2022-10-07 19:49:52 +03:00
|
|
|
height: visible ? implicitHeight : 0
|
|
|
|
onTriggered: renameFolderDialog.open()
|
|
|
|
|
|
|
|
RenameFolderDialog {
|
|
|
|
id: renameFolderDialog
|
2022-11-23 11:49:45 +02:00
|
|
|
parent: root.assetsView
|
|
|
|
dirPath: root._dirPath
|
|
|
|
dirName: root._dirName
|
|
|
|
|
|
|
|
onAccepted: root._onFolderRenamed()
|
2022-10-07 19:49:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
StudioControls.MenuItem {
|
|
|
|
text: qsTr("New Folder")
|
|
|
|
|
|
|
|
NewFolderDialog {
|
|
|
|
id: newFolderDialog
|
2022-11-23 11:49:45 +02:00
|
|
|
parent: root.assetsView
|
|
|
|
dirPath: root._dirPath
|
|
|
|
|
|
|
|
onAccepted: root._onFolderCreated(newFolderDialog.createdDirPath)
|
2022-10-07 19:49:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
onTriggered: newFolderDialog.open()
|
|
|
|
}
|
|
|
|
|
|
|
|
StudioControls.MenuItem {
|
|
|
|
text: qsTr("Delete Folder")
|
2022-11-23 11:49:45 +02:00
|
|
|
visible: root._isDirectory
|
2022-10-07 19:49:52 +03:00
|
|
|
height: visible ? implicitHeight : 0
|
|
|
|
|
|
|
|
ConfirmDeleteFolderDialog {
|
|
|
|
id: confirmDeleteFolderDialog
|
2022-11-23 11:49:45 +02:00
|
|
|
parent: root.assetsView
|
|
|
|
dirName: root._dirName
|
|
|
|
dirIndex: root._dirIndex
|
2022-10-07 19:49:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
onTriggered: {
|
2022-11-23 11:49:45 +02:00
|
|
|
if (!assetsModel.hasChildren(root._dirIndex)) {
|
|
|
|
// NOTE: the folder may still not be empty -- it doesn't have files visible to the
|
|
|
|
// user, but that doesn't mean that there are no other files (e.g. files of unknown
|
|
|
|
// types) on disk in this directory.
|
|
|
|
assetsModel.deleteFolderRecursively(root._dirIndex)
|
|
|
|
} else {
|
2022-10-07 19:49:52 +03:00
|
|
|
confirmDeleteFolderDialog.open()
|
2022-11-23 11:49:45 +02:00
|
|
|
}
|
2022-10-07 19:49:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|