ProjectExplorer: Add special handling for removing files

... from a project which are pulled in via wildcards.
Such files cannot be removed from a project file, because they are
not listed verbatim. This kind of failure should not be reported to the
user if the file is also deleted, as the file list will have the correct
state after the next reparse.

Fixes: QTCREATORBUG-22586
Done-with: Christian Kandeler <christian.kandeler@qt.io>
Change-Id: I3dc66fe9a6594be7d0b86f46d830cd099ee49fd7
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Ville Nummela
2019-06-18 14:39:38 +03:00
committed by Christian Kandeler
parent 90ad2797eb
commit 63e4180242
20 changed files with 138 additions and 59 deletions

View File

@@ -296,31 +296,50 @@ bool QbsProject::addFilesToProduct(const QStringList &filePaths,
return notAdded->isEmpty();
}
bool QbsProject::removeFilesFromProduct(const QStringList &filePaths,
const qbs::ProductData productData,
const qbs::GroupData groupData,
QStringList *notRemoved)
RemovedFilesFromProject QbsProject::removeFilesFromProduct(const QStringList &filePaths,
const qbs::ProductData &productData,
const qbs::GroupData &groupData,
QStringList *notRemoved)
{
QTC_ASSERT(m_qbsProject.isValid(), return false);
QStringList allPaths = groupData.allFilePaths();
QTC_ASSERT(m_qbsProject.isValid(), return RemovedFilesFromProject::Error);
const QList<qbs::ArtifactData> allWildcardsInGroup = groupData.sourceArtifactsFromWildcards();
QStringList wildcardFiles;
QStringList nonWildcardFiles;
for (const QString &filePath : filePaths) {
if (contains(allWildcardsInGroup, [filePath](const qbs::ArtifactData &artifact) {
return artifact.filePath() == filePath; })) {
wildcardFiles << filePath;
} else {
nonWildcardFiles << filePath;
}
}
const QString productFilePath = productData.location().filePath();
ChangeExpector expector(productFilePath, m_qbsDocuments);
ensureWriteableQbsFile(productFilePath);
foreach (const QString &path, filePaths) {
qbs::ErrorInfo err
= m_qbsProject.removeFiles(productData, groupData, QStringList() << path);
for (const QString &path : qAsConst(nonWildcardFiles)) {
const qbs::ErrorInfo err = m_qbsProject.removeFiles(productData, groupData, {path});
if (err.hasError()) {
MessageManager::write(err.toString());
*notRemoved += path;
} else {
allPaths.removeOne(path);
}
}
if (notRemoved->count() != filePaths.count()) {
m_projectData = m_qbsProject.projectData();
delayedUpdateAfterParse();
}
return notRemoved->isEmpty();
const bool success = notRemoved->isEmpty();
if (!wildcardFiles.isEmpty()) {
*notRemoved += wildcardFiles;
delayParsing();
}
if (!success)
return RemovedFilesFromProject::Error;
if (!wildcardFiles.isEmpty())
return RemovedFilesFromProject::Wildcard;
return RemovedFilesFromProject::Ok;
}
bool QbsProject::renameFileInProduct(const QString &oldPath, const QString &newPath,
@@ -330,8 +349,10 @@ bool QbsProject::renameFileInProduct(const QString &oldPath, const QString &newP
if (newPath.isEmpty())
return false;
QStringList dummy;
if (!removeFilesFromProduct(QStringList(oldPath), productData, groupData, &dummy))
if (removeFilesFromProduct(QStringList(oldPath), productData, groupData, &dummy)
!= RemovedFilesFromProject::Ok) {
return false;
}
qbs::ProductData newProductData;
foreach (const qbs::ProductData &p, m_projectData.allProducts()) {
if (uniqueProductName(p) == uniqueProductName(productData)) {