diff options
author | Miikka Heikkinen <miikka.heikkinen@qt.io> | 2024-01-22 15:26:39 +0200 |
---|---|---|
committer | Miikka Heikkinen <miikka.heikkinen@qt.io> | 2024-01-22 14:21:48 +0000 |
commit | 44f0e0819ac3c6174d06028ec82b5524f5ff0437 (patch) | |
tree | 2cf9df0ada09d3fcb80d621098dfb10bb57df099 | |
parent | 0707cca359cbe751f9f9d1ab7112d93b792c9403 (diff) |
QmlDesigner: Delete related resources if .qep file is deleted
Effect maker effects consist of .qep file under project content and
an imported module under asset_imports containing effect resources.
Now the resources module is also deleted when .qep file is deleted.
Fixes: QDS-11365
Change-Id: If3a91419970f6b26c4fc4df6d6d891b591ebedd3
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
-rw-r--r-- | src/plugins/qmldesigner/components/assetslibrary/assetslibrarymodel.cpp | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/src/plugins/qmldesigner/components/assetslibrary/assetslibrarymodel.cpp b/src/plugins/qmldesigner/components/assetslibrary/assetslibrarymodel.cpp index 1d6fc0dd77..1033341d34 100644 --- a/src/plugins/qmldesigner/components/assetslibrary/assetslibrarymodel.cpp +++ b/src/plugins/qmldesigner/components/assetslibrary/assetslibrarymodel.cpp @@ -115,10 +115,34 @@ void AssetsLibraryModel::deleteFiles(const QStringList &filePaths, bool dontAskA QmlDesignerPlugin::settings().insert(DesignerSettingsKey::ASK_BEFORE_DELETING_ASSET, false); for (const QString &filePath : filePaths) { - if (QFileInfo::exists(filePath) && !QFile::remove(filePath)) { - QMessageBox::warning(Core::ICore::dialogParent(), - tr("Failed to Delete File"), - tr("Could not delete \"%1\".").arg(filePath)); + QFileInfo fi(filePath); + if (fi.exists()) { + if (QFile::remove(filePath)) { + if (Asset(filePath).isEffect()) { + // If effect maker effect was removed, also remove effect module from project + QString effectName = fi.baseName(); + if (!effectName.isEmpty()) { + Utils::FilePath eDir = ModelNodeOperations::getEffectsImportDirectory(); + eDir = eDir.pathAppended(effectName); + // The size check is to weed out cases where project path somehow resolves + // to just slash. Shortest legal currentProjectDirPath() would be "/a/". + if (currentProjectDirPath().size() > 2 && eDir.exists() + && eDir.toString().startsWith(currentProjectDirPath())) { + QString error; + eDir.removeRecursively(&error); + if (!error.isEmpty()) { + QMessageBox::warning(Core::ICore::dialogParent(), + tr("Failed to Delete Effect Resources"), + tr("Could not delete \"%1\".").arg(eDir.toString())); + } + } + } + } + } else { + QMessageBox::warning(Core::ICore::dialogParent(), + tr("Failed to Delete File"), + tr("Could not delete \"%1\".").arg(filePath)); + } } } } |