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
|
2022-11-23 11:49:45 +02:00
|
|
|
import HelperWidgets as HelperWidgets
|
2022-10-07 19:49:52 +03:00
|
|
|
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
|
|
|
|
|
|
|
|
Dialog {
|
2022-11-23 11:49:45 +02:00
|
|
|
id: root
|
2022-10-07 19:49:52 +03:00
|
|
|
|
|
|
|
|
title: qsTr("Create New Folder")
|
|
|
|
|
anchors.centerIn: parent
|
|
|
|
|
closePolicy: Popup.CloseOnEscape
|
|
|
|
|
modal: true
|
|
|
|
|
|
2022-11-23 11:49:45 +02:00
|
|
|
required property string dirPath
|
|
|
|
|
property string createdDirPath: ""
|
2022-11-23 15:47:34 +02:00
|
|
|
readonly property int __maxPath: 260
|
2022-11-23 11:49:45 +02:00
|
|
|
|
|
|
|
|
HelperWidgets.RegExpValidator {
|
|
|
|
|
id: folderNameValidator
|
|
|
|
|
regExp: /^(\w[^*/><?\\|:]*)$/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ErrorDialog {
|
|
|
|
|
id: creationFailedDialog
|
|
|
|
|
title: qsTr("Could not create folder")
|
|
|
|
|
message: qsTr("An error occurred while trying to create the folder.")
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-07 19:49:52 +03:00
|
|
|
contentItem: Column {
|
|
|
|
|
spacing: 2
|
|
|
|
|
|
|
|
|
|
Row {
|
|
|
|
|
Text {
|
|
|
|
|
text: qsTr("Folder name: ")
|
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
|
color: StudioTheme.Values.themeTextColor
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StudioControls.TextField {
|
|
|
|
|
id: folderName
|
|
|
|
|
|
|
|
|
|
actionIndicator.visible: false
|
|
|
|
|
translationIndicator.visible: false
|
|
|
|
|
validator: folderNameValidator
|
|
|
|
|
|
|
|
|
|
Keys.onEnterPressed: btnCreate.onClicked()
|
|
|
|
|
Keys.onReturnPressed: btnCreate.onClicked()
|
2023-02-09 18:42:51 +02:00
|
|
|
Keys.onEscapePressed: root.reject()
|
2022-11-23 11:49:45 +02:00
|
|
|
|
|
|
|
|
onTextChanged: {
|
|
|
|
|
root.createdDirPath = root.dirPath + '/' + folderName.text
|
|
|
|
|
}
|
2022-10-07 19:49:52 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Text {
|
|
|
|
|
text: qsTr("Folder name cannot be empty.")
|
|
|
|
|
color: "#ff0000"
|
|
|
|
|
anchors.right: parent.right
|
|
|
|
|
visible: folderName.text === ""
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-23 11:49:45 +02:00
|
|
|
Text {
|
|
|
|
|
text: qsTr("Folder path is too long.")
|
|
|
|
|
color: "#ff0000"
|
|
|
|
|
anchors.right: parent.right
|
2022-11-23 15:47:34 +02:00
|
|
|
visible: root.createdDirPath.length > root.__maxPath
|
2022-11-23 11:49:45 +02:00
|
|
|
}
|
|
|
|
|
|
2022-10-07 19:49:52 +03:00
|
|
|
Item { // spacer
|
|
|
|
|
width: 1
|
|
|
|
|
height: 20
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Row {
|
|
|
|
|
anchors.right: parent.right
|
|
|
|
|
|
2022-11-23 11:49:45 +02:00
|
|
|
HelperWidgets.Button {
|
2022-10-07 19:49:52 +03:00
|
|
|
id: btnCreate
|
|
|
|
|
|
|
|
|
|
text: qsTr("Create")
|
2022-11-23 15:47:34 +02:00
|
|
|
enabled: folderName.text !== "" && root.createdDirPath.length <= root.__maxPath
|
2022-10-07 19:49:52 +03:00
|
|
|
onClicked: {
|
2022-11-23 11:49:45 +02:00
|
|
|
root.createdDirPath = root.dirPath + '/' + folderName.text
|
2023-03-07 16:51:02 +01:00
|
|
|
if (AssetsLibraryBackend.assetsModel.addNewFolder(root.createdDirPath))
|
2022-11-23 11:49:45 +02:00
|
|
|
root.accept()
|
|
|
|
|
else
|
|
|
|
|
creationFailedDialog.open()
|
2022-10-07 19:49:52 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-23 11:49:45 +02:00
|
|
|
HelperWidgets.Button {
|
2022-10-07 19:49:52 +03:00
|
|
|
text: qsTr("Cancel")
|
2022-11-23 11:49:45 +02:00
|
|
|
onClicked: root.reject()
|
2022-10-07 19:49:52 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onOpened: {
|
|
|
|
|
folderName.text = qsTr("New folder")
|
|
|
|
|
folderName.selectAll()
|
|
|
|
|
folderName.forceActiveFocus()
|
|
|
|
|
}
|
2022-11-23 11:49:45 +02:00
|
|
|
|
|
|
|
|
onRejected: {
|
|
|
|
|
root.createdDirPath = ""
|
|
|
|
|
}
|
2022-10-07 19:49:52 +03:00
|
|
|
}
|