aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp
diff options
context:
space:
mode:
authorTobias Hunger <[email protected]>2020-04-17 15:30:05 +0200
committerTobias Hunger <[email protected]>2020-04-20 10:05:24 +0000
commit5350288e45d26b3e14ffb99d7f0b342fe5f2076a (patch)
tree8a0ffc34cf79cbbe863b060b8bf1379c7d18e407 /src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp
parent9f981e7e239c1b188b320017f064c633795714ae (diff)
CMake: Fix includes all over the CMake plugin
Keep internals internal, remove some unnecessary includes, add some that should have been there. This reduces the number of files that get rebuild when working on CMake internals from over 1000 to about 200. This patch also moves some code around that ended up being in the wrong file. Change-Id: Icd7366ac760dc85031040720418fbb16336dce9b Reviewed-by: Eike Ziller <[email protected]>
Diffstat (limited to 'src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp')
-rw-r--r--src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp108
1 files changed, 103 insertions, 5 deletions
diff --git a/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp b/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp
index a647c405f78..b0d962d72cb 100644
--- a/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp
+++ b/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp
@@ -27,33 +27,105 @@
#include "cmakebuildconfiguration.h"
#include "cmakekitinformation.h"
-#include "cmakeproject.h"
#include "cmakeprojectconstants.h"
#include "cmakeprojectnodes.h"
+#include "cmakeprojectplugin.h"
+#include "cmakespecificsettings.h"
#include <android/androidconstants.h>
-
+#include <coreplugin/icore.h>
#include <coreplugin/progressmanager/progressmanager.h>
#include <cpptools/cppprojectupdater.h>
+#include <cpptools/cpptoolsconstants.h>
#include <cpptools/generatedcodemodelsupport.h>
-#include <projectexplorer/kitmanager.h>
-#include <projectexplorer/project.h>
+#include <projectexplorer/kitinformation.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/target.h>
#include <qmljs/qmljsmodelmanagerinterface.h>
#include <qtsupport/qtcppkitinfo.h>
-#include <qtsupport/qtkitinformation.h>
+#include <utils/checkablemessagebox.h>
#include <utils/fileutils.h>
#include <utils/mimetypes/mimetype.h>
#include <utils/qtcassert.h>
+#include <QClipboard>
+#include <QDir>
+#include <QGuiApplication>
#include <QLoggingCategory>
using namespace ProjectExplorer;
using namespace Utils;
+namespace {
+
+void copySourcePathToClipboard(Utils::optional<QString> srcPath,
+ const ProjectExplorer::ProjectNode *node)
+{
+ QClipboard *clip = QGuiApplication::clipboard();
+
+ QDir projDir{node->filePath().toFileInfo().absoluteFilePath()};
+ clip->setText(QDir::cleanPath(projDir.relativeFilePath(srcPath.value())));
+}
+
+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) {
+ CMakeProjectManager::Internal::CMakeSpecificSettings *settings
+ = CMakeProjectManager::Internal::CMakeProjectPlugin::projectTypeSpecificSettings();
+ switch (settings->afterAddFileSetting()) {
+ case CMakeProjectManager::Internal::ASK_USER: {
+ bool checkValue{false};
+ QDialogButtonBox::StandardButton reply = Utils::CheckableMessageBox::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?"),
+ "Remember My Choice",
+ &checkValue,
+ QDialogButtonBox::Yes | QDialogButtonBox::No,
+ QDialogButtonBox::Yes);
+ if (checkValue) {
+ if (QDialogButtonBox::Yes == reply)
+ settings->setAfterAddFileSetting(
+ CMakeProjectManager::Internal::AfterAddFileAction::COPY_FILE_PATH);
+ else if (QDialogButtonBox::No == reply)
+ settings->setAfterAddFileSetting(
+ CMakeProjectManager::Internal::AfterAddFileAction::NEVER_COPY_FILE_PATH);
+
+ settings->toSettings(Core::ICore::settings());
+ }
+
+ if (QDialogButtonBox::Yes == reply) {
+ copySourcePathToClipboard(srcPath, node);
+ }
+ break;
+ }
+
+ case CMakeProjectManager::Internal::COPY_FILE_PATH: {
+ copySourcePathToClipboard(srcPath, node);
+ break;
+ }
+
+ case CMakeProjectManager::Internal::NEVER_COPY_FILE_PATH:
+ break;
+ }
+ }
+}
+
+} // namespace
+
namespace CMakeProjectManager {
namespace Internal {
@@ -264,6 +336,32 @@ void CMakeBuildSystem::triggerParsing()
m_buildDirManager.parse();
}
+bool CMakeBuildSystem::supportsAction(Node *context, ProjectAction action, const Node *node) const
+{
+ if (dynamic_cast<CMakeTargetNode *>(context))
+ return action == ProjectAction::AddNewFile;
+
+ if (dynamic_cast<CMakeListsNode *>(context))
+ return action == ProjectAction::AddNewFile;
+
+ return BuildSystem::supportsAction(context, action, node);
+}
+
+bool CMakeBuildSystem::addFiles(Node *context, const QStringList &filePaths, QStringList *notAdded)
+{
+ 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);
+}
+
QStringList CMakeBuildSystem::filesGeneratedFrom(const QString &sourceFile) const
{
QFileInfo fi(sourceFile);