aboutsummaryrefslogtreecommitdiffstats
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
parent513c4e0a892d33e6754dcb869fe4c01675e7e96c (diff)
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>
-rw-r--r--src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp23
-rw-r--r--src/plugins/cmakeprojectmanager/cmakeprojectmanager.h3
-rw-r--r--src/plugins/genericprojectmanager/genericprojectplugin.cpp11
-rw-r--r--src/plugins/genericprojectmanager/genericprojectplugin.h5
4 files changed, 18 insertions, 24 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
diff --git a/src/plugins/genericprojectmanager/genericprojectplugin.cpp b/src/plugins/genericprojectmanager/genericprojectplugin.cpp
index 2a595b4d26..f3c249877c 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<GenericProject *>(m_contextMenuProject);
+ auto genericProject = qobject_cast<GenericProject *>(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 d87478c802..1f4b30991d 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