From b9bdacb27a8a2a5253d7ab070261049bf27f5ce9 Mon Sep 17 00:00:00 2001 From: Pawel Rutka Date: Tue, 13 Feb 2018 18:14:03 +0100 Subject: [PATCH] Support basic behavior for AddFile in CMake project Change-Id: Ib9c764908abc7daa9a3c614b93da98bc4e674862 Reviewed-by: Tobias Hunger --- .../cmakeprojectmanager/cmakeprojectnodes.cpp | 64 ++++++++++++++++++- .../cmakeprojectmanager/cmakeprojectnodes.h | 6 ++ 2 files changed, 69 insertions(+), 1 deletion(-) diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectnodes.cpp b/src/plugins/cmakeprojectmanager/cmakeprojectnodes.cpp index 3740aee8be5..64344436665 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprojectnodes.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeprojectnodes.cpp @@ -28,12 +28,50 @@ #include "cmakeprojectconstants.h" #include - +#include #include +#include +#include + + +#include +#include +#include +#include using namespace CMakeProjectManager; using namespace CMakeProjectManager::Internal; +namespace { +void noAutoAdditionNotify(const QStringList &filePaths, const ProjectExplorer::ProjectNode *node) +{ + Utils::optional srcPath{}; + + for (const QString &file : filePaths) { + if (Utils::mimeTypeForFile(file).name() == CppTools::Constants::CPP_SOURCE_MIMETYPE) { + srcPath = file; + break; + } + } + + if (srcPath) { + QMessageBox::StandardButton reply = + QMessageBox::question(nullptr, QMessageBox::tr("Copy to Clipboard?"), + QMessageBox::tr("Files are not automatically added to the CMakeLists.txt file of the CMake project." + "\nCopy the path to the source files to the clipboard?"), + QMessageBox::Yes | QMessageBox::No); + + if (QMessageBox::Yes == reply) { + QClipboard *clip = QGuiApplication::clipboard(); + + QDir projDir{node->filePath().toFileInfo().absoluteFilePath()}; + clip->setText(QDir::cleanPath(projDir.relativeFilePath(srcPath.value()))); + } + } +} + +} + CMakeInputsNode::CMakeInputsNode(const Utils::FileName &cmakeLists) : ProjectExplorer::ProjectNode(cmakeLists, generateId(cmakeLists)) { @@ -84,6 +122,18 @@ QString CMakeProjectNode::tooltip() const return QString(); } +bool CMakeProjectNode::supportsAction(ProjectExplorer::ProjectAction action, + const ProjectExplorer::Node *node) const +{ + return action == ProjectExplorer::ProjectAction::AddNewFile; +} + +bool CMakeProjectNode::addFiles(const QStringList &filePaths, QStringList *notAdded) +{ + noAutoAdditionNotify(filePaths, this); + return true; // Return always true as autoadd is not supported! +} + CMakeTargetNode::CMakeTargetNode(const Utils::FileName &directory, const QString &target) : ProjectExplorer::ProjectNode(directory, generateId(directory, target)) { @@ -107,6 +157,18 @@ QString CMakeTargetNode::tooltip() const return m_tooltip; } +bool CMakeTargetNode::supportsAction(ProjectExplorer::ProjectAction action, + const ProjectExplorer::Node *node) const +{ + return action == ProjectExplorer::ProjectAction::AddNewFile; +} + +bool CMakeTargetNode::addFiles(const QStringList &filePaths, QStringList *notAdded) +{ + noAutoAdditionNotify(filePaths, this); + return true; // Return always true as autoadd is not supported! +} + void CMakeTargetNode::setTargetInformation(const QList &artifacts, const QString &type) { diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectnodes.h b/src/plugins/cmakeprojectmanager/cmakeprojectnodes.h index edf031bf57d..e483e7b61e5 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprojectnodes.h +++ b/src/plugins/cmakeprojectmanager/cmakeprojectnodes.h @@ -55,6 +55,9 @@ public: bool showInSimpleTree() const final; QString tooltip() const final; + + bool supportsAction(ProjectExplorer::ProjectAction action, const Node *node) const override; + bool addFiles(const QStringList &filePaths, QStringList *notAdded) override; }; class CMakeTargetNode : public ProjectExplorer::ProjectNode @@ -69,6 +72,9 @@ public: bool showInSimpleTree() const final; QString tooltip() const final; + bool supportsAction(ProjectExplorer::ProjectAction action, const Node *node) const override; + bool addFiles(const QStringList &filePaths, QStringList *notAdded) override; + private: QString m_tooltip; };