Fix various context menu actions from project managers

The correct pattern is this: The actions in the build menu are supposed
to be for the startup project. They should use the global context and be
manually hidden/shown if the startup project changes.

This fixes a crash on assigning keyboard shortcut to the edit files
context menu action.

The slot connected assumed that the action could only be triggered via
the context menu. By using ProjectTree;:currentProject() the code now
works even if the project tree is not actually focused.

It also fixes that the "Run CMake" action was shown even in the build menu,
even though a non cmake project was the startup project.

Change-Id: I0bb8086d8b1078b4c71c3b5ba9d7f8596757e724
Task-number: QTCREATORBUG-14728
Task-number: QTCREATORBUG-14768
Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
This commit is contained in:
Daniel Teske
2015-07-14 13:10:18 +02:00
parent 513c4e0a89
commit cea36f1376
4 changed files with 18 additions and 24 deletions

View File

@@ -39,9 +39,11 @@
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/actionmanager/actioncontainer.h>
#include <projectexplorer/buildmanager.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/projecttree.h>
#include <projectexplorer/session.h>
#include <utils/synchronousprocess.h>
@@ -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<CMakeProject *>(ProjectExplorer::SessionManager::startupProject());
m_runCMakeAction->setVisible(project && !ProjectExplorer::BuildManager::isBuilding(project));
}
void CMakeManager::runCMake(ProjectExplorer::Project *project)