Commit 53d45de8 authored by Tobias Hunger's avatar Tobias Hunger Committed by Tim Jenssen

CMake: Allow to build target from context menu of CMakeTargetNodes

Change-Id: I0457abd6dabea1699272482eb5f7fbb3ca097310
Reviewed-by: Tim Jenssen's avatarTim Jenssen <tim.jenssen@qt.io>
parent 6fe3d3bd
......@@ -37,8 +37,10 @@
#include <coreplugin/documentmanager.h>
#include <coreplugin/icore.h>
#include <projectexplorer/buildmanager.h>
#include <projectexplorer/buildsteplist.h>
#include <projectexplorer/kit.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/projectmacroexpander.h>
#include <projectexplorer/target.h>
......@@ -230,6 +232,28 @@ FileName CMakeBuildConfiguration::shadowBuildDirectory(const FileName &projectFi
return FileName::fromUserInput(projectDir.absoluteFilePath(buildPath));
}
void CMakeBuildConfiguration::buildTarget(const QString &buildTarget)
{
const Core::Id buildStep = ProjectExplorer::Constants::BUILDSTEPS_BUILD;
const QString name = ProjectExplorer::ProjectExplorerPlugin::displayNameForStepId(buildStep);
CMakeBuildStep *cmBs
= qobject_cast<CMakeBuildStep *>(Utils::findOrDefault(stepList(buildStep)->steps(),
[](const ProjectExplorer::BuildStep *bs) {
return bs->id() == Constants::CMAKE_BUILD_STEP_ID;
}));
QString originalBuildTarget;
if (cmBs) {
originalBuildTarget = cmBs->buildTarget();
cmBs->setBuildTarget(buildTarget);
}
BuildManager::buildList(stepList(buildStep), name);
if (cmBs)
cmBs->setBuildTarget(originalBuildTarget);
}
QList<ConfigModel::DataItem> CMakeBuildConfiguration::completeCMakeConfiguration() const
{
if (!m_buildDirManager || m_buildDirManager->isParsing())
......
......@@ -92,6 +92,9 @@ public:
shadowBuildDirectory(const Utils::FileName &projectFilePath, const ProjectExplorer::Kit *k,
const QString &bcName, BuildConfiguration::BuildType buildType);
// Context menu action:
void buildTarget(const QString &buildTarget);
signals:
void errorOccured(const QString &message);
void warningOccured(const QString &message);
......
......@@ -62,7 +62,6 @@ using namespace CMakeProjectManager::Internal;
using namespace ProjectExplorer;
namespace {
const char MS_ID[] = "CMakeProjectManager.MakeStep";
const char CLEAN_KEY[] = "CMakeProjectManager.MakeStep.Clean"; // Obsolete since QtC 3.7
const char BUILD_TARGETS_KEY[] = "CMakeProjectManager.MakeStep.BuildTargets";
const char TOOL_ARGUMENTS_KEY[] = "CMakeProjectManager.MakeStep.AdditionalArguments";
......@@ -75,7 +74,8 @@ static bool isCurrentExecutableTarget(const QString &target)
return target == QLatin1String(ADD_RUNCONFIGURATION_TEXT);
}
CMakeBuildStep::CMakeBuildStep(BuildStepList *bsl) : AbstractProcessStep(bsl, Core::Id(MS_ID))
CMakeBuildStep::CMakeBuildStep(BuildStepList *bsl) :
AbstractProcessStep(bsl, Core::Id(Constants::CMAKE_BUILD_STEP_ID))
{
ctor(bsl);
}
......@@ -99,7 +99,7 @@ void CMakeBuildStep::ctor(BuildStepList *bsl)
m_ninjaProgress = QRegExp(QLatin1String("^\\[\\s*(\\d*)/\\s*(\\d*)"));
m_ninjaProgressString = QLatin1String("[%f/%t "); // ninja: [33/100
//: Default display name for the cmake make step.
setDefaultDisplayName(tr("Make"));
setDefaultDisplayName(tr("CMake Build"));
auto bc = qobject_cast<CMakeBuildConfiguration *>(bsl->parent());
if (!bc) {
......@@ -526,7 +526,8 @@ QList<BuildStepInfo> CMakeBuildStepFactory::availableSteps(BuildStepList *parent
if (parent->target()->project()->id() != Constants::CMAKEPROJECT_ID)
return {};
return {{ MS_ID, tr("Build", "Display name for CMakeProjectManager::CMakeBuildStep id.") }};
return {{ Constants::CMAKE_BUILD_STEP_ID,
tr("Build", "Display name for CMakeProjectManager::CMakeBuildStep id.") }};
}
BuildStep *CMakeBuildStepFactory::create(BuildStepList *parent, Core::Id id)
......
......@@ -216,6 +216,15 @@ void CMakeProject::runCMake()
bc->runCMake();
}
void CMakeProject::buildCMakeTarget(const QString &buildTarget)
{
QTC_ASSERT(!buildTarget.isEmpty(), return);
Target *t = activeTarget();
auto bc = qobject_cast<CMakeBuildConfiguration *>(t ? t->activeBuildConfiguration() : nullptr);
if (bc)
bc->buildTarget(buildTarget);
}
QList<CMakeBuildTarget> CMakeProject::buildTargets() const
{
CMakeBuildConfiguration *bc = nullptr;
......
......@@ -96,6 +96,9 @@ public:
void runCMake();
// Context menu actions:
void buildCMakeTarget(const QString &buildTarget);
signals:
/// emitted when cmake is running:
void parsingStarted();
......
......@@ -57,5 +57,11 @@ const char CMAKE_SNIPPETS_GROUP_ID[] = "CMake";
// Icons
const char FILEOVERLAY_CMAKE[] = ":/cmakeproject/images/fileoverlay_cmake.png";
// Actions
const char BUILD_TARGET_CONTEXTMENU[] = "CMake.BuildTargetContextMenu";
// Build Step
const char CMAKE_BUILD_STEP_ID[] = "CMakeProjectManager.MakeStep";
} // namespace Constants
} // namespace CMakeProjectManager
......@@ -27,7 +27,10 @@
#include "cmakeeditor.h"
#include "cmakebuildstep.h"
#include "cmakeproject.h"
#include "cmakeprojectconstants.h"
#include "cmakeprojectmanager.h"
#include "cmakeprojectnodes.h"
#include "cmakebuildconfiguration.h"
#include "cmakerunconfiguration.h"
#include "cmakesnippetprovider.h"
......@@ -37,16 +40,25 @@
#include "cmaketoolmanager.h"
#include "cmakekitinformation.h"
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/fileiconprovider.h>
#include <projectexplorer/kitmanager.h>
#include <projectexplorer/projecttree.h>
#include <utils/mimetypes/mimedatabase.h>
#include <utils/parameteraction.h>
using namespace CMakeProjectManager::Internal;
using namespace Core;
using namespace ProjectExplorer;
bool CMakeProjectPlugin::initialize(const QStringList & /*arguments*/, QString *errorMessage)
{
Q_UNUSED(errorMessage)
const Context projectContext(Constants::PROJECTCONTEXT);
Utils::MimeDatabase::addMimeTypes(QLatin1String(":cmakeproject/CMakeProjectManager.mimetypes.xml"));
Core::FileIconProvider::registerIconOverlayForSuffix(Constants::FILEOVERLAY_CMAKE, "cmake");
......@@ -63,9 +75,29 @@ bool CMakeProjectPlugin::initialize(const QStringList & /*arguments*/, QString *
new CMakeToolManager(this);
ProjectExplorer::KitManager::registerKitInformation(new CMakeKitInformation);
ProjectExplorer::KitManager::registerKitInformation(new CMakeGeneratorKitInformation);
ProjectExplorer::KitManager::registerKitInformation(new CMakeConfigurationKitInformation);
KitManager::registerKitInformation(new CMakeKitInformation);
KitManager::registerKitInformation(new CMakeGeneratorKitInformation);
KitManager::registerKitInformation(new CMakeConfigurationKitInformation);
//menus
ActionContainer *msubproject =
ActionManager::actionContainer(ProjectExplorer::Constants::M_SUBPROJECTCONTEXT);
//register actions
Command *command = nullptr;
m_buildTargetContextAction = new Utils::ParameterAction(tr("Build"), tr("Build \"%1\""),
Utils::ParameterAction::AlwaysEnabled/*handled manually*/,
this);
command = ActionManager::registerAction(m_buildTargetContextAction, Constants::BUILD_TARGET_CONTEXTMENU, projectContext);
command->setAttribute(Command::CA_Hide);
command->setAttribute(Command::CA_UpdateText);
command->setDescription(m_buildTargetContextAction->text());
msubproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_BUILD);
// Wire up context menu updates:
connect(ProjectTree::instance(), &ProjectTree::currentNodeChanged,
this, &CMakeProjectPlugin::updateContextActions);
return true;
}
......@@ -75,3 +107,20 @@ void CMakeProjectPlugin::extensionsInitialized()
//restore the cmake tools before loading the kits
CMakeToolManager::restoreCMakeTools();
}
void CMakeProjectPlugin::updateContextActions(ProjectExplorer::Node *node,
ProjectExplorer::Project *project)
{
CMakeTargetNode *targetNode = dynamic_cast<CMakeTargetNode *>(node);
CMakeProject *cmProject = dynamic_cast<CMakeProject *>(project);
// Build Target:
disconnect(m_buildTargetContextAction);
m_buildTargetContextAction->setParameter(targetNode ? targetNode->displayName() : QString());
m_buildTargetContextAction->setEnabled(targetNode);
m_buildTargetContextAction->setVisible(targetNode);
if (cmProject && targetNode) {
connect(m_buildTargetContextAction, &Utils::ParameterAction::triggered,
cmProject, [cmProject, targetNode]() { cmProject->buildCMakeTarget(targetNode->displayName()); });
}
}
......@@ -29,8 +29,16 @@
#include <QObject>
namespace ProjectExplorer {
class Node;
class Project;
} // namespace ProjectExplorer
namespace Utils { class ParameterAction; }
namespace CMakeProjectManager {
class CMakeProject;
class CMakeToolManager;
namespace Internal {
......@@ -53,6 +61,11 @@ private slots:
void testCMakeSplitValue_data();
void testCMakeSplitValue();
#endif
private:
void updateContextActions(ProjectExplorer::Node *node, ProjectExplorer::Project *project);
Utils::ParameterAction *m_buildTargetContextAction;
};
} // namespace Internal
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment