forked from qt-creator/qt-creator
QmakeProjectManager: Prevent adding files to the project a second time
We check the child nodes of the current project and only add the new file if it doesn't occur there already. Fixes: QTCREATORBUG-19546 Change-Id: Ic784a117515eb7e433ebf1d08db1708da6cf5440 Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
This commit is contained in:
@@ -171,7 +171,28 @@ bool QmakePriFileNode::removeSubProject(const QString &proFilePath)
|
||||
bool QmakePriFileNode::addFiles(const QStringList &filePaths, QStringList *notAdded)
|
||||
{
|
||||
QmakePriFile *pri = priFile();
|
||||
return pri ? pri->addFiles(filePaths, notAdded) : false;
|
||||
if (!pri)
|
||||
return false;
|
||||
QList<Node *> matchingNodes = findNodes([filePaths](const Node *n) {
|
||||
return n->nodeType() == NodeType::File && filePaths.contains(n->filePath().toString());
|
||||
});
|
||||
matchingNodes = filtered(matchingNodes, [](const Node *n) {
|
||||
for (const Node *parent = n->parentFolderNode(); parent;
|
||||
parent = parent->parentFolderNode()) {
|
||||
if (dynamic_cast<const ResourceEditor::ResourceTopLevelNode *>(parent))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
QStringList alreadyPresentFiles = transform<QStringList>(matchingNodes,
|
||||
[](const Node *n) { return n->filePath().toString(); });
|
||||
alreadyPresentFiles.removeDuplicates();
|
||||
QStringList actualFilePaths = filePaths;
|
||||
for (const QString &e : alreadyPresentFiles)
|
||||
actualFilePaths.removeOne(e);
|
||||
if (notAdded)
|
||||
*notAdded = alreadyPresentFiles;
|
||||
return pri->addFiles(actualFilePaths, notAdded);
|
||||
}
|
||||
|
||||
bool QmakePriFileNode::removeFiles(const QStringList &filePaths, QStringList *notRemoved)
|
||||
|
Reference in New Issue
Block a user