2022-11-23 11:49:45 +02:00
|
|
|
// Copyright (C) 2022 The Qt Company Ltd.
|
2023-01-04 08:52:22 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only 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
|
2023-03-07 16:51:02 +01:00
|
|
|
import AssetsLibraryBackend
|
2022-10-07 19:49:52 +03:00
|
|
|
|
|
|
|
StudioControls.Menu {
|
2022-11-23 11:49:45 +02:00
|
|
|
id: root
|
|
|
|
|
|
|
|
required property Item assetsView
|
|
|
|
|
2023-03-07 16:51:02 +01:00
|
|
|
property var assetsModel: AssetsLibraryBackend.assetsModel
|
|
|
|
property var rootView: AssetsLibraryBackend.rootView
|
|
|
|
|
2022-11-23 15:47:34 +02:00
|
|
|
property bool __isDirectory: false
|
|
|
|
property var __fileIndex: null
|
|
|
|
property string __dirPath: ""
|
|
|
|
property string __dirName: ""
|
|
|
|
property var __onFolderCreated: null
|
|
|
|
property var __dirIndex: null
|
|
|
|
property string __allExpandedState: ""
|
|
|
|
property var __selectedAssetPathsList: null
|
2023-02-07 16:44:30 +02:00
|
|
|
property bool __showInGraphicalShellEnabled: false
|
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)
|
|
|
|
{
|
2023-02-07 16:44:30 +02:00
|
|
|
root.__showInGraphicalShellEnabled = true
|
|
|
|
|
2023-03-28 01:58:46 +03:00
|
|
|
rootView.updateContextMenuActionsEnableState()
|
2023-01-12 17:53:10 +02:00
|
|
|
|
2022-11-23 15:47:34 +02:00
|
|
|
root.__onFolderCreated = onFolderCreated
|
|
|
|
root.__fileIndex = ""
|
|
|
|
root.__dirPath = dirPath
|
|
|
|
root.__dirName = dirName
|
|
|
|
root.__dirIndex = rootModelIndex
|
|
|
|
root.__isDirectory = false
|
2022-11-23 11:49:45 +02:00
|
|
|
root.popup()
|
|
|
|
}
|
|
|
|
|
2023-02-07 16:44:30 +02:00
|
|
|
function openContextMenuForDir(dirModelIndex, dirPath, dirName, allExpandedState, onFolderCreated)
|
2022-11-23 11:49:45 +02:00
|
|
|
{
|
2023-02-07 16:44:30 +02:00
|
|
|
root.__showInGraphicalShellEnabled = true
|
|
|
|
|
2023-03-28 01:58:46 +03:00
|
|
|
rootView.updateContextMenuActionsEnableState()
|
2023-01-12 17:53:10 +02:00
|
|
|
|
2022-11-23 15:47:34 +02:00
|
|
|
root.__onFolderCreated = onFolderCreated
|
|
|
|
root.__dirPath = dirPath
|
|
|
|
root.__dirName = dirName
|
|
|
|
root.__fileIndex = ""
|
|
|
|
root.__dirIndex = dirModelIndex
|
|
|
|
root.__isDirectory = true
|
|
|
|
root.__allExpandedState = allExpandedState
|
2022-11-23 11:49:45 +02:00
|
|
|
root.popup()
|
|
|
|
}
|
|
|
|
|
2022-11-23 15:47:34 +02:00
|
|
|
function openContextMenuForFile(fileIndex, dirModelIndex, selectedAssetPathsList, onFolderCreated)
|
2022-11-23 11:49:45 +02:00
|
|
|
{
|
2023-02-07 16:44:30 +02:00
|
|
|
// check that all assets are in the same folder
|
|
|
|
let asset0 = selectedAssetPathsList[0]
|
|
|
|
let asset0Folder = asset0.substring(0, asset0.lastIndexOf('/'))
|
|
|
|
|
|
|
|
root.__showInGraphicalShellEnabled = selectedAssetPathsList.every(v => {
|
|
|
|
let assetFolder = v.substring(0, v.lastIndexOf('/'))
|
|
|
|
return assetFolder === asset0Folder
|
|
|
|
})
|
|
|
|
|
2022-11-24 19:23:03 +02:00
|
|
|
if (selectedAssetPathsList.length > 1) {
|
|
|
|
deleteFileItem.text = qsTr("Delete Files")
|
|
|
|
addTexturesItem.text = qsTr("Add Textures")
|
|
|
|
} else {
|
|
|
|
deleteFileItem.text = qsTr("Delete File")
|
|
|
|
addTexturesItem.text = qsTr("Add Texture")
|
|
|
|
}
|
2022-11-23 11:49:45 +02:00
|
|
|
|
2023-03-28 01:58:46 +03:00
|
|
|
rootView.updateContextMenuActionsEnableState()
|
2023-01-12 17:53:10 +02:00
|
|
|
|
2022-11-23 15:47:34 +02:00
|
|
|
root.__onFolderCreated = onFolderCreated
|
|
|
|
root.__selectedAssetPathsList = selectedAssetPathsList
|
|
|
|
root.__fileIndex = fileIndex
|
|
|
|
root.__dirIndex = dirModelIndex
|
2023-03-07 16:51:02 +01:00
|
|
|
root.__dirPath = AssetsLibraryBackend.assetsModel.filePath(dirModelIndex)
|
2022-11-23 15:47:34 +02:00
|
|
|
root.__isDirectory = false
|
2022-11-23 11:49:45 +02:00
|
|
|
root.popup()
|
2022-10-07 19:49:52 +03:00
|
|
|
}
|
|
|
|
|
2023-01-10 11:51:20 +02:00
|
|
|
function openContextMenuForEmpty(dirPath)
|
|
|
|
{
|
2023-02-07 16:44:30 +02:00
|
|
|
__showInGraphicalShellEnabled = true
|
|
|
|
|
2023-01-10 11:51:20 +02:00
|
|
|
root.__dirPath = dirPath
|
|
|
|
root.__fileIndex = ""
|
|
|
|
root.__dirIndex = ""
|
|
|
|
root.__isDirectory = false
|
|
|
|
root.popup()
|
|
|
|
}
|
|
|
|
|
2022-10-07 19:49:52 +03:00
|
|
|
StudioControls.MenuItem {
|
|
|
|
text: qsTr("Expand All")
|
2022-11-23 15:47:34 +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 15:47:34 +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 15:47:34 +02:00
|
|
|
visible: root.__isDirectory
|
2022-10-07 19:49:52 +03:00
|
|
|
height: visible ? StudioTheme.Values.border : 0
|
|
|
|
}
|
|
|
|
|
2022-11-24 19:23:03 +02:00
|
|
|
StudioControls.MenuItem {
|
|
|
|
id: addTexturesItem
|
|
|
|
text: qsTr("Add Texture")
|
2023-01-12 17:53:10 +02:00
|
|
|
enabled: rootView.hasMaterialLibrary
|
2023-03-07 16:51:02 +01:00
|
|
|
visible: root.__fileIndex && AssetsLibraryBackend.assetsModel.allFilePathsAreTextures(root.__selectedAssetPathsList)
|
2022-11-24 19:23:03 +02:00
|
|
|
height: addTexturesItem.visible ? addTexturesItem.implicitHeight : 0
|
2023-03-07 16:51:02 +01:00
|
|
|
onTriggered: AssetsLibraryBackend.rootView.addTextures(root.__selectedAssetPathsList)
|
2022-11-24 19:23:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
StudioControls.MenuItem {
|
|
|
|
id: addLightProbes
|
|
|
|
text: qsTr("Add Light Probe")
|
2023-03-28 01:58:46 +03:00
|
|
|
enabled: rootView.hasMaterialLibrary && rootView.hasSceneEnv
|
2022-11-24 19:23:03 +02:00
|
|
|
visible: root.__fileIndex && root.__selectedAssetPathsList.length === 1
|
2023-03-07 16:51:02 +01:00
|
|
|
&& AssetsLibraryBackend.assetsModel.allFilePathsAreTextures(root.__selectedAssetPathsList)
|
2022-11-24 19:23:03 +02:00
|
|
|
height: addLightProbes.visible ? addLightProbes.implicitHeight : 0
|
|
|
|
onTriggered: rootView.addLightProbe(root.__selectedAssetPathsList[0])
|
|
|
|
}
|
|
|
|
|
2022-10-07 19:49:52 +03:00
|
|
|
StudioControls.MenuItem {
|
|
|
|
id: deleteFileItem
|
|
|
|
text: qsTr("Delete File")
|
2022-11-23 15:47:34 +02:00
|
|
|
visible: root.__fileIndex
|
2022-10-07 19:49:52 +03:00
|
|
|
height: deleteFileItem.visible ? deleteFileItem.implicitHeight : 0
|
2022-10-31 15:24:30 +02:00
|
|
|
onTriggered: {
|
2023-03-07 16:51:02 +01:00
|
|
|
let deleted = AssetsLibraryBackend.assetsModel.requestDeleteFiles(root.__selectedAssetPathsList)
|
2022-10-31 15:24:30 +02:00
|
|
|
if (!deleted)
|
|
|
|
confirmDeleteFiles.open()
|
|
|
|
}
|
|
|
|
|
|
|
|
ConfirmDeleteFilesDialog {
|
|
|
|
id: confirmDeleteFiles
|
|
|
|
parent: root.assetsView
|
2022-11-23 15:47:34 +02:00
|
|
|
files: root.__selectedAssetPathsList
|
2022-10-31 15:24:30 +02:00
|
|
|
|
|
|
|
onAccepted: root.assetsView.selectedAssets = {}
|
|
|
|
}
|
2022-10-07 19:49:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
StudioControls.MenuSeparator {
|
2022-11-23 15:47:34 +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 15:47:34 +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
|
2022-11-23 15:47:34 +02:00
|
|
|
dirPath: root.__dirPath
|
|
|
|
dirName: root.__dirName
|
2022-11-23 11:49:45 +02:00
|
|
|
|
2023-01-26 23:40:01 +02:00
|
|
|
onAccepted: root.__onFolderCreated(renameFolderDialog.renamedDirPath)
|
2022-10-07 19:49:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
StudioControls.MenuItem {
|
|
|
|
text: qsTr("New Folder")
|
2023-03-07 16:51:02 +01:00
|
|
|
visible: AssetsLibraryBackend.assetsModel.haveFiles
|
2023-01-10 11:51:20 +02:00
|
|
|
height: visible ? implicitHeight : 0
|
2022-10-07 19:49:52 +03:00
|
|
|
|
|
|
|
NewFolderDialog {
|
|
|
|
id: newFolderDialog
|
2022-11-23 11:49:45 +02:00
|
|
|
parent: root.assetsView
|
2022-11-23 15:47:34 +02:00
|
|
|
dirPath: root.__dirPath
|
2022-11-23 11:49:45 +02:00
|
|
|
|
2022-11-23 15:47:34 +02:00
|
|
|
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 15:47:34 +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
|
2022-11-23 15:47:34 +02:00
|
|
|
dirName: root.__dirName
|
|
|
|
dirIndex: root.__dirIndex
|
2022-10-07 19:49:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
onTriggered: {
|
2023-03-07 16:51:02 +01:00
|
|
|
if (!AssetsLibraryBackend.assetsModel.hasChildren(root.__dirIndex)) {
|
2022-11-23 11:49:45 +02:00
|
|
|
// 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.
|
2023-03-07 16:51:02 +01:00
|
|
|
AssetsLibraryBackend.assetsModel.deleteFolderRecursively(root.__dirIndex)
|
2022-11-23 11:49:45 +02:00
|
|
|
} 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
|
|
|
}
|
|
|
|
}
|
2022-12-19 11:35:21 +02:00
|
|
|
|
|
|
|
StudioControls.MenuItem {
|
|
|
|
text: qsTr("New Effect")
|
2023-01-26 15:12:00 +02:00
|
|
|
visible: rootView.canCreateEffects()
|
2023-02-07 16:44:30 +02:00
|
|
|
height: visible ? implicitHeight : 0
|
2022-12-19 11:35:21 +02:00
|
|
|
|
|
|
|
NewEffectDialog {
|
|
|
|
id: newEffectDialog
|
2023-01-10 11:51:20 +02:00
|
|
|
parent: root.assetsView.parent
|
2022-12-19 11:35:21 +02:00
|
|
|
dirPath: root.__dirPath
|
|
|
|
}
|
|
|
|
|
|
|
|
onTriggered: newEffectDialog.open()
|
|
|
|
}
|
2023-02-07 16:44:30 +02:00
|
|
|
|
|
|
|
StudioControls.MenuItem {
|
|
|
|
text: rootView.showInGraphicalShellMsg()
|
|
|
|
|
|
|
|
enabled: root.__showInGraphicalShellEnabled
|
|
|
|
|
|
|
|
onTriggered: {
|
|
|
|
if (!root.__fileIndex || root.__selectedAssetPathsList.length > 1)
|
|
|
|
rootView.showInGraphicalShell(root.__dirPath)
|
|
|
|
else
|
|
|
|
rootView.showInGraphicalShell(root.__selectedAssetPathsList[0])
|
|
|
|
}
|
|
|
|
}
|
2022-10-07 19:49:52 +03:00
|
|
|
}
|