forked from qt-creator/qt-creator
CMake: Split big plugin tests into smaller pieces
... which can then live closer to the tested code. Change-Id: Icd975a76424ea2258c1bb93afdbaabdf1959340a Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include "cmakeprojectplugin.h"
|
||||
|
||||
#include "cmakebuildconfiguration.h"
|
||||
#include "cmakebuildstep.h"
|
||||
#include "cmakebuildsystem.h"
|
||||
@@ -10,8 +8,10 @@
|
||||
#include "cmakeformatter.h"
|
||||
#include "cmakeinstallstep.h"
|
||||
#include "cmakelocatorfilter.h"
|
||||
#include "cmakeparser.h"
|
||||
#include "cmakeproject.h"
|
||||
#include "cmakeprojectconstants.h"
|
||||
#include "cmakeprojectimporter.h"
|
||||
#include "cmakeprojectmanager.h"
|
||||
#include "cmakeprojectmanagertr.h"
|
||||
#include "cmakeprojectnodes.h"
|
||||
@@ -21,6 +21,8 @@
|
||||
#include <coreplugin/actionmanager/actioncontainer.h>
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
|
||||
#include <extensionsystem/iplugin.h>
|
||||
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
#include <projectexplorer/projectmanager.h>
|
||||
#include <projectexplorer/projecttree.h>
|
||||
@@ -66,64 +68,79 @@ public:
|
||||
CMakeFormatter cmakeFormatter;
|
||||
};
|
||||
|
||||
CMakeProjectPlugin::~CMakeProjectPlugin()
|
||||
class CMakeProjectPlugin final : public ExtensionSystem::IPlugin
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
Q_OBJECT
|
||||
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "CMakeProjectManager.json")
|
||||
|
||||
void CMakeProjectPlugin::initialize()
|
||||
{
|
||||
d = new CMakeProjectPluginPrivate;
|
||||
~CMakeProjectPlugin()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
const Context projectContext{CMakeProjectManager::Constants::CMAKE_PROJECT_ID};
|
||||
void initialize() final
|
||||
{
|
||||
d = new CMakeProjectPluginPrivate;
|
||||
|
||||
FileIconProvider::registerIconOverlayForSuffix(Constants::Icons::FILE_OVERLAY, "cmake");
|
||||
FileIconProvider::registerIconOverlayForFilename(Constants::Icons::FILE_OVERLAY,
|
||||
"CMakeLists.txt");
|
||||
#ifdef WITH_TESTS
|
||||
addTestCreator(createCMakeConfigTest);
|
||||
addTestCreator(createCMakeParserTest);
|
||||
addTestCreator(createCMakeProjectImporterTest);
|
||||
#endif
|
||||
|
||||
TextEditor::SnippetProvider::registerGroup(Constants::CMAKE_SNIPPETS_GROUP_ID,
|
||||
Tr::tr("CMake", "SnippetProvider"));
|
||||
ProjectManager::registerProjectType<CMakeProject>(Utils::Constants::CMAKE_PROJECT_MIMETYPE);
|
||||
const Context projectContext{CMakeProjectManager::Constants::CMAKE_PROJECT_ID};
|
||||
|
||||
//register actions
|
||||
Command *command = ActionManager::registerAction(&d->buildTargetContextAction,
|
||||
Constants::BUILD_TARGET_CONTEXT_MENU,
|
||||
projectContext);
|
||||
command->setAttribute(Command::CA_Hide);
|
||||
command->setAttribute(Command::CA_UpdateText);
|
||||
command->setDescription(d->buildTargetContextAction.text());
|
||||
FileIconProvider::registerIconOverlayForSuffix(Constants::Icons::FILE_OVERLAY, "cmake");
|
||||
FileIconProvider::registerIconOverlayForFilename(Constants::Icons::FILE_OVERLAY,
|
||||
"CMakeLists.txt");
|
||||
|
||||
ActionManager::actionContainer(ProjectExplorer::Constants::M_SUBPROJECTCONTEXT)
|
||||
TextEditor::SnippetProvider::registerGroup(Constants::CMAKE_SNIPPETS_GROUP_ID,
|
||||
Tr::tr("CMake", "SnippetProvider"));
|
||||
ProjectManager::registerProjectType<CMakeProject>(Utils::Constants::CMAKE_PROJECT_MIMETYPE);
|
||||
|
||||
//register actions
|
||||
Command *command = ActionManager::registerAction(&d->buildTargetContextAction,
|
||||
Constants::BUILD_TARGET_CONTEXT_MENU,
|
||||
projectContext);
|
||||
command->setAttribute(Command::CA_Hide);
|
||||
command->setAttribute(Command::CA_UpdateText);
|
||||
command->setDescription(d->buildTargetContextAction.text());
|
||||
|
||||
ActionManager::actionContainer(ProjectExplorer::Constants::M_SUBPROJECTCONTEXT)
|
||||
->addAction(command, ProjectExplorer::Constants::G_PROJECT_BUILD);
|
||||
|
||||
// Wire up context menu updates:
|
||||
connect(ProjectTree::instance(), &ProjectTree::currentNodeChanged,
|
||||
this, &CMakeProjectPlugin::updateContextActions);
|
||||
// Wire up context menu updates:
|
||||
connect(ProjectTree::instance(), &ProjectTree::currentNodeChanged,
|
||||
this, &CMakeProjectPlugin::updateContextActions);
|
||||
|
||||
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());
|
||||
}
|
||||
});
|
||||
}
|
||||
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());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void CMakeProjectPlugin::extensionsInitialized()
|
||||
{
|
||||
// Delay the restoration to allow the devices to load first.
|
||||
QTimer::singleShot(0, this, [] { CMakeToolManager::restoreCMakeTools(); });
|
||||
}
|
||||
void extensionsInitialized() final
|
||||
{
|
||||
// Delay the restoration to allow the devices to load first.
|
||||
QTimer::singleShot(0, this, [] { CMakeToolManager::restoreCMakeTools(); });
|
||||
}
|
||||
|
||||
void CMakeProjectPlugin::updateContextActions(Node *node)
|
||||
{
|
||||
auto targetNode = dynamic_cast<const CMakeTargetNode *>(node);
|
||||
const QString targetDisplayName = targetNode ? targetNode->displayName() : QString();
|
||||
void updateContextActions(ProjectExplorer::Node *node)
|
||||
{
|
||||
auto targetNode = dynamic_cast<const CMakeTargetNode *>(node);
|
||||
const QString targetDisplayName = targetNode ? targetNode->displayName() : QString();
|
||||
|
||||
// Build Target:
|
||||
d->buildTargetContextAction.setParameter(targetDisplayName);
|
||||
d->buildTargetContextAction.setEnabled(targetNode);
|
||||
d->buildTargetContextAction.setVisible(targetNode);
|
||||
}
|
||||
// Build Target:
|
||||
d->buildTargetContextAction.setParameter(targetDisplayName);
|
||||
d->buildTargetContextAction.setEnabled(targetNode);
|
||||
d->buildTargetContextAction.setVisible(targetNode);
|
||||
}
|
||||
|
||||
class CMakeProjectPluginPrivate *d = nullptr;
|
||||
};
|
||||
|
||||
} // CMakeProjectManager::Internal
|
||||
|
||||
#include "cmakeprojectplugin.moc"
|
||||
|
||||
Reference in New Issue
Block a user