2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "cmakeprojectplugin.h"
|
2014-08-20 00:07:43 +02:00
|
|
|
|
2020-04-17 15:30:05 +02:00
|
|
|
#include "cmakebuildconfiguration.h"
|
2016-01-07 12:33:52 +01:00
|
|
|
#include "cmakebuildstep.h"
|
2020-04-17 15:30:05 +02:00
|
|
|
#include "cmakebuildsystem.h"
|
|
|
|
|
#include "cmakeeditor.h"
|
2022-11-21 00:10:25 +01:00
|
|
|
#include "cmakeformatter.h"
|
2022-12-09 18:44:42 +01:00
|
|
|
#include "cmakeinstallstep.h"
|
2020-04-17 15:30:05 +02:00
|
|
|
#include "cmakelocatorfilter.h"
|
2016-11-14 15:18:25 +01:00
|
|
|
#include "cmakeproject.h"
|
|
|
|
|
#include "cmakeprojectconstants.h"
|
2008-12-02 14:09:21 +01:00
|
|
|
#include "cmakeprojectmanager.h"
|
2022-09-29 15:26:31 +02:00
|
|
|
#include "cmakeprojectmanagertr.h"
|
2016-11-14 15:18:25 +01:00
|
|
|
#include "cmakeprojectnodes.h"
|
2014-09-12 13:02:40 +04:00
|
|
|
#include "cmakesettingspage.h"
|
2020-04-17 15:30:05 +02:00
|
|
|
#include "cmaketoolmanager.h"
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2016-11-14 15:18:25 +01:00
|
|
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
|
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
2022-09-29 15:26:31 +02:00
|
|
|
|
2020-04-17 15:30:05 +02:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2017-03-03 18:16:34 +01:00
|
|
|
#include <projectexplorer/projectmanager.h>
|
2016-11-14 15:18:25 +01:00
|
|
|
#include <projectexplorer/projecttree.h>
|
2022-09-29 15:26:31 +02:00
|
|
|
|
2022-11-21 00:10:25 +01:00
|
|
|
#include <texteditor/formattexteditor.h>
|
2017-04-24 15:52:04 +02:00
|
|
|
#include <texteditor/snippets/snippetprovider.h>
|
|
|
|
|
|
2022-05-31 11:16:44 +02:00
|
|
|
#include <utils/fsengine/fileiconprovider.h>
|
2016-11-14 15:18:25 +01:00
|
|
|
#include <utils/parameteraction.h>
|
2016-11-09 14:25:30 +01:00
|
|
|
|
2022-09-29 10:11:28 +02:00
|
|
|
#include <QTimer>
|
2022-11-21 00:10:25 +01:00
|
|
|
#include <QMenu>
|
2022-09-29 10:11:28 +02:00
|
|
|
|
2016-11-14 15:18:25 +01:00
|
|
|
using namespace Core;
|
|
|
|
|
using namespace ProjectExplorer;
|
2019-10-25 09:55:32 +02:00
|
|
|
using namespace Utils;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2022-09-29 15:26:31 +02:00
|
|
|
namespace CMakeProjectManager::Internal {
|
2018-02-09 15:35:02 +01:00
|
|
|
|
2022-11-21 00:10:25 +01:00
|
|
|
class CMakeProjectPluginPrivate : public QObject
|
2018-02-09 15:35:02 +01:00
|
|
|
{
|
|
|
|
|
public:
|
2023-08-23 10:16:28 +02:00
|
|
|
// This can't be stand-alone yet as it registers in the plugin object pool
|
|
|
|
|
CMakeToolManager cmakeToolManager;
|
2019-03-19 15:36:07 +01:00
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
ParameterAction buildTargetContextAction{
|
2022-09-29 15:26:31 +02:00
|
|
|
Tr::tr("Build"),
|
|
|
|
|
Tr::tr("Build \"%1\""),
|
2019-10-25 09:55:32 +02:00
|
|
|
ParameterAction::AlwaysEnabled/*handled manually*/
|
|
|
|
|
};
|
|
|
|
|
|
2018-02-09 15:35:02 +01:00
|
|
|
CMakeSettingsPage settingsPage;
|
2019-10-25 09:55:32 +02:00
|
|
|
|
2018-02-09 15:35:02 +01:00
|
|
|
CMakeManager manager;
|
|
|
|
|
CMakeBuildStepFactory buildStepFactory;
|
|
|
|
|
CMakeBuildConfigurationFactory buildConfigFactory;
|
|
|
|
|
CMakeEditorFactory editorFactor;
|
2022-12-09 18:44:42 +01:00
|
|
|
CMakeInstallStepFactory installStepFactory;
|
2023-04-24 21:03:18 +02:00
|
|
|
CMakeBuildTargetFilter cMakeBuildTargetFilter;
|
|
|
|
|
CMakeOpenTargetFilter cMakeOpenTargetFilter;
|
2019-03-14 09:17:59 +01:00
|
|
|
|
2022-11-21 00:10:25 +01:00
|
|
|
CMakeFormatter cmakeFormatter;
|
2018-02-09 15:35:02 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
CMakeProjectPlugin::~CMakeProjectPlugin()
|
|
|
|
|
{
|
|
|
|
|
delete d;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-20 12:28:36 +01:00
|
|
|
void CMakeProjectPlugin::initialize()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2018-02-09 15:35:02 +01:00
|
|
|
d = new CMakeProjectPluginPrivate;
|
|
|
|
|
|
2020-04-07 14:44:22 +02:00
|
|
|
const Context projectContext{CMakeProjectManager::Constants::CMAKE_PROJECT_ID};
|
2016-11-14 15:18:25 +01:00
|
|
|
|
2022-07-07 20:44:24 +02:00
|
|
|
FileIconProvider::registerIconOverlayForSuffix(Constants::Icons::FILE_OVERLAY, "cmake");
|
|
|
|
|
FileIconProvider::registerIconOverlayForFilename(Constants::Icons::FILE_OVERLAY,
|
2019-10-25 09:55:32 +02:00
|
|
|
"CMakeLists.txt");
|
2016-11-09 14:25:30 +01:00
|
|
|
|
2017-04-24 15:52:04 +02:00
|
|
|
TextEditor::SnippetProvider::registerGroup(Constants::CMAKE_SNIPPETS_GROUP_ID,
|
2022-09-29 15:26:31 +02:00
|
|
|
Tr::tr("CMake", "SnippetProvider"));
|
2020-04-07 14:44:22 +02:00
|
|
|
ProjectManager::registerProjectType<CMakeProject>(Constants::CMAKE_PROJECT_MIMETYPE);
|
2017-03-03 18:16:34 +01:00
|
|
|
|
2016-11-14 15:18:25 +01:00
|
|
|
//register actions
|
2019-10-25 09:55:32 +02:00
|
|
|
Command *command = ActionManager::registerAction(&d->buildTargetContextAction,
|
2020-04-07 14:44:22 +02:00
|
|
|
Constants::BUILD_TARGET_CONTEXT_MENU,
|
|
|
|
|
projectContext);
|
2016-11-14 15:18:25 +01:00
|
|
|
command->setAttribute(Command::CA_Hide);
|
|
|
|
|
command->setAttribute(Command::CA_UpdateText);
|
2019-10-25 09:55:32 +02:00
|
|
|
command->setDescription(d->buildTargetContextAction.text());
|
|
|
|
|
|
|
|
|
|
ActionManager::actionContainer(ProjectExplorer::Constants::M_SUBPROJECTCONTEXT)
|
|
|
|
|
->addAction(command, ProjectExplorer::Constants::G_PROJECT_BUILD);
|
2016-11-14 15:18:25 +01:00
|
|
|
|
|
|
|
|
// Wire up context menu updates:
|
|
|
|
|
connect(ProjectTree::instance(), &ProjectTree::currentNodeChanged,
|
|
|
|
|
this, &CMakeProjectPlugin::updateContextActions);
|
2015-02-24 21:57:00 +01:00
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
connect(&d->buildTargetContextAction, &ParameterAction::triggered, this, [] {
|
|
|
|
|
if (auto bs = qobject_cast<CMakeBuildSystem *>(ProjectTree::currentBuildSystem())) {
|
|
|
|
|
auto targetNode = dynamic_cast<const CMakeTargetNode *>(ProjectTree::currentNode());
|
|
|
|
|
bs->buildCMakeTarget(targetNode ? targetNode->displayName() : QString());
|
|
|
|
|
}
|
|
|
|
|
});
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeProjectPlugin::extensionsInitialized()
|
|
|
|
|
{
|
2022-09-29 10:11:28 +02:00
|
|
|
// Delay the restoration to allow the devices to load first.
|
|
|
|
|
QTimer::singleShot(0, this, [] { CMakeToolManager::restoreCMakeTools(); });
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2016-11-14 15:18:25 +01:00
|
|
|
|
2021-06-18 08:46:38 +02:00
|
|
|
void CMakeProjectPlugin::updateContextActions(Node *node)
|
2016-11-14 15:18:25 +01:00
|
|
|
{
|
2021-06-18 08:46:38 +02:00
|
|
|
auto targetNode = dynamic_cast<const CMakeTargetNode *>(node);
|
2016-12-08 22:31:43 +01:00
|
|
|
const QString targetDisplayName = targetNode ? targetNode->displayName() : QString();
|
2016-11-14 15:18:25 +01:00
|
|
|
|
|
|
|
|
// Build Target:
|
2019-10-25 09:55:32 +02:00
|
|
|
d->buildTargetContextAction.setParameter(targetDisplayName);
|
|
|
|
|
d->buildTargetContextAction.setEnabled(targetNode);
|
|
|
|
|
d->buildTargetContextAction.setVisible(targetNode);
|
2016-11-14 15:18:25 +01:00
|
|
|
}
|
2018-02-09 15:35:02 +01:00
|
|
|
|
2022-09-29 15:26:31 +02:00
|
|
|
} // CMakeProjectManager::Internal
|
2018-02-09 15:35:02 +01:00
|
|
|
|