forked from qt-creator/qt-creator
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:
committed by
Christian Kandeler
parent
90ad2797eb
commit
63e4180242
@@ -276,7 +276,8 @@ bool QbsGroupNode::addFiles(const QStringList &filePaths, QStringList *notAdded)
|
||||
m_qbsGroupData, notAdded);
|
||||
}
|
||||
|
||||
bool QbsGroupNode::removeFiles(const QStringList &filePaths, QStringList *notRemoved)
|
||||
RemovedFilesFromProject QbsGroupNode::removeFiles(const QStringList &filePaths,
|
||||
QStringList *notRemoved)
|
||||
{
|
||||
QStringList notRemovedDummy;
|
||||
if (!notRemoved)
|
||||
@@ -285,13 +286,13 @@ bool QbsGroupNode::removeFiles(const QStringList &filePaths, QStringList *notRem
|
||||
const QbsProjectNode *prjNode = parentQbsProjectNode(this);
|
||||
if (!prjNode || !prjNode->qbsProject().isValid()) {
|
||||
*notRemoved += filePaths;
|
||||
return false;
|
||||
return RemovedFilesFromProject::Error;
|
||||
}
|
||||
|
||||
const QbsProductNode *prdNode = parentQbsProductNode(this);
|
||||
if (!prdNode || !prdNode->qbsProductData().isValid()) {
|
||||
*notRemoved += filePaths;
|
||||
return false;
|
||||
return RemovedFilesFromProject::Error;
|
||||
}
|
||||
|
||||
return prjNode->project()->removeFilesFromProduct(filePaths, prdNode->qbsProductData(),
|
||||
@@ -361,7 +362,8 @@ bool QbsProductNode::addFiles(const QStringList &filePaths, QStringList *notAdde
|
||||
QTC_ASSERT(false, return false);
|
||||
}
|
||||
|
||||
bool QbsProductNode::removeFiles(const QStringList &filePaths, QStringList *notRemoved)
|
||||
RemovedFilesFromProject QbsProductNode::removeFiles(const QStringList &filePaths,
|
||||
QStringList *notRemoved)
|
||||
{
|
||||
QStringList notRemovedDummy;
|
||||
if (!notRemoved)
|
||||
@@ -370,7 +372,7 @@ bool QbsProductNode::removeFiles(const QStringList &filePaths, QStringList *notR
|
||||
const QbsProjectNode *prjNode = parentQbsProjectNode(this);
|
||||
if (!prjNode || !prjNode->qbsProject().isValid()) {
|
||||
*notRemoved += filePaths;
|
||||
return false;
|
||||
return RemovedFilesFromProject::Error;
|
||||
}
|
||||
|
||||
qbs::GroupData grp = findMainQbsGroup(m_qbsProductData);
|
||||
@@ -379,7 +381,7 @@ bool QbsProductNode::removeFiles(const QStringList &filePaths, QStringList *notR
|
||||
notRemoved);
|
||||
}
|
||||
|
||||
QTC_ASSERT(false, return false);
|
||||
QTC_ASSERT(false, return RemovedFilesFromProject::Error);
|
||||
}
|
||||
|
||||
bool QbsProductNode::renameFile(const QString &filePath, const QString &newFilePath)
|
||||
|
||||
@@ -47,7 +47,8 @@ public:
|
||||
bool showInSimpleTree() const final { return false; }
|
||||
bool supportsAction(ProjectExplorer::ProjectAction action, const Node *node) const final;
|
||||
bool addFiles(const QStringList &filePaths, QStringList *notAdded = nullptr) override;
|
||||
bool removeFiles(const QStringList &filePaths, QStringList *notRemoved = nullptr) override;
|
||||
ProjectExplorer::RemovedFilesFromProject removeFiles(const QStringList &filePaths,
|
||||
QStringList *notRemoved = nullptr) override;
|
||||
bool renameFile(const QString &filePath, const QString &newFilePath) override;
|
||||
|
||||
private:
|
||||
@@ -68,7 +69,8 @@ public:
|
||||
|
||||
bool supportsAction(ProjectExplorer::ProjectAction action, const Node *node) const final;
|
||||
bool addFiles(const QStringList &filePaths, QStringList *notAdded = nullptr) override;
|
||||
bool removeFiles(const QStringList &filePaths, QStringList *notRemoved = nullptr) override;
|
||||
ProjectExplorer::RemovedFilesFromProject removeFiles(const QStringList &filePaths,
|
||||
QStringList *notRemoved = nullptr) override;
|
||||
bool renameFile(const QString &filePath, const QString &newFilePath) override;
|
||||
void build() override;
|
||||
QStringList targetApplications() const override;
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -67,8 +67,8 @@ public:
|
||||
// for shared data.
|
||||
bool addFilesToProduct(const QStringList &filePaths, const qbs::ProductData productData,
|
||||
const qbs::GroupData groupData, QStringList *notAdded);
|
||||
bool removeFilesFromProduct(const QStringList &filePaths,
|
||||
const qbs::ProductData productData, const qbs::GroupData groupData,
|
||||
ProjectExplorer::RemovedFilesFromProject removeFilesFromProduct(const QStringList &filePaths,
|
||||
const qbs::ProductData &productData, const qbs::GroupData &groupData,
|
||||
QStringList *notRemoved);
|
||||
bool renameFileInProduct(const QString &oldPath,
|
||||
const QString &newPath, const qbs::ProductData productData,
|
||||
|
||||
Reference in New Issue
Block a user