diff options
author | Tobias Hunger <tobias.hunger@qt.io> | 2016-11-14 15:18:25 +0100 |
---|---|---|
committer | Tim Jenssen <tim.jenssen@qt.io> | 2016-11-15 09:30:59 +0000 |
commit | 53d45de8a0d5d9efacbf208f25ba75b47414838e (patch) | |
tree | 92b49e44c3c78ce0ce94110dc64a06900241f5cb | |
parent | 6fe3d3bde9eed4027b37c88c7d75a62c89ce25f6 (diff) |
CMake: Allow to build target from context menu of CMakeTargetNodes
Change-Id: I0457abd6dabea1699272482eb5f7fbb3ca097310
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
8 files changed, 115 insertions, 7 deletions
diff --git a/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp b/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp index e3770a989ff..407019f4195 100644 --- a/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp +++ b/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp @@ -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()) diff --git a/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.h b/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.h index 3ef255907a5..04a4f096816 100644 --- a/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.h +++ b/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.h @@ -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); diff --git a/src/plugins/cmakeprojectmanager/cmakebuildstep.cpp b/src/plugins/cmakeprojectmanager/cmakebuildstep.cpp index accdfc84034..940789a0a71 100644 --- a/src/plugins/cmakeprojectmanager/cmakebuildstep.cpp +++ b/src/plugins/cmakeprojectmanager/cmakebuildstep.cpp @@ -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) diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.cpp b/src/plugins/cmakeprojectmanager/cmakeproject.cpp index 5cb22147f2e..ddf538983af 100644 --- a/src/plugins/cmakeprojectmanager/cmakeproject.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeproject.cpp @@ -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; diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.h b/src/plugins/cmakeprojectmanager/cmakeproject.h index eab29256775..52b73edc14c 100644 --- a/src/plugins/cmakeprojectmanager/cmakeproject.h +++ b/src/plugins/cmakeprojectmanager/cmakeproject.h @@ -96,6 +96,9 @@ public: void runCMake(); + // Context menu actions: + void buildCMakeTarget(const QString &buildTarget); + signals: /// emitted when cmake is running: void parsingStarted(); diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectconstants.h b/src/plugins/cmakeprojectmanager/cmakeprojectconstants.h index 94abe1c1fdc..6d0bb31f4da 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprojectconstants.h +++ b/src/plugins/cmakeprojectmanager/cmakeprojectconstants.h @@ -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 diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp b/src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp index cffcc282a62..6febf97b001 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp @@ -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()); }); + } +} diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectplugin.h b/src/plugins/cmakeprojectmanager/cmakeprojectplugin.h index 73d4df1d6d6..961c965983e 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprojectplugin.h +++ b/src/plugins/cmakeprojectmanager/cmakeprojectplugin.h @@ -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 |