forked from qt-creator/qt-creator
QmlDesigner: Implement renaming assets folders
Fixes: QDS-6123 Change-Id: I1923f78fe2a6739f1cf32fd86c0919965190d8ca Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io> Reviewed-by: Samuel Ghinet <samuel.ghinet@qt.io> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -90,6 +90,103 @@ Item {
|
|||||||
selectedAssetsChanged()
|
selectedAssetsChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RegExpValidator {
|
||||||
|
id: folderNameValidator
|
||||||
|
regExp: /^(\w[^*/><?\\|:]*)$/
|
||||||
|
}
|
||||||
|
|
||||||
|
Dialog {
|
||||||
|
id: renameFolderDialog
|
||||||
|
|
||||||
|
title: qsTr("Rename folder")
|
||||||
|
anchors.centerIn: parent
|
||||||
|
closePolicy: Popup.CloseOnEscape
|
||||||
|
implicitWidth: 280
|
||||||
|
modal: true
|
||||||
|
|
||||||
|
property bool renameError: false
|
||||||
|
|
||||||
|
contentItem: Column {
|
||||||
|
spacing: 2
|
||||||
|
|
||||||
|
StudioControls.TextField {
|
||||||
|
id: folderRename
|
||||||
|
|
||||||
|
actionIndicator.visible: false
|
||||||
|
translationIndicator.visible: false
|
||||||
|
width: renameFolderDialog.width - 12
|
||||||
|
validator: folderNameValidator
|
||||||
|
|
||||||
|
onEditChanged: renameFolderDialog.renameError = false
|
||||||
|
Keys.onEnterPressed: btnRename.onClicked()
|
||||||
|
Keys.onReturnPressed: btnRename.onClicked()
|
||||||
|
}
|
||||||
|
|
||||||
|
Text {
|
||||||
|
text: qsTr("Folder Name cannot be empty.")
|
||||||
|
color: "#ff0000"
|
||||||
|
visible: folderRename.text === "" && !renameFolderDialog.renameError
|
||||||
|
}
|
||||||
|
|
||||||
|
Text {
|
||||||
|
text: qsTr("Could not rename directory. Make sure no folder with the same name exists.")
|
||||||
|
wrapMode: Text.WordWrap
|
||||||
|
width: renameFolderDialog.width
|
||||||
|
color: "#ff0000"
|
||||||
|
visible: renameFolderDialog.renameError
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
width: renameFolderDialog.width
|
||||||
|
leftPadding: 10
|
||||||
|
rightPadding: 10
|
||||||
|
}
|
||||||
|
|
||||||
|
Item { // spacer
|
||||||
|
width: 1
|
||||||
|
height: 20
|
||||||
|
}
|
||||||
|
|
||||||
|
Row {
|
||||||
|
anchors.right: parent.right
|
||||||
|
|
||||||
|
Button {
|
||||||
|
id: btnRename
|
||||||
|
|
||||||
|
text: qsTr("Rename")
|
||||||
|
enabled: folderRename.text !== ""
|
||||||
|
onClicked: {
|
||||||
|
var success = assetsModel.renameFolder(contextDir.dirPath, folderRename.text)
|
||||||
|
if (success)
|
||||||
|
renameFolderDialog.accept()
|
||||||
|
|
||||||
|
renameFolderDialog.renameError = !success
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Button {
|
||||||
|
text: qsTr("Cancel")
|
||||||
|
onClicked: renameFolderDialog.reject()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onOpened: {
|
||||||
|
folderRename.text = contextDir.dirName
|
||||||
|
folderRename.selectAll()
|
||||||
|
folderRename.forceActiveFocus()
|
||||||
|
renameFolderDialog.renameError = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Dialog {
|
Dialog {
|
||||||
id: newFolderDialog
|
id: newFolderDialog
|
||||||
|
|
||||||
@@ -113,6 +210,7 @@ Item {
|
|||||||
|
|
||||||
actionIndicator.visible: false
|
actionIndicator.visible: false
|
||||||
translationIndicator.visible: false
|
translationIndicator.visible: false
|
||||||
|
validator: folderNameValidator
|
||||||
|
|
||||||
Keys.onEnterPressed: btnCreate.onClicked()
|
Keys.onEnterPressed: btnCreate.onClicked()
|
||||||
Keys.onReturnPressed: btnCreate.onClicked()
|
Keys.onReturnPressed: btnCreate.onClicked()
|
||||||
@@ -261,6 +359,13 @@ Item {
|
|||||||
height: visible ? StudioTheme.Values.border : 0
|
height: visible ? StudioTheme.Values.border : 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StudioControls.MenuItem {
|
||||||
|
text: qsTr("Rename Folder")
|
||||||
|
visible: isDirContextMenu
|
||||||
|
height: visible ? implicitHeight : 0
|
||||||
|
onTriggered: renameFolderDialog.open()
|
||||||
|
}
|
||||||
|
|
||||||
StudioControls.MenuItem {
|
StudioControls.MenuItem {
|
||||||
text: qsTr("New Folder")
|
text: qsTr("New Folder")
|
||||||
onTriggered: newFolderDialog.open()
|
onTriggered: newFolderDialog.open()
|
||||||
|
@@ -135,6 +135,18 @@ void ItemLibraryAssetsModel::deleteFile(const QString &filePath)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ItemLibraryAssetsModel::renameFolder(const QString &folderPath, const QString &newName)
|
||||||
|
{
|
||||||
|
QDir dir{folderPath};
|
||||||
|
QString oldName = dir.dirName();
|
||||||
|
|
||||||
|
if (oldName == newName)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
dir.cdUp();
|
||||||
|
return dir.rename(oldName, newName);
|
||||||
|
}
|
||||||
|
|
||||||
void ItemLibraryAssetsModel::addNewFolder(const QString &folderPath)
|
void ItemLibraryAssetsModel::addNewFolder(const QString &folderPath)
|
||||||
{
|
{
|
||||||
QString iterPath = folderPath;
|
QString iterPath = folderPath;
|
||||||
|
@@ -84,6 +84,7 @@ public:
|
|||||||
Q_INVOKABLE void toggleExpandAll(bool expand);
|
Q_INVOKABLE void toggleExpandAll(bool expand);
|
||||||
Q_INVOKABLE DirExpandState getAllExpandedState() const;
|
Q_INVOKABLE DirExpandState getAllExpandedState() const;
|
||||||
Q_INVOKABLE void deleteFile(const QString &filePath);
|
Q_INVOKABLE void deleteFile(const QString &filePath);
|
||||||
|
Q_INVOKABLE bool renameFolder(const QString &folderPath, const QString &newName);
|
||||||
Q_INVOKABLE void addNewFolder(const QString &folderPath);
|
Q_INVOKABLE void addNewFolder(const QString &folderPath);
|
||||||
Q_INVOKABLE void deleteFolder(const QString &folderPath);
|
Q_INVOKABLE void deleteFolder(const QString &folderPath);
|
||||||
Q_INVOKABLE QObject *rootDir() const;
|
Q_INVOKABLE QObject *rootDir() const;
|
||||||
|
Reference in New Issue
Block a user