Commit e50b75eb authored by Christian Kandeler's avatar Christian Kandeler

QbsProjectManager: Support UI-based file renaming.

Task-number: QBS-652
Change-Id: Iaaf767871b1f546814acec62330e2c8d732b8d75
Reviewed-by: default avatarJoerg Bornemann <joerg.bornemann@digia.com>
parent d87f3d53
......@@ -336,6 +336,7 @@ static QList<ProjectExplorer::ProjectAction> supportedNodeActions(ProjectExplore
if (node->nodeType() == ProjectExplorer::FileNodeType
&& !project->qbsProject().buildSystemFiles().contains(node->path())) {
actions << ProjectExplorer::RemoveFile;
actions << ProjectExplorer::Rename;
}
return actions;
}
......@@ -417,6 +418,19 @@ bool QbsGroupNode::removeFiles(const QStringList &filePaths, QStringList *notRem
m_qbsGroupData, notRemoved);
}
bool QbsGroupNode::renameFile(const QString &filePath, const QString &newFilePath)
{
QbsProjectNode * const prjNode = parentQbsProjectNode(this);
if (!prjNode || !prjNode->qbsProject().isValid())
return false;
QbsProductNode * const prdNode = parentQbsProductNode(this);
if (!prdNode || !prdNode->qbsProductData().isValid())
return false;
return prjNode->project()->renameFileInProduct(this, filePath, newFilePath,
prdNode->qbsProductData(), m_qbsGroupData);
}
void QbsGroupNode::updateQbsGroupData(const qbs::GroupData &grp, const QString &productPath,
bool productWasEnabled, bool productIsEnabled)
{
......@@ -623,6 +637,17 @@ bool QbsProductNode::removeFiles(const QStringList &filePaths, QStringList *notR
QTC_ASSERT(false, return false);
}
bool QbsProductNode::renameFile(const QString &filePath, const QString &newFilePath)
{
QbsProjectNode * const prjNode = parentQbsProjectNode(this);
if (!prjNode || !prjNode->qbsProject().isValid())
return false;
const qbs::GroupData grp = findMainQbsGroup(m_qbsProductData);
QTC_ASSERT(grp.isValid(), return false);
return prjNode->project()->renameFileInProduct(this, filePath, newFilePath, m_qbsProductData,
grp);
}
void QbsProductNode::setQbsProductData(const qbs::Project &project, const qbs::ProductData prd)
{
if (m_qbsProductData == prd)
......
......@@ -105,6 +105,7 @@ public:
QList<ProjectExplorer::ProjectAction> supportedActions(Node *node) const;
bool addFiles(const QStringList &filePaths, QStringList *notAdded = 0);
bool removeFiles(const QStringList &filePaths, QStringList *notRemoved = 0);
bool renameFile(const QString &filePath, const QString &newFilePath);
void updateQbsGroupData(const qbs::GroupData &grp, const QString &productPath,
bool productWasEnabled, bool productIsEnabled);
......@@ -140,6 +141,7 @@ public:
QList<ProjectExplorer::ProjectAction> supportedActions(Node *node) const;
bool addFiles(const QStringList &filePaths, QStringList *notAdded = 0);
bool removeFiles(const QStringList &filePaths, QStringList *notRemoved = 0);
bool renameFile(const QString &filePath, const QString &newFilePath);
void setQbsProductData(const qbs::Project &project, const qbs::ProductData prd);
const qbs::ProductData qbsProductData() const { return m_qbsProductData; }
......
......@@ -307,6 +307,37 @@ bool QbsProject::removeFilesFromProduct(QbsBaseProjectNode *node, const QStringL
return notRemoved->isEmpty();
}
bool QbsProject::renameFileInProduct(QbsBaseProjectNode *node, const QString &oldPath,
const QString &newPath, const qbs::ProductData &productData,
const qbs::GroupData &groupData)
{
if (newPath.isEmpty())
return false;
QStringList dummy;
if (!removeFilesFromProduct(node, QStringList() << oldPath, productData, groupData, &dummy))
return false;
qbs::ProductData newProductData;
foreach (const qbs::ProductData &p, m_projectData.allProducts()) {
if (uniqueProductName(p) == uniqueProductName(productData)) {
newProductData = p;
break;
}
}
if (!newProductData.isValid())
return false;
qbs::GroupData newGroupData;
foreach (const qbs::GroupData &g, newProductData.groups()) {
if (g.name() == groupData.name()) {
newGroupData = g;
break;
}
}
if (!newGroupData.isValid())
return false;
return addFilesToProduct(node, QStringList() << newPath, newProductData, newGroupData, &dummy);
}
void QbsProject::invalidate()
{
prepareForParsing();
......
......@@ -78,6 +78,9 @@ public:
bool removeFilesFromProduct(QbsBaseProjectNode *node, const QStringList &filePaths,
const qbs::ProductData &productData, const qbs::GroupData &groupData,
QStringList *notRemoved);
bool renameFileInProduct(QbsBaseProjectNode *node, const QString &oldPath,
const QString &newPath, const qbs::ProductData &productData,
const qbs::GroupData &groupData);
qbs::BuildJob *build(const qbs::BuildOptions &opts, QStringList products = QStringList());
qbs::CleanJob *clean(const qbs::CleanOptions &opts);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment