Support basic behavior for AddFile in CMake project

Change-Id: Ib9c764908abc7daa9a3c614b93da98bc4e674862
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
Pawel Rutka
2018-02-13 18:14:03 +01:00
committed by pawelrutka
parent d0273f83f9
commit b9bdacb27a
2 changed files with 69 additions and 1 deletions

View File

@@ -28,12 +28,50 @@
#include "cmakeprojectconstants.h"
#include <coreplugin/fileiconprovider.h>
#include <cpptools/cpptoolsconstants.h>
#include <utils/algorithm.h>
#include <utils/mimetypes/mimedatabase.h>
#include <utils/optional.h>
#include <QClipboard>
#include <QDir>
#include <QGuiApplication>
#include <QMessageBox>
using namespace CMakeProjectManager;
using namespace CMakeProjectManager::Internal;
namespace {
void noAutoAdditionNotify(const QStringList &filePaths, const ProjectExplorer::ProjectNode *node)
{
Utils::optional<QString> 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<Utils::FileName> &artifacts,
const QString &type)
{

View File

@@ -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;
};