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
|
|
|
|
|
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 __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)
|
|
|
|
{
|
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()
|
|
|
|
}
|
|
|
|
|
|
|
|
function openContextMenuForDir(dirModelIndex, dirPath, dirName, allExpandedState,
|
|
|
|
onFolderCreated, onFolderRenamed)
|
|
|
|
{
|
2022-11-23 15:47:34 +02:00
|
|
|
root.__onFolderCreated = onFolderCreated
|
|
|
|
root.__onFolderRenamed = onFolderRenamed
|
|
|
|
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
|
|
|
{
|
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
|
|
|
|
2022-11-23 15:47:34 +02:00
|
|
|
root.__onFolderCreated = onFolderCreated
|
|
|
|
root.__selectedAssetPathsList = selectedAssetPathsList
|
|
|
|
root.__fileIndex = fileIndex
|
|
|
|
root.__dirIndex = dirModelIndex
|
|
|
|
root.__dirPath = assetsModel.filePath(dirModelIndex)
|
|
|
|
root.__isDirectory = false
|
2022-11-23 11:49:45 +02:00
|
|
|
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")
|
|
|
|
visible: root.__fileIndex && assetsModel.allFilePathsAreImages(root.__selectedAssetPathsList)
|
|
|
|
height: addTexturesItem.visible ? addTexturesItem.implicitHeight : 0
|
|
|
|
onTriggered: rootView.addTextures(root.__selectedAssetPathsList)
|
|
|
|
}
|
|
|
|
|
|
|
|
StudioControls.MenuItem {
|
|
|
|
id: addLightProbes
|
|
|
|
text: qsTr("Add Light Probe")
|
|
|
|
visible: root.__fileIndex && root.__selectedAssetPathsList.length === 1
|
|
|
|
&& assetsModel.allFilePathsAreImages(root.__selectedAssetPathsList)
|
|
|
|
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: {
|
2022-11-23 15:47:34 +02:00
|
|
|
let deleted = 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
|
|
|
|
2022-11-23 15:47:34 +02:00
|
|
|
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
|
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: {
|
2022-11-23 15:47:34 +02:00
|
|
|
if (!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.
|
2022-11-23 15:47:34 +02:00
|
|
|
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")
|
2022-12-19 16:50:24 +02:00
|
|
|
visible: assetsModel.canCreateEffects()
|
2022-12-19 11:35:21 +02:00
|
|
|
|
|
|
|
NewEffectDialog {
|
|
|
|
id: newEffectDialog
|
|
|
|
parent: root.assetsView
|
|
|
|
dirPath: root.__dirPath
|
|
|
|
}
|
|
|
|
|
|
|
|
onTriggered: newEffectDialog.open()
|
|
|
|
}
|
2022-10-07 19:49:52 +03:00
|
|
|
}
|