summaryrefslogtreecommitdiff
path: root/src/plugins/cmakeprojectmanager
diff options
context:
space:
mode:
authorDaniel Teske <daniel.teske@theqtcompany.com>2015-07-14 13:10:18 +0200
committerDaniel Teske <daniel.teske@theqtcompany.com>2015-08-31 14:57:36 +0000
commitcea36f137676224132ac9389ae0aa773faa7beb8 (patch)
tree050e5a6fab74ba0594a6fdb1f86aab3fe96f156d /src/plugins/cmakeprojectmanager
parent513c4e0a892d33e6754dcb869fe4c01675e7e96c (diff)
downloadqt-creator-cea36f137676224132ac9389ae0aa773faa7beb8.tar.gz
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>
Diffstat (limited to 'src/plugins/cmakeprojectmanager')
-rw-r--r--src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp23
-rw-r--r--src/plugins/cmakeprojectmanager/cmakeprojectmanager.h3
2 files changed, 15 insertions, 11 deletions
diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp
index 476d3da3d9..a50d483d24 100644
--- a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp
+++ b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp
@@ -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)
diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.h b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.h
index 6c50ea34cf..0d8af0b35c 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