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
|
|
|
|
2023-03-30 23:57:59 +03:00
|
|
|
StudioControls.Dialog {
|
2022-11-23 11:49:45 +02:00
|
|
|
id: root
|
2022-10-07 19:49:52 +03:00
|
|
|
|
|
|
|
|
title: qsTr("Rename Folder")
|
|
|
|
|
anchors.centerIn: parent
|
|
|
|
|
closePolicy: Popup.CloseOnEscape
|
|
|
|
|
implicitWidth: 280
|
|
|
|
|
modal: true
|
|
|
|
|
|
|
|
|
|
property bool renameError: false
|
2023-01-26 23:40:01 +02:00
|
|
|
property string renamedDirPath: ""
|
2022-11-23 11:49:45 +02:00
|
|
|
required property string dirPath
|
|
|
|
|
required property string dirName
|
|
|
|
|
|
|
|
|
|
HelperWidgets.RegExpValidator {
|
|
|
|
|
id: folderNameValidator
|
|
|
|
|
regExp: /^(\w[^*/><?\\|:]*)$/
|
|
|
|
|
}
|
2022-10-07 19:49:52 +03:00
|
|
|
|
|
|
|
|
contentItem: Column {
|
|
|
|
|
spacing: 2
|
|
|
|
|
|
|
|
|
|
StudioControls.TextField {
|
|
|
|
|
id: folderRename
|
|
|
|
|
|
|
|
|
|
actionIndicator.visible: false
|
|
|
|
|
translationIndicator.visible: false
|
2022-11-23 11:49:45 +02:00
|
|
|
width: root.width - 12
|
2022-10-07 19:49:52 +03:00
|
|
|
validator: folderNameValidator
|
|
|
|
|
|
2022-11-23 11:49:45 +02:00
|
|
|
onEditChanged: root.renameError = false
|
2022-10-07 19:49:52 +03:00
|
|
|
Keys.onEnterPressed: btnRename.onClicked()
|
|
|
|
|
Keys.onReturnPressed: btnRename.onClicked()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Text {
|
|
|
|
|
text: qsTr("Folder name cannot be empty.")
|
|
|
|
|
color: "#ff0000"
|
2022-11-23 11:49:45 +02:00
|
|
|
visible: folderRename.text === "" && !root.renameError
|
2022-10-07 19:49:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Text {
|
|
|
|
|
text: qsTr("Could not rename folder. Make sure no folder with the same name exists.")
|
|
|
|
|
wrapMode: Text.WordWrap
|
2022-11-23 11:49:45 +02:00
|
|
|
width: root.width - 12
|
2022-10-07 19:49:52 +03:00
|
|
|
color: "#ff0000"
|
2022-11-23 11:49:45 +02:00
|
|
|
visible: root.renameError
|
2022-10-07 19:49:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Item { // spacer
|
|
|
|
|
width: 1
|
|
|
|
|
height: 10
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Text {
|
|
|
|
|
text: qsTr("If the folder has assets in use, renaming it might cause the project to not work correctly.")
|
|
|
|
|
color: StudioTheme.Values.themeTextColor
|
|
|
|
|
wrapMode: Text.WordWrap
|
2022-11-23 11:49:45 +02:00
|
|
|
width: root.width
|
2022-10-07 19:49:52 +03:00
|
|
|
leftPadding: 10
|
|
|
|
|
rightPadding: 10
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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: btnRename
|
|
|
|
|
|
|
|
|
|
text: qsTr("Rename")
|
|
|
|
|
enabled: folderRename.text !== ""
|
|
|
|
|
onClicked: {
|
2023-03-07 16:51:02 +01:00
|
|
|
var success = AssetsLibraryBackend.assetsModel.renameFolder(root.dirPath, folderRename.text)
|
2023-01-26 23:40:01 +02:00
|
|
|
if (success) {
|
|
|
|
|
root.renamedDirPath = root.dirPath.replace(/(.*\/)[^/]+$/, "$1" + folderRename.text)
|
2022-11-23 11:49:45 +02:00
|
|
|
root.accept()
|
2023-01-26 23:40:01 +02:00
|
|
|
}
|
2022-10-07 19:49:52 +03:00
|
|
|
|
2022-11-23 11:49:45 +02:00
|
|
|
root.renameError = !success
|
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: {
|
2022-11-23 11:49:45 +02:00
|
|
|
folderRename.text = root.dirName
|
2022-10-07 19:49:52 +03:00
|
|
|
folderRename.selectAll()
|
|
|
|
|
folderRename.forceActiveFocus()
|
2022-11-23 11:49:45 +02:00
|
|
|
root.renameError = false
|
2022-10-07 19:49:52 +03:00
|
|
|
}
|
2023-01-26 23:40:01 +02:00
|
|
|
|
|
|
|
|
onRejected: {
|
|
|
|
|
root.renamedDirPath = ""
|
|
|
|
|
}
|
2022-10-07 19:49:52 +03:00
|
|
|
}
|