forked from qt-creator/qt-creator
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:
@@ -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)
|
||||
|
@@ -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
|
||||
|
@@ -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)
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user