summaryrefslogtreecommitdiff
path: root/src/plugins/qbsprojectmanager/qbsnodes.cpp
diff options
context:
space:
mode:
authorThomas Epting <thomas.epting@stryker.com>2014-06-23 17:10:15 +0200
committerTobias Hunger <tobias.hunger@digia.com>2014-06-24 11:22:20 +0200
commit513aba55a2ea69a64fb820a9c453bd87eafdf26a (patch)
tree70bccc08638fcd83d13ad38b062f0787b429e1c7 /src/plugins/qbsprojectmanager/qbsnodes.cpp
parentc297510d93cfa49e3b6d85243c019856fc11f938 (diff)
downloadqt-creator-513aba55a2ea69a64fb820a9c453bd87eafdf26a.tar.gz
QbsProjectManager: Added functionality to remove files from projects
Change-Id: I3371e14b5fbf2eaaacc833b289f945aed57cc80e Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
Diffstat (limited to 'src/plugins/qbsprojectmanager/qbsnodes.cpp')
-rw-r--r--src/plugins/qbsprojectmanager/qbsnodes.cpp121
1 files changed, 101 insertions, 20 deletions
diff --git a/src/plugins/qbsprojectmanager/qbsnodes.cpp b/src/plugins/qbsprojectmanager/qbsnodes.cpp
index 62c7d3dde6..a2acaaa472 100644
--- a/src/plugins/qbsprojectmanager/qbsnodes.cpp
+++ b/src/plugins/qbsprojectmanager/qbsnodes.cpp
@@ -108,19 +108,51 @@ static QbsProductNode *parentQbsProductNode(ProjectExplorer::Node *node)
return 0;
}
+static qbs::GroupData findMainQbsGroup(const qbs::ProductData &productData)
+{
+ foreach (const qbs::GroupData &grp, productData.groups()) {
+ if (grp.name() == productData.name() && grp.location() == productData.location())
+ return grp;
+ }
+ return qbs::GroupData();
+}
+
static bool addQbsFiles(QbsBaseProjectNode *node, const QStringList &filePaths, qbs::Project prj,
const qbs::ProductData &productData, const qbs::GroupData &groupData,
const QString &productPath, QStringList *notAdded)
{
- qbs::ErrorInfo err = prj.addFiles(productData, groupData, filePaths);
- if (!err.hasError()) {
- QbsGroupNode::setupFiles(node, groupData.allFilePaths() + filePaths, productPath, true);
- return true;
+ QStringList allPaths = groupData.allFilePaths();
+ foreach (const QString &path, filePaths) {
+ qbs::ErrorInfo err = prj.addFiles(productData, groupData, QStringList() << path);
+ if (err.hasError()) {
+ *notAdded += path;
+ } else {
+ allPaths += path;
+ }
}
- if (notAdded)
- *notAdded += filePaths;
- return false;
+ if (notAdded->count() != filePaths.count())
+ QbsGroupNode::setupFiles(node, allPaths, productPath, true);
+ return notAdded->isEmpty();
+}
+
+static bool removeQbsFiles(QbsBaseProjectNode *node, const QStringList &filePaths, qbs::Project prj,
+ const qbs::ProductData &productData, const qbs::GroupData &groupData,
+ const QString &productPath, QStringList *notRemoved)
+{
+ QStringList allPaths = groupData.allFilePaths();
+ foreach (const QString &path, filePaths) {
+ qbs::ErrorInfo err = prj.removeFiles(productData, groupData, QStringList() << path);
+ if (err.hasError()) {
+ *notRemoved += path;
+ } else {
+ allPaths.removeOne(path);
+ }
+ }
+
+ if (notRemoved->count() != filePaths.count())
+ QbsGroupNode::setupFiles(node, allPaths, productPath, true);
+ return notRemoved->isEmpty();
}
class FileTreeNode {
@@ -373,22 +405,25 @@ bool QbsGroupNode::isEnabled() const
QList<ProjectExplorer::ProjectAction> QbsGroupNode::supportedActions(ProjectExplorer::Node *node) const
{
Q_UNUSED(node);
- return QList<ProjectExplorer::ProjectAction>() << ProjectExplorer::AddNewFile << ProjectExplorer::AddExistingFile;
+ return QList<ProjectExplorer::ProjectAction>() << ProjectExplorer::AddNewFile << ProjectExplorer::AddExistingFile
+ << ProjectExplorer::RemoveFile;
}
bool QbsGroupNode::addFiles(const QStringList &filePaths, QStringList *notAdded)
{
+ QStringList notAddedDummy;
+ if (!notAdded)
+ notAdded = &notAddedDummy;
+
QbsProjectNode *prjNode = parentQbsProjectNode(this);
if (!prjNode || !prjNode->qbsProject().isValid()) {
- if (notAdded)
- *notAdded += filePaths;
+ *notAdded += filePaths;
return false;
}
QbsProductNode *prdNode = parentQbsProductNode(this);
if (!prdNode || !prdNode->qbsProductData().isValid()) {
- if (notAdded)
- *notAdded += filePaths;
+ *notAdded += filePaths;
return false;
}
@@ -396,6 +431,28 @@ bool QbsGroupNode::addFiles(const QStringList &filePaths, QStringList *notAdded)
*m_qbsGroupData, m_productPath, notAdded);
}
+bool QbsGroupNode::removeFiles(const QStringList &filePaths, QStringList *notRemoved)
+{
+ QStringList notRemovedDummy;
+ if (!notRemoved)
+ notRemoved = &notRemovedDummy;
+
+ QbsProjectNode *prjNode = parentQbsProjectNode(this);
+ if (!prjNode || !prjNode->qbsProject().isValid()) {
+ *notRemoved += filePaths;
+ return false;
+ }
+
+ QbsProductNode *prdNode = parentQbsProductNode(this);
+ if (!prdNode || !prdNode->qbsProductData().isValid()) {
+ *notRemoved += filePaths;
+ return false;
+ }
+
+ return removeQbsFiles(this, filePaths, prjNode->qbsProject(), prdNode->qbsProductData(),
+ *m_qbsGroupData, m_productPath, notRemoved);
+}
+
void QbsGroupNode::updateQbsGroupData(const qbs::GroupData *grp, const QString &productPath,
bool productWasEnabled, bool productIsEnabled)
{
@@ -556,23 +613,47 @@ bool QbsProductNode::showInSimpleTree() const
QList<ProjectExplorer::ProjectAction> QbsProductNode::supportedActions(ProjectExplorer::Node *node) const
{
Q_UNUSED(node);
- return QList<ProjectExplorer::ProjectAction>() << ProjectExplorer::AddNewFile << ProjectExplorer::AddExistingFile;
+ return QList<ProjectExplorer::ProjectAction>() << ProjectExplorer::AddNewFile << ProjectExplorer::AddExistingFile
+ << ProjectExplorer::RemoveFile;
}
bool QbsProductNode::addFiles(const QStringList &filePaths, QStringList *notAdded)
{
+ QStringList notAddedDummy;
+ if (!notAdded)
+ notAdded = &notAddedDummy;
+
QbsProjectNode *prjNode = parentQbsProjectNode(this);
if (!prjNode || !prjNode->qbsProject().isValid()) {
- if (notAdded)
- *notAdded += filePaths;
+ *notAdded += filePaths;
return false;
}
- foreach (const qbs::GroupData &grp, m_qbsProductData.groups()) {
- if (grp.name() == m_qbsProductData.name() && grp.location() == m_qbsProductData.location()) {
- const QString &productPath = QFileInfo(m_qbsProductData.location().fileName()).absolutePath();
- return addQbsFiles(this, filePaths, prjNode->qbsProject(), m_qbsProductData, grp, productPath, notAdded);
- }
+ qbs::GroupData grp = findMainQbsGroup(m_qbsProductData);
+ if (grp.isValid()) {
+ const QString &productPath = QFileInfo(m_qbsProductData.location().fileName()).absolutePath();
+ return addQbsFiles(this, filePaths, prjNode->qbsProject(), m_qbsProductData, grp, productPath, notAdded);
+ }
+
+ QTC_ASSERT(false, return false);
+}
+
+bool QbsProductNode::removeFiles(const QStringList &filePaths, QStringList *notRemoved)
+{
+ QStringList notRemovedDummy;
+ if (!notRemoved)
+ notRemoved = &notRemovedDummy;
+
+ QbsProjectNode *prjNode = parentQbsProjectNode(this);
+ if (!prjNode || !prjNode->qbsProject().isValid()) {
+ *notRemoved += filePaths;
+ return false;
+ }
+
+ qbs::GroupData grp = findMainQbsGroup(m_qbsProductData);
+ if (grp.isValid()) {
+ const QString &productPath = QFileInfo(m_qbsProductData.location().fileName()).absolutePath();
+ return removeQbsFiles(this, filePaths, prjNode->qbsProject(), m_qbsProductData, grp, productPath, notRemoved);
}
QTC_ASSERT(false, return false);