Qbs, Qmake, Python, Generic: Introduce BuildSystem derived classes

... and move context menu action handling there.

This is a temporary measure to be able to move that functionality
alongside the actual BuildSystem to the BuildConfiguration.

There is a lot to be cleaned up left, to keep the patch small.

Change-Id: If4b0820a13b376fc97b70785052924972ce22705
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2019-10-22 14:55:51 +02:00
parent e1baae2e20
commit 66c7d75dbd
24 changed files with 707 additions and 544 deletions
@@ -55,6 +55,13 @@ protected:
bool validateParsingContext(const ParsingContext &ctx) final;
void parseProject(ParsingContext &&ctx) final;
bool supportsAction(ProjectExplorer::Node *context,
ProjectExplorer::ProjectAction action,
const ProjectExplorer::Node *node) const override;
bool addFiles(ProjectExplorer::Node *context,
const QStringList &filePaths, QStringList *) final;
private:
// Treescanner states:
void handleTreeScanningFinished();
@@ -138,11 +138,6 @@ bool CMakeListsNode::showInSimpleTree() const
return false;
}
bool CMakeListsNode::supportsAction(ProjectExplorer::ProjectAction action, const ProjectExplorer::Node *) const
{
return action == ProjectExplorer::ProjectAction::AddNewFile;
}
Utils::optional<Utils::FilePath> CMakeListsNode::visibleAfterAddFileAction() const
{
return filePath().pathAppended("CMakeLists.txt");
@@ -161,10 +156,19 @@ QString CMakeProjectNode::tooltip() const
return QString();
}
bool CMakeProjectNode::addFiles(const QStringList &filePaths, QStringList *)
bool CMakeBuildSystem::addFiles(Node *context, const QStringList &filePaths, QStringList *notAdded)
{
noAutoAdditionNotify(filePaths, this);
if (auto n = dynamic_cast<CMakeProjectNode *>(context)) {
noAutoAdditionNotify(filePaths, n);
return true; // Return always true as autoadd is not supported!
}
if (auto n = dynamic_cast<CMakeTargetNode *>(context)) {
noAutoAdditionNotify(filePaths, n);
return true; // Return always true as autoadd is not supported!
}
return BuildSystem::addFiles(context, filePaths, notAdded);
}
CMakeTargetNode::CMakeTargetNode(const Utils::FilePath &directory, const QString &target) :
@@ -243,16 +247,15 @@ void CMakeTargetNode::setConfig(const CMakeConfig &config)
m_config = config;
}
bool CMakeTargetNode::supportsAction(ProjectExplorer::ProjectAction action,
const ProjectExplorer::Node *) const
bool CMakeBuildSystem::supportsAction(Node *context, ProjectAction action, const Node *node) const
{
return action == ProjectExplorer::ProjectAction::AddNewFile;
}
if (dynamic_cast<CMakeTargetNode *>(context))
return action == ProjectAction::AddNewFile;
bool CMakeTargetNode::addFiles(const QStringList &filePaths, QStringList *)
{
noAutoAdditionNotify(filePaths, this);
return true; // Return always true as autoadd is not supported!
if (dynamic_cast<CMakeListsNode *>(context))
return action == ProjectAction::AddNewFile;
return BuildSystem::supportsAction(context, action, node);
}
Utils::optional<Utils::FilePath> CMakeTargetNode::visibleAfterAddFileAction() const
@@ -44,7 +44,6 @@ public:
CMakeListsNode(const Utils::FilePath &cmakeListPath);
bool showInSimpleTree() const final;
bool supportsAction(ProjectExplorer::ProjectAction action, const Node *node) const override;
Utils::optional<Utils::FilePath> visibleAfterAddFileAction() const override;
};
@@ -54,8 +53,6 @@ public:
CMakeProjectNode(const Utils::FilePath &directory);
QString tooltip() const final;
bool addFiles(const QStringList &filePaths, QStringList *notAdded) override;
};
class CMakeTargetNode : public ProjectExplorer::ProjectNode
@@ -70,8 +67,6 @@ public:
Utils::FilePath buildDirectory() const;
void setBuildDirectory(const Utils::FilePath &directory);
bool supportsAction(ProjectExplorer::ProjectAction action, const Node *node) const override;
bool addFiles(const QStringList &filePaths, QStringList *notAdded) override;
Utils::optional<Utils::FilePath> visibleAfterAddFileAction() const override;
void build() override;
@@ -40,6 +40,7 @@
#include <projectexplorer/abi.h>
#include <projectexplorer/buildsteplist.h>
#include <projectexplorer/buildsystem.h>
#include <projectexplorer/customexecutablerunconfiguration.h>
#include <projectexplorer/deploymentdata.h>
#include <projectexplorer/headerpath.h>
@@ -118,17 +119,14 @@ private:
//
////////////////////////////////////////////////////////////////////////////////////
class GenericProjectNode : public ProjectNode
class GenericBuildSytem : public BuildSystem
{
public:
explicit GenericProjectNode(GenericProject *project) :
ProjectNode(project->projectDirectory()),
m_project(project)
{
setDisplayName(project->projectFilePath().toFileInfo().completeBaseName());
}
explicit GenericBuildSytem(GenericProject *project)
: BuildSystem(project)
{}
bool supportsAction(ProjectAction action, const Node *) const override
bool supportsAction(Node *, ProjectAction action, const Node *) const override
{
return action == AddNewFile
|| action == AddExistingFile
@@ -137,25 +135,25 @@ public:
|| action == Rename;
}
bool addFiles(const QStringList &filePaths, QStringList * = nullptr) override
bool addFiles(Node *, const QStringList &filePaths, QStringList *) override
{
return m_project->addFiles(filePaths);
return project()->addFiles(filePaths);
}
RemovedFilesFromProject removeFiles(const QStringList &filePaths,
RemovedFilesFromProject removeFiles(Node *, const QStringList &filePaths,
QStringList * = nullptr) override
{
return m_project->removeFiles(filePaths) ? RemovedFilesFromProject::Ok
return project()->removeFiles(filePaths) ? RemovedFilesFromProject::Ok
: RemovedFilesFromProject::Error;
}
bool renameFile(const QString &filePath, const QString &newFilePath) override
bool renameFile(Node *, const QString &filePath, const QString &newFilePath) override
{
return m_project->renameFile(filePath, newFilePath);
return project()->renameFile(filePath, newFilePath);
}
private:
GenericProject *m_project = nullptr;
GenericProject *project() { return static_cast<GenericProject *>(BuildSystem::project()); }
};
@@ -178,6 +176,7 @@ GenericProject::GenericProject(const Utils::FilePath &fileName)
setId(Constants::GENERICPROJECT_ID);
setProjectLanguages(Context(ProjectExplorer::Constants::CXX_LANGUAGE_ID));
setDisplayName(fileName.toFileInfo().completeBaseName());
setBuildSystem(std::make_unique<GenericBuildSytem>(this));
QObject *projectUpdaterFactory = ExtensionSystem::PluginManager::getObjectByName(
"CppProjectUpdaterFactory");
@@ -432,7 +431,8 @@ void GenericProject::refresh(RefreshOptions options)
parseProject(options);
if (options & Files) {
auto newRoot = std::make_unique<GenericProjectNode>(this);
auto newRoot = std::make_unique<ProjectNode>(projectDirectory());
newRoot->setDisplayName(projectFilePath().toFileInfo().completeBaseName());
// find the common base directory of all source files
Utils::FilePath baseDir = findCommonSourceRoot();
+36 -28
View File
@@ -34,34 +34,6 @@
#include <QVariantMap>
#if 0
#include "nimbuildconfiguration.h"
#include "nimtoolchain.h"
#include "../nimconstants.h"
#include <coreplugin/icontext.h>
#include <coreplugin/progressmanager/progressmanager.h>
#include <coreplugin/iversioncontrol.h>
#include <coreplugin/vcsmanager.h>
#include <projectexplorer/buildconfiguration.h>
#include <projectexplorer/kit.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/projectnodes.h>
#include <projectexplorer/target.h>
#include <projectexplorer/toolchain.h>
#include <projectexplorer/kitinformation.h>
#include <texteditor/textdocument.h>
#include <utils/runextensions.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>
#include <QFileInfo>
#include <QQueue>
#endif
using namespace ProjectExplorer;
using namespace Utils;
@@ -176,4 +148,40 @@ void NimBuildSystem::updateProject()
m_currentContext = {};
}
bool NimBuildSystem::supportsAction(Node *context, ProjectAction action, const Node *node) const
{
if (node->asFileNode()) {
return action == ProjectAction::Rename
|| action == ProjectAction::RemoveFile;
}
if (node->isFolderNodeType() || node->isProjectNodeType()) {
return action == ProjectAction::AddNewFile
|| action == ProjectAction::RemoveFile
|| action == ProjectAction::AddExistingFile;
}
return BuildSystem::supportsAction(context, action, node);
}
bool NimBuildSystem::addFiles(Node *, const QStringList &filePaths, QStringList *)
{
return addFiles(filePaths);
}
RemovedFilesFromProject NimBuildSystem::removeFiles(Node *,
const QStringList &filePaths,
QStringList *)
{
return removeFiles(filePaths) ? RemovedFilesFromProject::Ok
: RemovedFilesFromProject::Error;
}
bool NimBuildSystem::deleteFiles(Node *, const QStringList &)
{
return true;
}
bool NimBuildSystem::renameFile(Node *, const QString &filePath, const QString &newFilePath)
{
return renameFile(filePath, newFilePath);
}
} // namespace Nim
+12
View File
@@ -43,6 +43,18 @@ public:
bool removeFiles(const QStringList &filePaths);
bool renameFile(const QString &filePath, const QString &newFilePath);
bool supportsAction(ProjectExplorer::Node *,
ProjectExplorer::ProjectAction action,
const ProjectExplorer::Node *node) const override;
bool addFiles(ProjectExplorer::Node *node,
const QStringList &filePaths, QStringList *) override;
ProjectExplorer::RemovedFilesFromProject removeFiles(ProjectExplorer::Node *node,
const QStringList &filePaths,
QStringList *) override;
bool deleteFiles(ProjectExplorer::Node *, const QStringList &) override;
bool renameFile(ProjectExplorer::Node *,
const QString &filePath, const QString &newFilePath) override;
void setExcludedFiles(const QStringList &list); // Keep for compatibility with Qt Creator 4.10
QStringList excludedFiles(); // Make private when no longer supporting Qt Creator 4.10
+1 -50
View File
@@ -25,59 +25,10 @@
#include "nimprojectnode.h"
#include "nimbuildsystem.h"
#include <projectexplorer/projecttree.h>
using namespace ProjectExplorer;
using namespace Utils;
namespace Nim {
NimProjectNode::NimProjectNode(const FilePath &projectFilePath)
NimProjectNode::NimProjectNode(const Utils::FilePath &projectFilePath)
: ProjectNode(projectFilePath)
{}
bool NimProjectNode::supportsAction(ProjectAction action, const Node *node) const
{
if (node->asFileNode()) {
return action == ProjectAction::Rename
|| action == ProjectAction::RemoveFile;
}
if (node->isFolderNodeType() || node->isProjectNodeType()) {
return action == ProjectAction::AddNewFile
|| action == ProjectAction::RemoveFile
|| action == ProjectAction::AddExistingFile;
}
return ProjectNode::supportsAction(action, node);
}
bool NimProjectNode::addFiles(const QStringList &filePaths, QStringList *)
{
return buildSystem()->addFiles(filePaths);
}
RemovedFilesFromProject NimProjectNode::removeFiles(const QStringList &filePaths,
QStringList *)
{
return buildSystem()->removeFiles(filePaths) ? RemovedFilesFromProject::Ok
: RemovedFilesFromProject::Error;
}
bool NimProjectNode::deleteFiles(const QStringList &)
{
return true;
}
bool NimProjectNode::renameFile(const QString &filePath, const QString &newFilePath)
{
return buildSystem()->renameFile(filePath, newFilePath);
}
NimBuildSystem *NimProjectNode::buildSystem() const
{
return qobject_cast<NimBuildSystem *>(
ProjectTree::instance()->projectForNode(this)->buildSystem());
}
} // namespace Nim
-14
View File
@@ -27,26 +27,12 @@
#include <projectexplorer/projectnodes.h>
namespace Utils { class FilePath; }
namespace Nim {
class NimBuildSystem;
class NimProjectNode : public ProjectExplorer::ProjectNode
{
public:
NimProjectNode(const Utils::FilePath &projectFilePath);
bool supportsAction(ProjectExplorer::ProjectAction action, const Node *node) const override;
bool addFiles(const QStringList &filePaths, QStringList *) override;
ProjectExplorer::RemovedFilesFromProject removeFiles(const QStringList &filePaths,
QStringList *) override;
bool deleteFiles(const QStringList &) override;
bool renameFile(const QString &filePath, const QString &newFilePath) override;
private:
NimBuildSystem *buildSystem() const;
};
}
@@ -54,6 +54,16 @@ Project *BuildSystem::project() const
return m_project;
}
FilePath BuildSystem::projectFilePath() const
{
return m_project->projectFilePath();
}
FilePath BuildSystem::projectDirectory() const
{
return m_project->projectDirectory();
}
bool BuildSystem::isWaitingForParse() const
{
return m_delayedParsingTimer.isActive();
@@ -101,4 +111,50 @@ void BuildSystem::triggerParsing()
parseProject(std::move(ctx));
}
bool BuildSystem::addFiles(Node *, const QStringList &filePaths, QStringList *notAdded)
{
Q_UNUSED(filePaths)
Q_UNUSED(notAdded)
return false;
}
RemovedFilesFromProject BuildSystem::removeFiles(Node *, const QStringList &filePaths,
QStringList *notRemoved)
{
Q_UNUSED(filePaths)
Q_UNUSED(notRemoved)
return RemovedFilesFromProject::Error;
}
bool BuildSystem::deleteFiles(Node *, const QStringList &filePaths)
{
Q_UNUSED(filePaths)
return false;
}
bool BuildSystem::canRenameFile(Node *, const QString &filePath, const QString &newFilePath)
{
Q_UNUSED(filePath)
Q_UNUSED(newFilePath)
return true;
}
bool BuildSystem::renameFile(Node *, const QString &filePath, const QString &newFilePath)
{
Q_UNUSED(filePath)
Q_UNUSED(newFilePath)
return false;
}
bool BuildSystem::addDependencies(Node *, const QStringList &dependencies)
{
Q_UNUSED(dependencies)
return false;
}
bool BuildSystem::supportsAction(Node *, ProjectAction, const Node *) const
{
return false;
}
} // namespace ProjectExplorer
+13 -1
View File
@@ -36,6 +36,7 @@ namespace ProjectExplorer {
class BuildConfiguration;
class ExtraCompiler;
class Node;
// --------------------------------------------------------------------
// BuildSystem:
@@ -51,12 +52,23 @@ public:
BuildSystem(const BuildSystem &other) = delete;
Project *project() const;
Utils::FilePath projectFilePath() const;
Utils::FilePath projectDirectory() const;
bool isWaitingForParse() const;
void requestParse();
void requestDelayedParse();
virtual bool addFiles(Node *context, const QStringList &filePaths, QStringList *notAdded = nullptr);
virtual RemovedFilesFromProject removeFiles(Node *context, const QStringList &filePaths,
QStringList *notRemoved = nullptr);
virtual bool deleteFiles(Node *context, const QStringList &filePaths);
virtual bool canRenameFile(Node *context, const QString &filePath, const QString &newFilePath);
virtual bool renameFile(Node *context, const QString &filePath, const QString &newFilePath);
virtual bool addDependencies(Node *context, const QStringList &dependencies);
virtual bool supportsAction(Node *context, ProjectAction action, const Node *node) const;
protected:
class ParsingContext
{
@@ -111,7 +123,7 @@ protected:
return true;
}
virtual void parseProject(ParsingContext &&ctx) = 0; // actual code to parse project
virtual void parseProject(ParsingContext &&) {} // actual code to parse project
private:
void requestParse(int delay); // request a (delayed!) parser run.
+22 -11
View File
@@ -25,6 +25,7 @@
#include "projectnodes.h"
#include "buildsystem.h"
#include "project.h"
#include "projectexplorerconstants.h"
#include "projecttree.h"
@@ -882,47 +883,51 @@ bool ProjectNode::removeSubProject(const QString &proFilePath)
bool ProjectNode::addFiles(const QStringList &filePaths, QStringList *notAdded)
{
Q_UNUSED(filePaths)
Q_UNUSED(notAdded)
if (BuildSystem *bs = buildSystem())
return bs->addFiles(this, filePaths, notAdded);
return false;
}
RemovedFilesFromProject ProjectNode::removeFiles(const QStringList &filePaths,
QStringList *notRemoved)
{
Q_UNUSED(filePaths)
Q_UNUSED(notRemoved)
if (BuildSystem *bs = buildSystem())
return bs->removeFiles(this, filePaths, notRemoved);
return RemovedFilesFromProject::Error;
}
bool ProjectNode::deleteFiles(const QStringList &filePaths)
{
Q_UNUSED(filePaths)
if (BuildSystem *bs = buildSystem())
return bs->deleteFiles(this, filePaths);
return false;
}
bool ProjectNode::canRenameFile(const QString &filePath, const QString &newFilePath)
{
Q_UNUSED(filePath)
Q_UNUSED(newFilePath)
if (BuildSystem *bs = buildSystem())
return bs->canRenameFile(this, filePath, newFilePath);
return true;
}
bool ProjectNode::renameFile(const QString &filePath, const QString &newFilePath)
{
Q_UNUSED(filePath)
Q_UNUSED(newFilePath)
if (BuildSystem *bs = buildSystem())
return bs->renameFile(this, filePath, newFilePath);
return false;
}
bool ProjectNode::addDependencies(const QStringList &dependencies)
{
Q_UNUSED(dependencies)
if (BuildSystem *bs = buildSystem())
return bs->addDependencies(this, dependencies);
return false;
}
bool ProjectNode::supportsAction(ProjectAction, const Node *) const
bool ProjectNode::supportsAction(ProjectAction action, const Node *node) const
{
if (BuildSystem *bs = buildSystem())
return bs->supportsAction(const_cast<ProjectNode *>(this), action, node);
return false;
}
@@ -959,6 +964,12 @@ void ProjectNode::setFallbackData(Core::Id key, const QVariant &value)
m_fallbackData.insert(key, value);
}
BuildSystem *ProjectNode::buildSystem() const
{
Project *p = getProject();
return p ? p->buildSystem() : nullptr;
}
bool FolderNode::isEmpty() const
{
return m_nodes.size() == 0;
+10 -7
View File
@@ -42,6 +42,7 @@ namespace Utils { class MimeType; }
namespace ProjectExplorer {
class BuildSystem;
class Project;
// File types common for qt projects
@@ -357,14 +358,14 @@ public:
bool isProjectNodeType() const override { return true; }
bool showInSimpleTree() const override { return true; }
bool addFiles(const QStringList &filePaths, QStringList *notAdded = nullptr) override;
bool addFiles(const QStringList &filePaths, QStringList *notAdded = nullptr) final;
RemovedFilesFromProject removeFiles(const QStringList &filePaths,
QStringList *notRemoved = nullptr) override;
bool deleteFiles(const QStringList &filePaths) override;
bool canRenameFile(const QString &filePath, const QString &newFilePath) override;
bool renameFile(const QString &filePath, const QString &newFilePath) override;
bool addDependencies(const QStringList &dependencies) override;
bool supportsAction(ProjectAction action, const Node *node) const override;
QStringList *notRemoved = nullptr) final;
bool deleteFiles(const QStringList &filePaths) final;
bool canRenameFile(const QString &filePath, const QString &newFilePath) final;
bool renameFile(const QString &filePath, const QString &newFilePath) final;
bool addDependencies(const QStringList &dependencies) final;
bool supportsAction(ProjectAction action, const Node *node) const final;
// by default returns false
virtual bool deploysFolder(const QString &folder) const;
@@ -399,6 +400,8 @@ protected:
QString m_target;
private:
BuildSystem *buildSystem() const;
QHash<Core::Id, QVariant> m_fallbackData; // Used in data(), unless overridden.
ProductType m_productType = ProductType::None;
};
+75 -56
View File
@@ -27,6 +27,7 @@
#include "pythonconstants.h"
#include <projectexplorer/buildsystem.h>
#include <projectexplorer/buildtargetinfo.h>
#include <projectexplorer/kitmanager.h>
#include <projectexplorer/projectexplorerconstants.h>
@@ -53,19 +54,34 @@ using namespace Utils;
namespace Python {
namespace Internal {
class PythonProjectNode : public ProjectNode
class PythonBuildSystem : public BuildSystem
{
public:
PythonProjectNode(PythonProject *project);
PythonBuildSystem(PythonProject *project);
bool supportsAction(ProjectAction action, const Node *node) const override;
bool addFiles(const QStringList &filePaths, QStringList *) override;
RemovedFilesFromProject removeFiles(const QStringList &filePaths, QStringList *) override;
bool deleteFiles(const QStringList &) override;
bool renameFile(const QString &filePath, const QString &newFilePath) override;
bool supportsAction(Node *context, ProjectAction action, const Node *node) const override;
bool addFiles(Node *, const QStringList &filePaths, QStringList *) override;
RemovedFilesFromProject removeFiles(Node *, const QStringList &filePaths, QStringList *) override;
bool deleteFiles(Node *, const QStringList &) override;
bool renameFile(Node *, const QString &filePath, const QString &newFilePath) override;
bool saveRawFileList(const QStringList &rawFileList);
bool saveRawList(const QStringList &rawList, const QString &fileName);
void parse();
QStringList processEntries(const QStringList &paths,
QHash<QString, QString> *map = nullptr) const;
bool writePyProjectFile(const QString &fileName, QString &content,
const QStringList &rawList, QString *errorMessage);
void refresh();
private:
PythonProject *m_project;
PythonProject *project() const;
QStringList m_rawFileList;
QStringList m_files;
QHash<QString, QString> m_rawListEntries;
};
@@ -156,6 +172,17 @@ static QStringList readLinesJson(const FilePath &projectFile, QString *errorMess
return lines;
}
class PythonProjectNode : public ProjectNode
{
public:
PythonProjectNode(const Utils::FilePath &path)
: ProjectNode(path)
{
setDisplayName(path.toFileInfo().completeBaseName());
setAddFileFilter("*.py");
}
};
PythonProject::PythonProject(const FilePath &fileName)
: Project(Constants::C_PY_MIMETYPE, fileName)
{
@@ -164,18 +191,18 @@ PythonProject::PythonProject(const FilePath &fileName)
setDisplayName(fileName.toFileInfo().completeBaseName());
setNeedsBuildConfigurations(false);
connect(this, &PythonProject::projectFileIsDirty, this, [this]() { refresh(); });
setBuildSystem(std::make_unique<PythonBuildSystem>(this));
}
void PythonProject::refresh(Target *target)
void PythonBuildSystem::refresh()
{
ParseGuard guard = guardParsingRun();
parseProject();
Project::ParseGuard guard = project()->guardParsingRun();
parse();
const QDir baseDir(projectDirectory().toString());
QList<BuildTargetInfo> appTargets;
auto newRoot = std::make_unique<PythonProjectNode>(this);
auto newRoot = std::make_unique<PythonProjectNode>(projectDirectory());
for (const QString &f : qAsConst(m_files)) {
const QString displayName = baseDir.relativeFilePath(f);
const FileType fileType = f.endsWith(".pyproject") || f.endsWith(".pyqtc") ? FileType::Project
@@ -190,24 +217,22 @@ void PythonProject::refresh(Target *target)
appTargets.append(bti);
}
}
setRootProjectNode(std::move(newRoot));
project()->setRootProjectNode(std::move(newRoot));
if (!target)
target = activeTarget();
if (target)
if (Target *target = project()->activeTarget())
target->setApplicationTargets(appTargets);
guard.markAsSuccess();
}
bool PythonProject::saveRawFileList(const QStringList &rawFileList)
bool PythonBuildSystem::saveRawFileList(const QStringList &rawFileList)
{
const bool result = saveRawList(rawFileList, projectFilePath().toString());
// refresh(PythonProject::Files);
return result;
}
bool PythonProject::saveRawList(const QStringList &rawList, const QString &fileName)
bool PythonBuildSystem::saveRawList(const QStringList &rawList, const QString &fileName)
{
FileChangeBlocker changeGuarg(fileName);
bool result = false;
@@ -238,7 +263,7 @@ bool PythonProject::saveRawList(const QStringList &rawList, const QString &fileN
return result;
}
bool PythonProject::writePyProjectFile(const QString &fileName, QString &content,
bool PythonBuildSystem::writePyProjectFile(const QString &fileName, QString &content,
const QStringList &rawList, QString *errorMessage)
{
QFile file(fileName);
@@ -265,7 +290,7 @@ bool PythonProject::writePyProjectFile(const QString &fileName, QString &content
return true;
}
bool PythonProject::addFiles(const QStringList &filePaths)
bool PythonBuildSystem::addFiles(Node *, const QStringList &filePaths, QStringList *)
{
QStringList newList = m_rawFileList;
@@ -276,7 +301,7 @@ bool PythonProject::addFiles(const QStringList &filePaths)
return saveRawFileList(newList);
}
bool PythonProject::removeFiles(const QStringList &filePaths)
RemovedFilesFromProject PythonBuildSystem::removeFiles(Node *, const QStringList &filePaths, QStringList *)
{
QStringList newList = m_rawFileList;
@@ -286,10 +311,17 @@ bool PythonProject::removeFiles(const QStringList &filePaths)
newList.removeOne(i.value());
}
return saveRawFileList(newList);
bool res = saveRawFileList(newList);
return res ? RemovedFilesFromProject::Ok : RemovedFilesFromProject::Error;
}
bool PythonProject::renameFile(const QString &filePath, const QString &newFilePath)
bool PythonBuildSystem::deleteFiles(Node *, const QStringList &)
{
return true;
}
bool PythonBuildSystem::renameFile(Node *, const QString &filePath, const QString &newFilePath)
{
QStringList newList = m_rawFileList;
@@ -305,7 +337,7 @@ bool PythonProject::renameFile(const QString &filePath, const QString &newFilePa
return saveRawFileList(newList);
}
void PythonProject::parseProject()
void PythonBuildSystem::parse()
{
m_rawListEntries.clear();
const FilePath filePath = projectFilePath();
@@ -323,6 +355,7 @@ void PythonProject::parseProject()
m_files = processEntries(m_rawFileList, &m_rawListEntries);
}
/**
* Expands environment variables in the given \a string when they are written
* like $$(VARIABLE).
@@ -349,7 +382,7 @@ static void expandEnvironmentVariables(const QProcessEnvironment &env, QString &
* The \a map variable is an optional argument that will map the returned
* absolute paths back to their original \a paths.
*/
QStringList PythonProject::processEntries(const QStringList &paths,
QStringList PythonBuildSystem::processEntries(const QStringList &paths,
QHash<QString, QString> *map) const
{
const QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
@@ -382,10 +415,11 @@ Project::RestoreResult PythonProject::fromMap(const QVariantMap &map, QString *e
{
Project::RestoreResult res = Project::fromMap(map, errorMessage);
if (res == RestoreResult::Ok) {
refresh();
if (!activeTarget())
addTargetForDefaultKit();
if (auto bs = dynamic_cast<PythonBuildSystem *>(buildSystem()))
bs->refresh();
}
return res;
@@ -393,19 +427,20 @@ Project::RestoreResult PythonProject::fromMap(const QVariantMap &map, QString *e
bool PythonProject::setupTarget(Target *t)
{
refresh(t);
return Project::setupTarget(t);
bool res = Project::setupTarget(t);
if (auto bs = dynamic_cast<PythonBuildSystem *>(buildSystem()))
QTimer::singleShot(0, bs, &PythonBuildSystem::refresh);
return res;
}
PythonProjectNode::PythonProjectNode(PythonProject *project)
: ProjectNode(project->projectDirectory())
, m_project(project)
PythonBuildSystem::PythonBuildSystem(PythonProject *project)
: BuildSystem(project)
{
setDisplayName(project->projectFilePath().toFileInfo().completeBaseName());
setAddFileFilter("*.py");
connect(project, &PythonProject::projectFileIsDirty, this, [this]() { refresh(); });
QTimer::singleShot(0, this, &PythonBuildSystem::refresh);
}
bool PythonProjectNode::supportsAction(ProjectAction action, const Node *node) const
bool PythonBuildSystem::supportsAction(Node *context, ProjectAction action, const Node *node) const
{
if (node->asFileNode()) {
return action == ProjectAction::Rename
@@ -416,28 +451,12 @@ bool PythonProjectNode::supportsAction(ProjectAction action, const Node *node) c
|| action == ProjectAction::RemoveFile
|| action == ProjectAction::AddExistingFile;
}
return ProjectNode::supportsAction(action, node);
return BuildSystem::supportsAction(context, action, node);
}
bool PythonProjectNode::addFiles(const QStringList &filePaths, QStringList *)
PythonProject *PythonBuildSystem::project() const
{
return m_project->addFiles(filePaths);
}
RemovedFilesFromProject PythonProjectNode::removeFiles(const QStringList &filePaths, QStringList *)
{
return m_project->removeFiles(filePaths) ? RemovedFilesFromProject::Ok
: RemovedFilesFromProject::Error;
}
bool PythonProjectNode::deleteFiles(const QStringList &)
{
return true;
}
bool PythonProjectNode::renameFile(const QString &filePath, const QString &newFilePath)
{
return m_project->renameFile(filePath, newFilePath);
return static_cast<PythonProject *>(BuildSystem::project());
}
} // namespace Internal
-19
View File
@@ -40,29 +40,10 @@ class PythonProject : public ProjectExplorer::Project
public:
explicit PythonProject(const Utils::FilePath &filename);
bool addFiles(const QStringList &filePaths);
bool removeFiles(const QStringList &filePaths);
bool renameFile(const QString &filePath, const QString &newFilePath);
void refresh(ProjectExplorer::Target *target = nullptr);
bool needsConfiguration() const final { return false; }
bool writePyProjectFile(const QString &fileName, QString &content,
const QStringList &rawList, QString *errorMessage);
private:
RestoreResult fromMap(const QVariantMap &map, QString *errorMessage) override;
bool setupTarget(ProjectExplorer::Target *t) override;
bool saveRawFileList(const QStringList &rawFileList);
bool saveRawList(const QStringList &rawList, const QString &fileName);
void parseProject();
QStringList processEntries(const QStringList &paths,
QHash<QString, QString> *map = nullptr) const;
QStringList m_rawFileList;
QStringList m_files;
QHash<QString, QString> m_rawListEntries;
};
} // namespace Internal
+141 -126
View File
@@ -236,72 +236,6 @@ QbsGroupNode::QbsGroupNode(const qbs::GroupData &grp, const QString &productPath
m_qbsGroupData = grp;
}
bool QbsGroupNode::supportsAction(ProjectAction action, const Node *node) const
{
if (action == AddNewFile || action == AddExistingFile)
return true;
return supportsNodeAction(action, node);
}
bool QbsGroupNode::addFiles(const QStringList &filePaths, QStringList *notAdded)
{
QStringList notAddedDummy;
if (!notAdded)
notAdded = &notAddedDummy;
const QbsProjectNode *prjNode = parentQbsProjectNode(this);
if (!prjNode || !prjNode->qbsProject().isValid()) {
*notAdded += filePaths;
return false;
}
const QbsProductNode *prdNode = parentQbsProductNode(this);
if (!prdNode || !prdNode->qbsProductData().isValid()) {
*notAdded += filePaths;
return false;
}
return prjNode->project()->addFilesToProduct(filePaths, prdNode->qbsProductData(),
m_qbsGroupData, notAdded);
}
RemovedFilesFromProject QbsGroupNode::removeFiles(const QStringList &filePaths,
QStringList *notRemoved)
{
QStringList notRemovedDummy;
if (!notRemoved)
notRemoved = &notRemovedDummy;
const QbsProjectNode *prjNode = parentQbsProjectNode(this);
if (!prjNode || !prjNode->qbsProject().isValid()) {
*notRemoved += filePaths;
return RemovedFilesFromProject::Error;
}
const QbsProductNode *prdNode = parentQbsProductNode(this);
if (!prdNode || !prdNode->qbsProductData().isValid()) {
*notRemoved += filePaths;
return RemovedFilesFromProject::Error;
}
return prjNode->project()->removeFilesFromProduct(filePaths, prdNode->qbsProductData(),
m_qbsGroupData, notRemoved);
}
bool QbsGroupNode::renameFile(const QString &filePath, const QString &newFilePath)
{
const QbsProjectNode *prjNode = parentQbsProjectNode(this);
if (!prjNode || !prjNode->qbsProject().isValid())
return false;
const QbsProductNode *prdNode = parentQbsProductNode(this);
if (!prdNode || !prdNode->qbsProductData().isValid())
return false;
return prjNode->project()->renameFileInProduct(filePath, newFilePath,
prdNode->qbsProductData(), m_qbsGroupData);
}
FolderNode::AddNewInformation QbsGroupNode::addNewInformation(const QStringList &files,
Node *context) const
{
@@ -338,66 +272,6 @@ QbsProductNode::QbsProductNode(const qbs::ProductData &prd) :
}
}
bool QbsProductNode::supportsAction(ProjectAction action, const Node *node) const
{
if (action == AddNewFile || action == AddExistingFile)
return true;
return supportsNodeAction(action, node);
}
bool QbsProductNode::addFiles(const QStringList &filePaths, QStringList *notAdded)
{
QStringList notAddedDummy;
if (!notAdded)
notAdded = &notAddedDummy;
const QbsProjectNode *prjNode = parentQbsProjectNode(this);
if (!prjNode || !prjNode->qbsProject().isValid()) {
*notAdded += filePaths;
return false;
}
qbs::GroupData grp = findMainQbsGroup(m_qbsProductData);
if (grp.isValid()) {
return prjNode->project()->addFilesToProduct(filePaths, m_qbsProductData, grp, notAdded);
}
QTC_ASSERT(false, return false);
}
RemovedFilesFromProject QbsProductNode::removeFiles(const QStringList &filePaths,
QStringList *notRemoved)
{
QStringList notRemovedDummy;
if (!notRemoved)
notRemoved = &notRemovedDummy;
const QbsProjectNode *prjNode = parentQbsProjectNode(this);
if (!prjNode || !prjNode->qbsProject().isValid()) {
*notRemoved += filePaths;
return RemovedFilesFromProject::Error;
}
qbs::GroupData grp = findMainQbsGroup(m_qbsProductData);
if (grp.isValid()) {
return prjNode->project()->removeFilesFromProduct(filePaths, m_qbsProductData, grp,
notRemoved);
}
QTC_ASSERT(false, return RemovedFilesFromProject::Error);
}
bool QbsProductNode::renameFile(const QString &filePath, const QString &newFilePath)
{
const QbsProjectNode * 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(filePath, newFilePath, m_qbsProductData, grp);
}
void QbsProductNode::build()
{
QbsProjectManagerPlugin::buildNamedProduct(static_cast<QbsProject *>(getProject()),
@@ -487,5 +361,146 @@ QbsRootProjectNode::QbsRootProjectNode(QbsProject *project) :
m_project(project)
{ }
// --------------------------------------------------------------------
// QbsBuildSystem:
// --------------------------------------------------------------------
QbsBuildSystem::QbsBuildSystem(QbsProject *project)
: BuildSystem(project), m_project(project)
{
}
bool QbsBuildSystem::supportsAction(Node *context, ProjectAction action, const Node *node) const
{
if (dynamic_cast<QbsGroupNode *>(context)) {
if (action == AddNewFile || action == AddExistingFile)
return true;
}
if (dynamic_cast<QbsProductNode *>(context)) {
if (action == AddNewFile || action == AddExistingFile)
return true;
}
return supportsNodeAction(action, node);
}
bool QbsBuildSystem::addFiles(Node *context, const QStringList &filePaths, QStringList *notAdded)
{
if (auto n = dynamic_cast<QbsGroupNode *>(context)) {
QStringList notAddedDummy;
if (!notAdded)
notAdded = &notAddedDummy;
const QbsProjectNode *prjNode = parentQbsProjectNode(n);
if (!prjNode || !prjNode->qbsProject().isValid()) {
*notAdded += filePaths;
return false;
}
const QbsProductNode *prdNode = parentQbsProductNode(n);
if (!prdNode || !prdNode->qbsProductData().isValid()) {
*notAdded += filePaths;
return false;
}
return prjNode->project()->addFilesToProduct(filePaths, prdNode->qbsProductData(),
n->m_qbsGroupData, notAdded);
}
if (auto n = dynamic_cast<QbsProductNode *>(context)) {
QStringList notAddedDummy;
if (!notAdded)
notAdded = &notAddedDummy;
const QbsProjectNode *prjNode = parentQbsProjectNode(n);
if (!prjNode || !prjNode->qbsProject().isValid()) {
*notAdded += filePaths;
return false;
}
qbs::GroupData grp = findMainQbsGroup(n->qbsProductData());
if (grp.isValid())
return prjNode->project()->addFilesToProduct(filePaths, n->qbsProductData(), grp, notAdded);
QTC_ASSERT(false, return false);
}
return BuildSystem::addFiles(context, filePaths, notAdded);
}
RemovedFilesFromProject QbsBuildSystem::removeFiles(Node *context, const QStringList &filePaths,
QStringList *notRemoved)
{
if (auto n = dynamic_cast<QbsGroupNode *>(context)) {
QStringList notRemovedDummy;
if (!notRemoved)
notRemoved = &notRemovedDummy;
const QbsProjectNode *prjNode = parentQbsProjectNode(n);
if (!prjNode || !prjNode->qbsProject().isValid()) {
*notRemoved += filePaths;
return RemovedFilesFromProject::Error;
}
const QbsProductNode *prdNode = parentQbsProductNode(n);
if (!prdNode || !prdNode->qbsProductData().isValid()) {
*notRemoved += filePaths;
return RemovedFilesFromProject::Error;
}
return m_project->removeFilesFromProduct(filePaths, prdNode->qbsProductData(),
n->m_qbsGroupData, notRemoved);
}
if (auto n = dynamic_cast<QbsProductNode *>(context)) {
QStringList notRemovedDummy;
if (!notRemoved)
notRemoved = &notRemovedDummy;
const QbsProjectNode *prjNode = parentQbsProjectNode(n);
if (!prjNode || !prjNode->qbsProject().isValid()) {
*notRemoved += filePaths;
return RemovedFilesFromProject::Error;
}
qbs::GroupData grp = findMainQbsGroup(n->qbsProductData());
if (grp.isValid()) {
return prjNode->project()->removeFilesFromProduct(filePaths, n->qbsProductData(), grp,
notRemoved);
}
QTC_ASSERT(false, return RemovedFilesFromProject::Error);
}
return BuildSystem::removeFiles(context, filePaths, notRemoved);
}
bool QbsBuildSystem::renameFile(Node *context, const QString &filePath, const QString &newFilePath)
{
if (auto *n = dynamic_cast<QbsGroupNode *>(context)) {
const QbsProjectNode *prjNode = parentQbsProjectNode(n);
if (!prjNode || !prjNode->qbsProject().isValid())
return false;
const QbsProductNode *prdNode = parentQbsProductNode(n);
if (!prdNode || !prdNode->qbsProductData().isValid())
return false;
return m_project->renameFileInProduct(filePath, newFilePath,
prdNode->qbsProductData(), n->m_qbsGroupData);
}
if (auto *n = dynamic_cast<QbsProductNode *>(context)) {
const QbsProjectNode * prjNode = parentQbsProjectNode(n);
if (!prjNode || !prjNode->qbsProject().isValid())
return false;
const qbs::GroupData grp = findMainQbsGroup(n->qbsProductData());
QTC_ASSERT(grp.isValid(), return false);
return prjNode->project()->renameFileInProduct(filePath, newFilePath, n->qbsProductData(), grp);
}
return BuildSystem::renameFile(context, filePath, newFilePath);
}
} // namespace Internal
} // namespace QbsProjectManager
+23 -10
View File
@@ -25,6 +25,7 @@
#pragma once
#include <projectexplorer/buildsystem.h>
#include <projectexplorer/projectnodes.h>
#include <qbs.h>
@@ -35,6 +36,27 @@ namespace Internal {
class QbsNodeTreeBuilder;
class QbsProject;
class QbsBuildSystem : public ProjectExplorer::BuildSystem
{
public:
explicit QbsBuildSystem(QbsProject *project);
bool supportsAction(ProjectExplorer::Node *context,
ProjectExplorer::ProjectAction action,
const ProjectExplorer::Node *node) const final;
bool addFiles(ProjectExplorer::Node *context,
const QStringList &filePaths,
QStringList *notAdded = nullptr) override;
ProjectExplorer::RemovedFilesFromProject removeFiles(ProjectExplorer::Node *context,
const QStringList &filePaths,
QStringList *notRemoved = nullptr) override;
bool renameFile(ProjectExplorer::Node *context,
const QString &filePath, const QString &newFilePath) override;
private:
QbsProject *m_project = nullptr;
};
// --------------------------------------------------------------------
// QbsGroupNode:
// --------------------------------------------------------------------
@@ -45,13 +67,9 @@ public:
QbsGroupNode(const qbs::GroupData &grp, const QString &productPath);
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;
ProjectExplorer::RemovedFilesFromProject removeFiles(const QStringList &filePaths,
QStringList *notRemoved = nullptr) override;
bool renameFile(const QString &filePath, const QString &newFilePath) override;
private:
friend class QbsBuildSystem;
AddNewInformation addNewInformation(const QStringList &files, Node *context) const override;
QVariant data(Core::Id role) const override;
@@ -68,11 +86,6 @@ class QbsProductNode : public ProjectExplorer::ProjectNode
public:
explicit QbsProductNode(const qbs::ProductData &prd);
bool supportsAction(ProjectExplorer::ProjectAction action, const Node *node) const final;
bool addFiles(const QStringList &filePaths, QStringList *notAdded = 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;
@@ -135,6 +135,8 @@ QbsProject::QbsProject(const FilePath &fileName)
setProjectLanguages(Context(ProjectExplorer::Constants::CXX_LANGUAGE_ID));
setCanBuildProducts();
setBuildSystem(std::make_unique<QbsBuildSystem>(this));
rebuildProjectTree();
connect(this, &Project::activeTargetChanged, this, &QbsProject::changeActiveTarget);
+56 -25
View File
@@ -82,15 +82,16 @@ QmakeProFileNode *QmakePriFileNode::proFileNode() const
return m_qmakeProFileNode;
}
bool QmakePriFileNode::supportsAction(ProjectAction action, const Node *node) const
bool QmakeBuildSystem::supportsAction(Node *context, ProjectAction action, const Node *node) const
{
if (auto n = dynamic_cast<QmakePriFileNode *>(context)) { // Covers QmakeProfile, too.
if (action == Rename) {
const FileNode *fileNode = node->asFileNode();
return (fileNode && fileNode->fileType() != FileType::Project)
|| dynamic_cast<const ResourceEditor::ResourceTopLevelNode *>(node);
}
const FolderNode *folderNode = this;
const FolderNode *folderNode = n;
const QmakeProFileNode *proFileNode;
while (!(proFileNode = dynamic_cast<const QmakeProFileNode*>(folderNode))) {
folderNode = folderNode->parentFolderNode();
@@ -122,12 +123,12 @@ bool QmakePriFileNode::supportsAction(ProjectAction action, const Node *node) co
QStringList list;
foreach (FolderNode *f, folder->folderNodes())
list << f->filePath().toString() + QLatin1Char('/');
if (deploysFolder(Utils::commonPath(list)))
if (n->deploysFolder(Utils::commonPath(list)))
addExistingFiles = false;
}
}
addExistingFiles = addExistingFiles && !deploysFolder(node->filePath().toString());
addExistingFiles = addExistingFiles && !n->deploysFolder(node->filePath().toString());
if (action == AddExistingFile || action == AddExistingDirectory)
return addExistingFiles;
@@ -143,6 +144,14 @@ bool QmakePriFileNode::supportsAction(ProjectAction action, const Node *node) co
}
return false;
}
if (auto n = dynamic_cast<QmakeProFileNode *>(context)) {
if (action == RemoveSubProject)
return n->parentProjectNode() && !n->parentProjectNode()->asContainerNode();
}
return BuildSystem::supportsAction(context, action, node);
}
bool QmakePriFileNode::canAddSubProject(const QString &proFilePath) const
@@ -168,13 +177,14 @@ QStringList QmakePriFileNode::subProjectFileNamePatterns() const
return QStringList("*.pro");
}
bool QmakePriFileNode::addFiles(const QStringList &filePaths, QStringList *notAdded)
bool QmakeBuildSystem::addFiles(Node *context, const QStringList &filePaths, QStringList *notAdded)
{
QmakePriFile *pri = priFile();
if (auto n = dynamic_cast<QmakePriFileNode *>(context)) {
QmakePriFile *pri = n->priFile();
if (!pri)
return false;
QList<Node *> matchingNodes = findNodes([filePaths](const Node *n) {
return n->asFileNode() && filePaths.contains(n->filePath().toString());
QList<Node *> matchingNodes = n->findNodes([filePaths](const Node *nn) {
return nn->asFileNode() && filePaths.contains(nn->filePath().toString());
});
matchingNodes = filtered(matchingNodes, [](const Node *n) {
for (const Node *parent = n->parentFolderNode(); parent;
@@ -193,12 +203,16 @@ bool QmakePriFileNode::addFiles(const QStringList &filePaths, QStringList *notAd
if (notAdded)
*notAdded = alreadyPresentFiles;
return pri->addFiles(actualFilePaths, notAdded);
}
return BuildSystem::addFiles(context, filePaths, notAdded);
}
RemovedFilesFromProject QmakePriFileNode::removeFiles(const QStringList &filePaths,
RemovedFilesFromProject QmakeBuildSystem::removeFiles(Node *context, const QStringList &filePaths,
QStringList *notRemoved)
{
QmakePriFile * const pri = priFile();
if (auto n = dynamic_cast<QmakePriFileNode *>(context)) {
QmakePriFile * const pri = n->priFile();
if (!pri)
return RemovedFilesFromProject::Error;
QStringList wildcardFiles;
@@ -217,31 +231,50 @@ RemovedFilesFromProject QmakePriFileNode::removeFiles(const QStringList &filePat
if (!wildcardFiles.isEmpty())
return RemovedFilesFromProject::Wildcard;
return RemovedFilesFromProject::Ok;
}
return BuildSystem::removeFiles(context, filePaths, notRemoved);
}
bool QmakePriFileNode::deleteFiles(const QStringList &filePaths)
bool QmakeBuildSystem::deleteFiles(Node *context, const QStringList &filePaths)
{
QmakePriFile *pri = priFile();
if (auto n = dynamic_cast<QmakePriFileNode *>(context)) {
QmakePriFile *pri = n->priFile();
return pri ? pri->deleteFiles(filePaths) : false;
}
return BuildSystem::deleteFiles(context, filePaths);
}
bool QmakePriFileNode::canRenameFile(const QString &filePath, const QString &newFilePath)
bool QmakeBuildSystem::canRenameFile(Node *context, const QString &filePath, const QString &newFilePath)
{
QmakePriFile *pri = priFile();
if (auto n = dynamic_cast<QmakePriFileNode *>(context)) {
QmakePriFile *pri = n->priFile();
return pri ? pri->canRenameFile(filePath, newFilePath) : false;
}
return BuildSystem::canRenameFile(context, filePath, newFilePath);
}
bool QmakePriFileNode::renameFile(const QString &filePath, const QString &newFilePath)
bool QmakeBuildSystem::renameFile(Node *context, const QString &filePath, const QString &newFilePath)
{
QmakePriFile *pri = priFile();
if (auto n = dynamic_cast<QmakePriFileNode *>(context)) {
QmakePriFile *pri = n->priFile();
return pri ? pri->renameFile(filePath, newFilePath) : false;
}
return BuildSystem::renameFile(context, filePath, newFilePath);
}
bool QmakePriFileNode::addDependencies(const QStringList &dependencies)
bool QmakeBuildSystem::addDependencies(Node *context, const QStringList &dependencies)
{
if (QmakePriFile * const pri = priFile())
if (auto n = dynamic_cast<QmakePriFileNode *>(context)) {
if (QmakePriFile * const pri = n->priFile())
return pri->addDependencies(dependencies);
return false;
}
return BuildSystem::addDependencies(context, dependencies);
}
FolderNode::AddNewInformation QmakePriFileNode::addNewInformation(const QStringList &files, Node *context) const
@@ -405,13 +438,6 @@ bool QmakeProFileNode::includedInExactParse() const
return pro && pro->includedInExactParse();
}
bool QmakeProFileNode::supportsAction(ProjectAction action, const Node *node) const
{
if (action == RemoveSubProject)
return parentProjectNode() && !parentProjectNode()->asContainerNode();
return QmakePriFileNode::supportsAction(action, node);
}
FolderNode::AddNewInformation QmakeProFileNode::addNewInformation(const QStringList &files, Node *context) const
{
Q_UNUSED(files)
@@ -474,4 +500,9 @@ TargetInformation QmakeProFileNode::targetInformation() const
return proFile() ? proFile()->targetInformation() : TargetInformation();
}
QmakeBuildSystem::QmakeBuildSystem(QmakeProject *project)
: BuildSystem(project), m_project(project)
{
}
} // namespace QmakeProjectManager
+28 -11
View File
@@ -28,6 +28,7 @@
#include "qmakeprojectmanager_global.h"
#include "qmakeparsernodes.h"
#include <projectexplorer/buildsystem.h>
#include <projectexplorer/projectnodes.h>
namespace Utils { class FilePath; }
@@ -36,6 +37,33 @@ namespace QmakeProjectManager {
class QmakeProFileNode;
class QmakeProject;
class QmakeBuildSystem : public ProjectExplorer::BuildSystem
{
public:
explicit QmakeBuildSystem(QmakeProject *project);
bool supportsAction(ProjectExplorer::Node *context,
ProjectExplorer::ProjectAction action,
const ProjectExplorer::Node *node) const override;
bool addFiles(ProjectExplorer::Node *context,
const QStringList &filePaths,
QStringList *notAdded = nullptr) override;
ProjectExplorer::RemovedFilesFromProject removeFiles(ProjectExplorer::Node *context,
const QStringList &filePaths,
QStringList *notRemoved = nullptr) override;
bool deleteFiles(ProjectExplorer::Node *context,
const QStringList &filePaths) override;
bool canRenameFile(ProjectExplorer::Node *context,
const QString &filePath, const QString &newFilePath) override;
bool renameFile(ProjectExplorer::Node *context,
const QString &filePath, const QString &newFilePath) override;
bool addDependencies(ProjectExplorer::Node *context,
const QStringList &dependencies) override;
private:
QmakeProject *m_project = nullptr;
};
// Implements ProjectNode for qmake .pri files
class QMAKEPROJECTMANAGER_EXPORT QmakePriFileNode : public ProjectExplorer::ProjectNode
{
@@ -45,9 +73,6 @@ public:
QmakePriFile *priFile() const;
// ProjectNode interface
bool supportsAction(ProjectExplorer::ProjectAction action, const Node *node) const override;
bool showInSimpleTree() const override { return false; }
bool canAddSubProject(const QString &proFilePath) const override;
@@ -55,13 +80,6 @@ public:
bool removeSubProject(const QString &proFilePath) override;
QStringList subProjectFileNamePatterns() const override;
bool addFiles(const QStringList &filePaths, QStringList *notAdded = nullptr) override;
ProjectExplorer::RemovedFilesFromProject removeFiles(const QStringList &filePaths,
QStringList *notRemoved = nullptr) override;
bool deleteFiles(const QStringList &filePaths) override;
bool canRenameFile(const QString &filePath, const QString &newFilePath) override;
bool renameFile(const QString &filePath, const QString &newFilePath) override;
bool addDependencies(const QStringList &dependencies) override;
AddNewInformation addNewInformation(const QStringList &files, Node *context) const override;
bool deploysFolder(const QString &folder) const override;
@@ -92,7 +110,6 @@ public:
bool isQtcRunnable() const;
bool includedInExactParse() const;
bool supportsAction(ProjectExplorer::ProjectAction action, const Node *node) const override;
bool showInSimpleTree() const override;
QString buildKey() const override;
@@ -145,6 +145,7 @@ QmakeProject::QmakeProject(const FilePath &fileName) :
this, &QmakeProject::buildFinished);
setPreferredKitPredicate([this](const Kit *kit) -> bool { return matchesKit(kit); });
setBuildSystem(std::make_unique<QmakeBuildSystem>(this));
}
QmakeProject::~QmakeProject()
@@ -67,6 +67,7 @@ QmlProject::QmlProject(const Utils::FilePath &fileName)
setDisplayName(fileName.toFileInfo().completeBaseName());
setNeedsBuildConfigurations(false);
setBuildSystem(std::make_unique<Internal::QmlBuildSystem>(this));
connect(this, &QmlProject::projectFileIsDirty, this, &QmlProject::refreshProjectFile);
}
@@ -398,5 +399,6 @@ void QmlProject::updateDeploymentData(ProjectExplorer::Target *target)
target->setDeploymentData(deploymentData);
}
} // namespace QmlProjectManager
@@ -28,6 +28,7 @@
#include "qmlprojectmanager_global.h"
#include "qmlprojectnodes.h"
#include <projectexplorer/buildsystem.h>
#include <projectexplorer/project.h>
#include <utils/environment.h>
@@ -38,8 +39,31 @@ namespace ProjectExplorer { class RunConfiguration; }
namespace QmlProjectManager {
class QmlProject;
class QmlProjectItem;
namespace Internal {
class QmlBuildSystem : public ProjectExplorer::BuildSystem
{
public:
explicit QmlBuildSystem(ProjectExplorer::Project *project) : BuildSystem(project) {}
bool supportsAction(ProjectExplorer::Node *context,
ProjectExplorer::ProjectAction action,
const ProjectExplorer::Node *node) const override;
bool addFiles(ProjectExplorer::Node *context,
const QStringList &filePaths, QStringList *notAdded = nullptr) override;
bool deleteFiles(ProjectExplorer::Node *context,
const QStringList &filePaths) override;
bool renameFile(ProjectExplorer::Node *context,
const QString &filePath, const QString &newFilePath) override;
QmlProject *project() const;
};
} // Internal
class QMLPROJECTMANAGER_EXPORT QmlProject : public ProjectExplorer::Project
{
Q_OBJECT
@@ -53,8 +53,9 @@ QmlProjectNode::QmlProjectNode(QmlProject *project) : ProjectNode(project->proje
setIcon(qmlProjectIcon);
}
bool QmlProjectNode::supportsAction(ProjectAction action, const Node *node) const
bool QmlBuildSystem::supportsAction(Node *context, ProjectAction action, const Node *node) const
{
if (dynamic_cast<QmlProjectNode *>(context)) {
if (action == AddNewFile || action == EraseFile)
return true;
QTC_ASSERT(node, return false);
@@ -66,25 +67,40 @@ bool QmlProjectNode::supportsAction(ProjectAction action, const Node *node) cons
}
return false;
}
return BuildSystem::supportsAction(context, action, node);
}
bool QmlProjectNode::addFiles(const QStringList &filePaths, QStringList * /*notAdded*/)
QmlProject *QmlBuildSystem::project() const
{
return m_project->addFiles(filePaths);
return static_cast<QmlProject *>(BuildSystem::project());
}
bool QmlProjectNode::deleteFiles(const QStringList & /*filePaths*/)
bool QmlBuildSystem::addFiles(Node *context, const QStringList &filePaths, QStringList *notAdded)
{
if (dynamic_cast<QmlProjectNode *>(context))
return project()->addFiles(filePaths);
return BuildSystem::addFiles(context, filePaths, notAdded);
}
bool QmlBuildSystem::deleteFiles(Node *context, const QStringList &filePaths)
{
if (dynamic_cast<QmlProjectNode *>(context))
return true;
return BuildSystem::deleteFiles(context, filePaths);
}
bool QmlProjectNode::renameFile(const QString & filePath, const QString & newFilePath)
bool QmlBuildSystem::renameFile(Node * context, const QString &filePath, const QString &newFilePath)
{
if (filePath.endsWith(m_project->mainFile())) {
m_project->setMainFile(newFilePath);
if (dynamic_cast<QmlProjectNode *>(context)) {
if (filePath.endsWith(project()->mainFile())) {
project()->setMainFile(newFilePath);
// make sure to change it also in the qmlproject file
const QString qmlProjectFilePath = m_project->projectFilePath().toString();
const QString qmlProjectFilePath = project()->projectFilePath().toString();
Core::FileChangeBlocker fileChangeBlocker(qmlProjectFilePath);
const QList<Core::IEditor *> editors = Core::DocumentModel::editorsForFilePath(qmlProjectFilePath);
TextEditor::TextDocument *document = nullptr;
@@ -114,10 +130,13 @@ bool QmlProjectNode::renameFile(const QString & filePath, const QString & newFil
if (!textFileFormat.writeFile(qmlProjectFilePath, fileContent, &error))
qWarning() << "Failed to write file" << qmlProjectFilePath << ":" << error;
m_project->refresh(QmlProject::Everything);
project()->refresh(QmlProject::Everything);
}
return true;
}
return BuildSystem::renameFile(context, filePath, newFilePath);
}
} // namespace Internal
@@ -38,11 +38,6 @@ class QmlProjectNode : public ProjectExplorer::ProjectNode
public:
QmlProjectNode(QmlProject *project);
bool supportsAction(ProjectExplorer::ProjectAction action, const Node *node) const override;
bool addFiles(const QStringList &filePaths, QStringList *notAdded = nullptr) override;
bool deleteFiles(const QStringList &filePaths) override;
bool renameFile(const QString &filePath, const QString &newFilePath) override;
private:
QmlProject *m_project;
};