QmlDesigner: Provide feedback on folder move failure

Fixes: QDS-13785
Change-Id: I014066a4dfad9979a54b8b7b0c544f9f37ec340d
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
This commit is contained in:
Shrief Gabr
2024-10-11 07:36:18 +03:00
parent 5d331cd965
commit 5a19f357a0
2 changed files with 16 additions and 11 deletions

View File

@@ -202,7 +202,7 @@ bool AssetsLibraryModel::isSameOrDescendantPath(const QUrl &source, const QStrin
Utils::FilePath srcPath = Utils::FilePath::fromUrl(source);
Utils::FilePath targetPath = Utils::FilePath::fromString(target);
return targetPath.isChildOf(srcPath);
return srcPath == targetPath || targetPath.isChildOf(srcPath);
}
bool AssetsLibraryModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const

View File

@@ -391,11 +391,11 @@ void AssetsLibraryWidget::handleAssetsDrop(const QList<QUrl> &urls, const QStrin
if (destDir.isFile())
destDir = destDir.parentDir();
QMessageBox mb;
mb.setInformativeText("What would you like to do with the existing asset?");
mb.addButton("Keep Both", QMessageBox::AcceptRole);
mb.addButton("Replace", QMessageBox::ResetRole);
mb.addButton("Cancel", QMessageBox::RejectRole);
QMessageBox msgBox;
msgBox.setInformativeText("What would you like to do with the existing asset?");
msgBox.addButton("Keep Both", QMessageBox::AcceptRole);
msgBox.addButton("Replace", QMessageBox::ResetRole);
msgBox.addButton("Cancel", QMessageBox::RejectRole);
for (const QUrl &url : urls) {
Utils::FilePath src = Utils::FilePath::fromUrl(url);
@@ -405,9 +405,9 @@ void AssetsLibraryWidget::handleAssetsDrop(const QList<QUrl> &urls, const QStrin
continue;
if (dest.exists()) {
mb.setText("An asset named " + dest.fileName() + " already exists.");
mb.exec();
int userAction = mb.buttonRole(mb.clickedButton());
msgBox.setText("An asset named " + dest.fileName() + " already exists.");
msgBox.exec();
int userAction = msgBox.buttonRole(msgBox.clickedButton());
if (userAction == QMessageBox::AcceptRole) { // "Keep Both"
dest = Utils::FilePath::fromString(UniqueName::generatePath(dest.toString()));
@@ -421,8 +421,13 @@ void AssetsLibraryWidget::handleAssetsDrop(const QList<QUrl> &urls, const QStrin
}
}
if (!src.renameFile(dest))
qWarning() << __FUNCTION__ << "Failed to move asset from" << src << "to" << dest;
if (!src.renameFile(dest) && src.isDir()) {
QMessageBox errBox;
QString message = QString("Failed to move folder \"%1\".\nThe folder might contain subfolders or one of its files is in use.")
.arg(src.fileName());
errBox.setInformativeText(message);
errBox.exec();
}
}
if (m_assetsView->model())