forked from qt-creator/qt-creator
ProjectExplorer: Remove arguments from node change signals
This discourages storing the pointers needlessly. The items are still easy accessible by the static ProjectTree::currentNode() Change-Id: I3c0cd019e9fdc382afacbc9d9de3b97d5f58ae1e Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
@@ -108,9 +108,10 @@ void CMakeProjectPlugin::extensionsInitialized()
|
||||
CMakeToolManager::restoreCMakeTools();
|
||||
}
|
||||
|
||||
void CMakeProjectPlugin::updateContextActions(ProjectExplorer::Node *node,
|
||||
ProjectExplorer::Project *project)
|
||||
void CMakeProjectPlugin::updateContextActions()
|
||||
{
|
||||
Project *project = ProjectTree::currentProject();
|
||||
Node *node = ProjectTree::currentNode();
|
||||
CMakeTargetNode *targetNode = dynamic_cast<CMakeTargetNode *>(node);
|
||||
// as targetNode can be deleted while the menu is open, we keep only the
|
||||
const QString targetDisplayName = targetNode ? targetNode->displayName() : QString();
|
||||
|
||||
@@ -29,11 +29,6 @@
|
||||
|
||||
#include <QObject>
|
||||
|
||||
namespace ProjectExplorer {
|
||||
class Node;
|
||||
class Project;
|
||||
} // namespace ProjectExplorer
|
||||
|
||||
namespace Utils { class ParameterAction; }
|
||||
|
||||
namespace CMakeProjectManager {
|
||||
@@ -69,7 +64,7 @@ private slots:
|
||||
#endif
|
||||
|
||||
private:
|
||||
void updateContextActions(ProjectExplorer::Node *node, ProjectExplorer::Project *project);
|
||||
void updateContextActions();
|
||||
|
||||
Utils::ParameterAction *m_buildTargetContextAction = nullptr;
|
||||
QMetaObject::Connection m_actionConnect;
|
||||
|
||||
@@ -222,10 +222,9 @@ void ProjectTree::update(Node *node, Project *project)
|
||||
|
||||
if (changedNode) {
|
||||
m_currentNode = node;
|
||||
emit currentNodeChanged(m_currentNode, project);
|
||||
emit currentNodeChanged();
|
||||
}
|
||||
|
||||
|
||||
if (changedProject) {
|
||||
emit currentProjectChanged(m_currentProject);
|
||||
sessionChanged();
|
||||
|
||||
@@ -64,7 +64,7 @@ public:
|
||||
|
||||
signals:
|
||||
void currentProjectChanged(ProjectExplorer::Project *project);
|
||||
void currentNodeChanged(ProjectExplorer::Node *node, ProjectExplorer::Project *project);
|
||||
void currentNodeChanged();
|
||||
|
||||
// Emitted whenever the model needs to send a update signal.
|
||||
void nodeUpdated(ProjectExplorer::Node *node);
|
||||
|
||||
@@ -180,7 +180,7 @@ bool QbsProjectManagerPlugin::initialize(const QStringList &arguments, QString *
|
||||
|
||||
// Connect
|
||||
connect(ProjectTree::instance(), &ProjectTree::currentNodeChanged,
|
||||
this, &QbsProjectManagerPlugin::nodeSelectionChanged);
|
||||
this, &QbsProjectManagerPlugin::updateContextActions);
|
||||
|
||||
connect(BuildManager::instance(), &BuildManager::buildStateChanged,
|
||||
this, &QbsProjectManagerPlugin::buildStateChanged);
|
||||
@@ -234,26 +234,19 @@ void QbsProjectManagerPlugin::projectWasRemoved()
|
||||
updateBuildActions();
|
||||
}
|
||||
|
||||
void QbsProjectManagerPlugin::nodeSelectionChanged(Node *node, Project *project)
|
||||
{
|
||||
m_selectedNode = node;
|
||||
m_selectedProject = qobject_cast<Internal::QbsProject *>(project);
|
||||
|
||||
updateContextActions();
|
||||
}
|
||||
|
||||
void QbsProjectManagerPlugin::updateContextActions()
|
||||
{
|
||||
bool isEnabled = !BuildManager::isBuilding(m_selectedProject)
|
||||
&& m_selectedProject && !m_selectedProject->isParsing()
|
||||
&& m_selectedNode && m_selectedNode->isEnabled();
|
||||
QbsProject *project = qobject_cast<Internal::QbsProject *>(ProjectTree::currentProject());
|
||||
Node *node = ProjectTree::currentNode();
|
||||
bool isEnabled = !BuildManager::isBuilding(project)
|
||||
&& project && !project->isParsing()
|
||||
&& node && node->isEnabled();
|
||||
|
||||
bool isFile = m_selectedProject && m_selectedNode && (m_selectedNode->nodeType() == NodeType::File);
|
||||
bool isProduct = m_selectedProject
|
||||
&& m_selectedNode
|
||||
&& dynamic_cast<QbsProductNode *>(m_selectedNode);
|
||||
QbsProjectNode *subproject = dynamic_cast<QbsProjectNode *>(m_selectedNode);
|
||||
bool isSubproject = m_selectedProject && subproject && subproject != m_selectedProject->rootProjectNode();
|
||||
bool isFile = project && node && (node->nodeType() == NodeType::File);
|
||||
bool isProduct = project && node
|
||||
&& dynamic_cast<QbsProductNode *>(node);
|
||||
QbsProjectNode *subproject = dynamic_cast<QbsProjectNode *>(node);
|
||||
bool isSubproject = project && subproject && subproject != project->rootProjectNode();
|
||||
|
||||
m_reparseQbsCtx->setEnabled(isEnabled);
|
||||
m_buildFileCtx->setEnabled(isEnabled && isFile);
|
||||
@@ -319,7 +312,7 @@ void QbsProjectManagerPlugin::buildStateChanged(Project *project)
|
||||
if (project == m_currentProject)
|
||||
updateReparseQbsAction();
|
||||
|
||||
if (project == m_selectedProject)
|
||||
if (project == ProjectTree::currentProject())
|
||||
updateContextActions();
|
||||
|
||||
m_editorNode = currentEditorNode();
|
||||
@@ -335,7 +328,7 @@ void QbsProjectManagerPlugin::parsingStateChanged()
|
||||
if (!project || project == m_currentProject)
|
||||
updateReparseQbsAction();
|
||||
|
||||
if (!project || project == m_selectedProject)
|
||||
if (!project || project == ProjectTree::currentProject())
|
||||
updateContextActions();
|
||||
|
||||
m_editorNode = currentEditorNode();
|
||||
@@ -354,10 +347,11 @@ void QbsProjectManagerPlugin::currentEditorChanged()
|
||||
|
||||
void QbsProjectManagerPlugin::buildFileContextMenu()
|
||||
{
|
||||
QTC_ASSERT(m_selectedNode, return);
|
||||
QTC_ASSERT(m_selectedProject, return);
|
||||
|
||||
buildSingleFile(m_selectedProject, m_selectedNode->filePath().toString());
|
||||
Node *node = ProjectTree::currentNode();
|
||||
QTC_ASSERT(node, return);
|
||||
QbsProject *project = dynamic_cast<QbsProject *>(ProjectTree::currentProject());
|
||||
QTC_ASSERT(project, return);
|
||||
buildSingleFile(project, node->filePath().toString());
|
||||
}
|
||||
|
||||
void QbsProjectManagerPlugin::buildFile()
|
||||
@@ -370,14 +364,15 @@ void QbsProjectManagerPlugin::buildFile()
|
||||
|
||||
void QbsProjectManagerPlugin::buildProductContextMenu()
|
||||
{
|
||||
QTC_ASSERT(m_selectedNode, return);
|
||||
QTC_ASSERT(m_selectedProject, return);
|
||||
Node *node = ProjectTree::currentNode();
|
||||
QTC_ASSERT(node, return);
|
||||
QbsProject *project = dynamic_cast<QbsProject *>(ProjectTree::currentProject());
|
||||
QTC_ASSERT(project, return);
|
||||
|
||||
const QbsProductNode * const productNode = dynamic_cast<QbsProductNode *>(m_selectedNode);
|
||||
const QbsProductNode * const productNode = dynamic_cast<QbsProductNode *>(node);
|
||||
QTC_ASSERT(productNode, return);
|
||||
|
||||
buildProducts(m_selectedProject,
|
||||
QStringList(QbsProject::uniqueProductName(productNode->qbsProductData())));
|
||||
buildProducts(project, {QbsProject::uniqueProductName(productNode->qbsProductData())});
|
||||
}
|
||||
|
||||
void QbsProjectManagerPlugin::buildProduct()
|
||||
@@ -396,17 +391,19 @@ void QbsProjectManagerPlugin::buildProduct()
|
||||
|
||||
void QbsProjectManagerPlugin::buildSubprojectContextMenu()
|
||||
{
|
||||
QTC_ASSERT(m_selectedNode, return);
|
||||
QTC_ASSERT(m_selectedProject, return);
|
||||
Node *node = ProjectTree::currentNode();
|
||||
QTC_ASSERT(node, return);
|
||||
QbsProject *project = dynamic_cast<QbsProject *>(ProjectTree::currentProject());
|
||||
QTC_ASSERT(project, return);
|
||||
|
||||
QbsProjectNode *subProject = dynamic_cast<QbsProjectNode *>(m_selectedNode);
|
||||
QbsProjectNode *subProject = dynamic_cast<QbsProjectNode *>(node);
|
||||
QTC_ASSERT(subProject, return);
|
||||
|
||||
QStringList toBuild;
|
||||
foreach (const qbs::ProductData &data, subProject->qbsProjectData().allProducts())
|
||||
toBuild << QbsProject::uniqueProductName(data);
|
||||
|
||||
buildProducts(m_selectedProject, toBuild);
|
||||
buildProducts(project, toBuild);
|
||||
}
|
||||
|
||||
void QbsProjectManagerPlugin::buildSubproject()
|
||||
@@ -497,7 +494,7 @@ void QbsProjectManagerPlugin::buildProducts(QbsProject *project, const QStringLi
|
||||
|
||||
void QbsProjectManagerPlugin::reparseSelectedProject()
|
||||
{
|
||||
reparseProject(m_selectedProject);
|
||||
reparseProject(dynamic_cast<QbsProject *>(ProjectTree::currentProject()));
|
||||
}
|
||||
|
||||
void QbsProjectManagerPlugin::reparseCurrentProject()
|
||||
|
||||
@@ -60,7 +60,6 @@ private:
|
||||
void projectWasAdded(ProjectExplorer::Project *project);
|
||||
void currentProjectWasChanged(ProjectExplorer::Project *project);
|
||||
void projectWasRemoved();
|
||||
void nodeSelectionChanged(ProjectExplorer::Node *node, ProjectExplorer::Project *project);
|
||||
void buildStateChanged(ProjectExplorer::Project *project);
|
||||
void parsingStateChanged();
|
||||
void currentEditorChanged();
|
||||
@@ -94,9 +93,6 @@ private:
|
||||
Utils::ParameterAction *m_buildProduct = nullptr;
|
||||
Utils::ParameterAction *m_buildSubproject = nullptr;
|
||||
|
||||
Internal::QbsProject *m_selectedProject = nullptr;
|
||||
ProjectExplorer::Node *m_selectedNode = nullptr;
|
||||
|
||||
Internal::QbsProject *m_currentProject = nullptr;
|
||||
|
||||
Internal::QbsProject *m_editorProject = nullptr;
|
||||
|
||||
@@ -315,8 +315,10 @@ void QmakeProjectManagerPlugin::updateRunQMakeAction()
|
||||
m_runQMakeAction->setEnabled(enable);
|
||||
}
|
||||
|
||||
void QmakeProjectManagerPlugin::updateContextActions(ProjectExplorer::Node *node, ProjectExplorer::Project *project)
|
||||
void QmakeProjectManagerPlugin::updateContextActions()
|
||||
{
|
||||
Node *node = ProjectTree::currentNode();
|
||||
Project *project = ProjectTree::currentProject();
|
||||
m_addLibraryActionContextMenu->setEnabled(dynamic_cast<QmakeProFileNode *>(node));
|
||||
|
||||
auto proFileNode = dynamic_cast<QmakeProFileNode *>(node);
|
||||
@@ -377,10 +379,9 @@ void QmakeProjectManagerPlugin::updateContextActions(ProjectExplorer::Node *node
|
||||
|
||||
void QmakeProjectManagerPlugin::buildStateChanged(ProjectExplorer::Project *pro)
|
||||
{
|
||||
ProjectExplorer::Project *currentProject = ProjectTree::currentProject();
|
||||
if (pro == currentProject) {
|
||||
if (pro == ProjectTree::currentProject()) {
|
||||
updateRunQMakeAction();
|
||||
updateContextActions(ProjectTree::currentNode(), pro);
|
||||
updateContextActions();
|
||||
updateBuildFileAction();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,9 +33,7 @@ class QAction;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace ProjectExplorer {
|
||||
class Node;
|
||||
class Project;
|
||||
class KitInformation;
|
||||
class Target;
|
||||
}
|
||||
namespace Utils { class ParameterAction; }
|
||||
@@ -69,7 +67,7 @@ private:
|
||||
void projectChanged();
|
||||
void activeTargetChanged();
|
||||
void updateRunQMakeAction();
|
||||
void updateContextActions(ProjectExplorer::Node *node, ProjectExplorer::Project *project);
|
||||
void updateContextActions();
|
||||
void buildStateChanged(ProjectExplorer::Project *pro);
|
||||
void updateBuildFileAction();
|
||||
|
||||
|
||||
@@ -306,8 +306,9 @@ void ResourceEditorPlugin::renamePrefixContextMenu()
|
||||
node->renamePrefix(prefix, dialog.lang());
|
||||
}
|
||||
|
||||
void ResourceEditorPlugin::updateContextActions(Node *node, Project *)
|
||||
void ResourceEditorPlugin::updateContextActions()
|
||||
{
|
||||
Node *node = ProjectTree::currentNode();
|
||||
bool isResourceNode = dynamic_cast<ResourceTopLevelNode *>(node);
|
||||
m_addPrefix->setEnabled(isResourceNode);
|
||||
m_addPrefix->setVisible(isResourceNode);
|
||||
|
||||
@@ -32,11 +32,6 @@ class QAction;
|
||||
class QMenu;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace ProjectExplorer {
|
||||
class Node;
|
||||
class Project;
|
||||
}
|
||||
|
||||
namespace Utils { class ParameterAction; }
|
||||
|
||||
namespace ResourceEditor {
|
||||
@@ -75,7 +70,7 @@ private slots:
|
||||
void copyPathContextMenu();
|
||||
void copyUrlContextMenu();
|
||||
|
||||
void updateContextActions(ProjectExplorer::Node*,ProjectExplorer::Project*);
|
||||
void updateContextActions();
|
||||
|
||||
public:
|
||||
void onUndoStackChanged(ResourceEditorW const *editor, bool canUndo, bool canRedo);
|
||||
|
||||
Reference in New Issue
Block a user