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 /src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp | |
parent | 6fe3d3bde9eed4027b37c88c7d75a62c89ce25f6 (diff) | |
download | qt-creator-53d45de8a0d5d9efacbf208f25ba75b47414838e.tar.gz |
CMake: Allow to build target from context menu of CMakeTargetNodes
Change-Id: I0457abd6dabea1699272482eb5f7fbb3ca097310
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
Diffstat (limited to 'src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp')
-rw-r--r-- | src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp | 55 |
1 files changed, 52 insertions, 3 deletions
diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp b/src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp index cffcc282a6..6febf97b00 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()); }); + } +} |