forked from qt-creator/qt-creator
GenericProject: Use new setup for GenericProject itself
Change-Id: I8c18cd5372de1179bf6ebdcfabc6c50ac8f6d50f Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io> Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include "genericprojectconstants.h"
|
||||
#include "genericprojectmanagertr.h"
|
||||
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
#include <coreplugin/documentmanager.h>
|
||||
#include <coreplugin/icontext.h>
|
||||
#include <coreplugin/icore.h>
|
||||
@@ -20,9 +21,11 @@
|
||||
#include <projectexplorer/headerpath.h>
|
||||
#include <projectexplorer/kitaspects.h>
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
#include <projectexplorer/projectmanager.h>
|
||||
#include <projectexplorer/projectnodes.h>
|
||||
#include <projectexplorer/projectnodes.h>
|
||||
#include <projectexplorer/projecttree.h>
|
||||
#include <projectexplorer/projectupdater.h>
|
||||
|
||||
#include <projectexplorer/selectablefilesmodel.h>
|
||||
#include <projectexplorer/target.h>
|
||||
#include <projectexplorer/taskhub.h>
|
||||
@@ -51,8 +54,7 @@ using namespace Core;
|
||||
using namespace ProjectExplorer;
|
||||
using namespace Utils;
|
||||
|
||||
namespace GenericProjectManager {
|
||||
namespace Internal {
|
||||
namespace GenericProjectManager::Internal {
|
||||
|
||||
enum RefreshOptions {
|
||||
Files = 0x01,
|
||||
@@ -60,13 +62,13 @@ enum RefreshOptions {
|
||||
Everything = Files | Configuration
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// GenericProjectFile
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class GenericProjectFile : public Core::IDocument
|
||||
class GenericProject;
|
||||
|
||||
class GenericProjectFile final : public IDocument
|
||||
{
|
||||
public:
|
||||
GenericProjectFile(GenericProject *parent, const FilePath &fileName, RefreshOptions options)
|
||||
@@ -82,7 +84,7 @@ public:
|
||||
return BehaviorSilent;
|
||||
}
|
||||
|
||||
bool reload(QString *errorString, ReloadFlag flag, ChangeType type) override;
|
||||
bool reload(QString *errorString, ReloadFlag flag, ChangeType type) final;
|
||||
|
||||
private:
|
||||
GenericProject *m_project = nullptr;
|
||||
@@ -90,13 +92,11 @@ private:
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// GenericBuildSystem
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class GenericBuildSystem : public BuildSystem
|
||||
class GenericBuildSystem final : public BuildSystem
|
||||
{
|
||||
public:
|
||||
explicit GenericBuildSystem(Target *target);
|
||||
@@ -131,7 +131,7 @@ public:
|
||||
SourceFiles processEntries(const QStringList &paths,
|
||||
QHash<QString, QString> *map = nullptr) const;
|
||||
|
||||
Utils::FilePath findCommonSourceRoot();
|
||||
FilePath findCommonSourceRoot();
|
||||
void refreshCppCodeModel();
|
||||
void updateDeploymentData();
|
||||
|
||||
@@ -148,7 +148,7 @@ private:
|
||||
SourceFiles m_files;
|
||||
QHash<QString, QString> m_rawListEntries;
|
||||
QStringList m_rawProjectIncludePaths;
|
||||
ProjectExplorer::HeaderPaths m_projectIncludePaths;
|
||||
HeaderPaths m_projectIncludePaths;
|
||||
QStringList m_cxxflags;
|
||||
QStringList m_cflags;
|
||||
|
||||
@@ -157,27 +157,39 @@ private:
|
||||
FileSystemWatcher m_deployFileWatcher;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// GenericProject
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static bool writeFile(const QString &filePath, const QString &contents)
|
||||
{
|
||||
Utils::FileSaver saver(Utils::FilePath::fromString(filePath),
|
||||
QIODevice::Text | QIODevice::WriteOnly);
|
||||
FileSaver saver(FilePath::fromString(filePath),
|
||||
QIODevice::Text | QIODevice::WriteOnly);
|
||||
return saver.write(contents.toUtf8()) && saver.finalize();
|
||||
}
|
||||
|
||||
GenericProject::GenericProject(const Utils::FilePath &fileName)
|
||||
: Project(Constants::GENERICMIMETYPE, fileName)
|
||||
class GenericProject final : public Project
|
||||
{
|
||||
setId(Constants::GENERICPROJECT_ID);
|
||||
setProjectLanguages(Context(ProjectExplorer::Constants::CXX_LANGUAGE_ID));
|
||||
setDisplayName(fileName.completeBaseName());
|
||||
setBuildSystemCreator([](Target *t) { return new GenericBuildSystem(t); });
|
||||
}
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit GenericProject(const FilePath &filePath)
|
||||
: Project(Constants::GENERICMIMETYPE, filePath)
|
||||
{
|
||||
setId(Constants::GENERICPROJECT_ID);
|
||||
setProjectLanguages(Context(ProjectExplorer::Constants::CXX_LANGUAGE_ID));
|
||||
setDisplayName(filePath.completeBaseName());
|
||||
setBuildSystemCreator([](Target *t) { return new GenericBuildSystem(t); });
|
||||
}
|
||||
|
||||
void editFilesTriggered();
|
||||
void removeFilesTriggered(const FilePaths &filesToRemove);
|
||||
|
||||
private:
|
||||
RestoreResult fromMap(const Store &map, QString *errorMessage) final;
|
||||
DeploymentKnowledge deploymentKnowledge() const final;
|
||||
void configureAsExampleProject(Kit *kit) final;
|
||||
};
|
||||
|
||||
GenericBuildSystem::GenericBuildSystem(Target *target)
|
||||
: BuildSystem(target)
|
||||
@@ -276,7 +288,7 @@ bool GenericBuildSystem::saveRawList(const QStringList &rawList, const QString &
|
||||
const FilePath filePath = FilePath::fromString(fileName);
|
||||
FileChangeBlocker changeGuard(filePath);
|
||||
// Make sure we can open the file for writing
|
||||
Utils::FileSaver saver(filePath, QIODevice::Text);
|
||||
FileSaver saver(filePath, QIODevice::Text);
|
||||
if (!saver.hasError()) {
|
||||
QTextStream stream(saver.file());
|
||||
for (const QString &filePath : rawList)
|
||||
@@ -404,7 +416,7 @@ void GenericBuildSystem::parse(RefreshOptions options)
|
||||
m_rawProjectIncludePaths = readLines(m_includesFileName);
|
||||
QStringList normalPaths;
|
||||
QStringList frameworkPaths;
|
||||
const auto baseDir = Utils::FilePath::fromString(m_includesFileName).parentDir();
|
||||
const auto baseDir = FilePath::fromString(m_includesFileName).parentDir();
|
||||
for (const QString &rawPath : std::as_const(m_rawProjectIncludePaths)) {
|
||||
if (rawPath.startsWith("-F"))
|
||||
frameworkPaths << rawPath.mid(2);
|
||||
@@ -499,11 +511,11 @@ GenericBuildSystem::SourceFiles GenericBuildSystem::processEntries(
|
||||
{
|
||||
const BuildConfiguration *const buildConfig = target()->activeBuildConfiguration();
|
||||
|
||||
const Utils::Environment buildEnv = buildConfig ? buildConfig->environment()
|
||||
: Utils::Environment::systemEnvironment();
|
||||
const Environment buildEnv = buildConfig ? buildConfig->environment()
|
||||
: Environment::systemEnvironment();
|
||||
|
||||
const Utils::MacroExpander *expander = buildConfig ? buildConfig->macroExpander()
|
||||
: target()->macroExpander();
|
||||
const MacroExpander *expander = buildConfig ? buildConfig->macroExpander()
|
||||
: target()->macroExpander();
|
||||
|
||||
const QDir projectDir(projectDirectory().toString());
|
||||
|
||||
@@ -518,7 +530,7 @@ GenericBuildSystem::SourceFiles GenericBuildSystem::processEntries(
|
||||
trimmedPath = buildEnv.expandVariables(trimmedPath);
|
||||
trimmedPath = expander->expand(trimmedPath);
|
||||
|
||||
trimmedPath = Utils::FilePath::fromUserInput(trimmedPath).toString();
|
||||
trimmedPath = FilePath::fromUserInput(trimmedPath).toString();
|
||||
|
||||
QStringList tagsForFile;
|
||||
const int tagListPos = trimmedPath.indexOf('|');
|
||||
@@ -575,7 +587,7 @@ void GenericBuildSystem::refreshCppCodeModel()
|
||||
void GenericBuildSystem::updateDeploymentData()
|
||||
{
|
||||
static const QString fileName("QtCreatorDeployment.txt");
|
||||
Utils::FilePath deploymentFilePath;
|
||||
FilePath deploymentFilePath;
|
||||
BuildConfiguration *bc = target()->activeBuildConfiguration();
|
||||
if (bc)
|
||||
deploymentFilePath = bc->buildDirectory().pathAppended(fileName);
|
||||
@@ -635,12 +647,12 @@ Project::RestoreResult GenericProject::fromMap(const Store &map, QString *errorM
|
||||
return RestoreResult::Ok;
|
||||
}
|
||||
|
||||
ProjectExplorer::DeploymentKnowledge GenericProject::deploymentKnowledge() const
|
||||
DeploymentKnowledge GenericProject::deploymentKnowledge() const
|
||||
{
|
||||
return DeploymentKnowledge::Approximative;
|
||||
}
|
||||
|
||||
void GenericProject::configureAsExampleProject(ProjectExplorer::Kit *kit)
|
||||
void GenericProject::configureAsExampleProject(Kit *kit)
|
||||
{
|
||||
QList<BuildInfo> infoList;
|
||||
const QList<Kit *> kits(kit != nullptr ? QList<Kit *>({kit}) : KitManager::kits());
|
||||
@@ -689,5 +701,38 @@ void GenericProject::removeFilesTriggered(const FilePaths &filesToRemove)
|
||||
static_cast<GenericBuildSystem *>(t->buildSystem())->removeFiles(filesToRemove);
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace GenericProjectManager
|
||||
void setupGenericProject(QObject *guard)
|
||||
{
|
||||
namespace PEC = ProjectExplorer::Constants;
|
||||
|
||||
ProjectManager::registerProjectType<GenericProject>(Constants::GENERICMIMETYPE);
|
||||
|
||||
ActionBuilder editAction(guard, "GenericProjectManager.EditFiles");
|
||||
editAction.setContext(Constants::GENERICPROJECT_ID);
|
||||
editAction.setText(Tr::tr("Edit Files..."));
|
||||
editAction.setCommandAttribute(Command::CA_Hide);
|
||||
editAction.setContainer(PEC::M_PROJECTCONTEXT, PEC::G_PROJECT_FILES);
|
||||
editAction.setOnTriggered([] {
|
||||
if (auto genericProject = qobject_cast<GenericProject *>(ProjectTree::currentProject()))
|
||||
genericProject->editFilesTriggered();
|
||||
});
|
||||
|
||||
ActionBuilder removeDirAction(guard, "GenericProject.RemoveDir");
|
||||
removeDirAction.setContext(PEC::C_PROJECT_TREE);
|
||||
removeDirAction.setText(Tr::tr("Remove Directory"));
|
||||
removeDirAction.setContainer(PEC::M_FOLDERCONTEXT, PEC::G_FOLDER_OTHER);
|
||||
removeDirAction.setOnTriggered([] {
|
||||
const auto folderNode = ProjectTree::currentNode()->asFolderNode();
|
||||
QTC_ASSERT(folderNode, return);
|
||||
const auto project = qobject_cast<GenericProject *>(folderNode->getProject());
|
||||
QTC_ASSERT(project, return);
|
||||
const FilePaths filesToRemove = transform(
|
||||
folderNode->findNodes([](const Node *node) { return node->asFileNode(); }),
|
||||
[](const Node *node) { return node->filePath();});
|
||||
project->removeFilesTriggered(filesToRemove);
|
||||
});
|
||||
}
|
||||
|
||||
} // GenericProjectManager::Internal
|
||||
|
||||
#include "genericproject.moc"
|
||||
|
||||
Reference in New Issue
Block a user