diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp index 476d3da3d94..a50d483d24d 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp @@ -39,9 +39,11 @@ #include #include #include +#include #include #include #include +#include #include @@ -52,10 +54,6 @@ using namespace CMakeProjectManager::Internal; CMakeManager::CMakeManager() { - ProjectExplorer::ProjectTree *tree = ProjectExplorer::ProjectTree::instance(); - connect(tree, &ProjectExplorer::ProjectTree::aboutToShowContextMenu, - this, &CMakeManager::updateContextMenu); - Core::ActionContainer *mbuild = Core::ActionManager::actionContainer(ProjectExplorer::Constants::M_BUILDPROJECT); Core::ActionContainer *mproject = @@ -64,14 +62,15 @@ CMakeManager::CMakeManager() Core::ActionManager::actionContainer(ProjectExplorer::Constants::M_SUBPROJECTCONTEXT); const Core::Context projectContext(CMakeProjectManager::Constants::PROJECTCONTEXT); + const Core::Context globalcontext(Core::Constants::C_GLOBAL); m_runCMakeAction = new QAction(QIcon(), tr("Run CMake"), this); Core::Command *command = Core::ActionManager::registerAction(m_runCMakeAction, - Constants::RUNCMAKE, projectContext); + Constants::RUNCMAKE, globalcontext); command->setAttribute(Core::Command::CA_Hide); mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_DEPLOY); connect(m_runCMakeAction, &QAction::triggered, [this]() { - runCMake(ProjectExplorer::ProjectTree::currentProject()); + runCMake(ProjectExplorer::SessionManager::startupProject()); }); m_runCMakeActionContextMenu = new QAction(QIcon(), tr("Run CMake"), this); @@ -81,14 +80,20 @@ CMakeManager::CMakeManager() mproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_BUILD); msubproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_BUILD); connect(m_runCMakeActionContextMenu, &QAction::triggered, [this]() { - runCMake(m_contextProject); + runCMake(ProjectExplorer::ProjectTree::currentProject()); }); + connect(ProjectExplorer::SessionManager::instance(), &ProjectExplorer::SessionManager::startupProjectChanged, + this, &CMakeManager::updateRunCmakeAction); + connect(ProjectExplorer::BuildManager::instance(), &ProjectExplorer::BuildManager::buildStateChanged, + this, &CMakeManager::updateRunCmakeAction); + } -void CMakeManager::updateContextMenu(ProjectExplorer::Project *project, ProjectExplorer::Node *) +void CMakeManager::updateRunCmakeAction() { - m_contextProject = project; + auto project = qobject_cast(ProjectExplorer::SessionManager::startupProject()); + m_runCMakeAction->setVisible(project && !ProjectExplorer::BuildManager::isBuilding(project)); } void CMakeManager::runCMake(ProjectExplorer::Project *project) diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.h b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.h index 6c50ea34cf9..0d8af0b35c2 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.h +++ b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.h @@ -69,14 +69,13 @@ public: static QString findCbpFile(const QDir &); private: - void updateContextMenu(ProjectExplorer::Project *project, ProjectExplorer::Node *node); + void updateRunCmakeAction(); void runCMake(ProjectExplorer::Project *project); private: CMakeSettingsPage *m_settingsPage; QAction *m_runCMakeAction; QAction *m_runCMakeActionContextMenu; - ProjectExplorer::Project *m_contextProject; }; } // namespace Internal diff --git a/src/plugins/genericprojectmanager/genericprojectplugin.cpp b/src/plugins/genericprojectmanager/genericprojectplugin.cpp index 2a595b4d26a..f3c249877c9 100644 --- a/src/plugins/genericprojectmanager/genericprojectplugin.cpp +++ b/src/plugins/genericprojectmanager/genericprojectplugin.cpp @@ -58,10 +58,6 @@ using namespace ProjectExplorer; namespace GenericProjectManager { namespace Internal { -GenericProjectPlugin::GenericProjectPlugin() - : m_contextMenuProject(0) -{ } - bool GenericProjectPlugin::initialize(const QStringList &, QString *errorMessage) { Q_UNUSED(errorMessage) @@ -85,15 +81,14 @@ bool GenericProjectPlugin::initialize(const QStringList &, QString *errorMessage connect(editFilesAction, &QAction::triggered, this, &GenericProjectPlugin::editFiles); - connect(ProjectTree::instance(), &ProjectTree::aboutToShowContextMenu, - [this] (Project *project, Node *) { m_contextMenuProject = project; }); - return true; } void GenericProjectPlugin::editFiles() { - GenericProject *genericProject = static_cast(m_contextMenuProject); + auto genericProject = qobject_cast(ProjectTree::currentProject()); + if (!genericProject) + return; SelectableFilesDialogEditFiles sfd(genericProject->projectFilePath().toFileInfo().path(), genericProject->files(), ICore::mainWindow()); if (sfd.exec() == QDialog::Accepted) diff --git a/src/plugins/genericprojectmanager/genericprojectplugin.h b/src/plugins/genericprojectmanager/genericprojectplugin.h index d87478c8023..1f4b30991d4 100644 --- a/src/plugins/genericprojectmanager/genericprojectplugin.h +++ b/src/plugins/genericprojectmanager/genericprojectplugin.h @@ -50,8 +50,6 @@ class GenericProjectPlugin : public ExtensionSystem::IPlugin Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "GenericProjectManager.json") public: - GenericProjectPlugin(); - bool initialize(const QStringList &arguments, QString *errorString); void extensionsInitialized() {} @@ -64,9 +62,6 @@ private slots: void test_mixed1(); void test_mixed2(); #endif // WITH_TESTS - -private: - ProjectExplorer::Project *m_contextMenuProject; }; } // namespace Internal