diff --git a/src/plugins/qbsprojectmanager/qbsprojectmanagerplugin.cpp b/src/plugins/qbsprojectmanager/qbsprojectmanagerplugin.cpp index bea05826a4c..3d7c2994743 100644 --- a/src/plugins/qbsprojectmanager/qbsprojectmanagerplugin.cpp +++ b/src/plugins/qbsprojectmanager/qbsprojectmanagerplugin.cpp @@ -183,17 +183,17 @@ bool QbsProjectManagerPlugin::initialize(const QStringList &arguments, QString * this, &QbsProjectManagerPlugin::updateContextActions); connect(BuildManager::instance(), &BuildManager::buildStateChanged, - this, &QbsProjectManagerPlugin::buildStateChanged); + this, &QbsProjectManagerPlugin::projectChanged); connect(Core::EditorManager::instance(), &Core::EditorManager::currentEditorChanged, - this, &QbsProjectManagerPlugin::currentEditorChanged); + this, &QbsProjectManagerPlugin::updateBuildActions); connect(SessionManager::instance(), &SessionManager::projectAdded, this, &QbsProjectManagerPlugin::projectWasAdded); connect(SessionManager::instance(), &SessionManager::projectRemoved, - this, &QbsProjectManagerPlugin::projectWasRemoved); + this, &QbsProjectManagerPlugin::updateBuildActions); connect(SessionManager::instance(), &SessionManager::startupProjectChanged, - this, &QbsProjectManagerPlugin::currentProjectWasChanged); + this, &QbsProjectManagerPlugin::updateReparseQbsAction); // Run initial setup routines updateContextActions(); @@ -214,24 +214,9 @@ void QbsProjectManagerPlugin::projectWasAdded(Project *project) return; connect(qbsProject, &QbsProject::projectParsingStarted, - this, &QbsProjectManagerPlugin::parsingStateChanged); + this, &QbsProjectManagerPlugin::projectChanged); connect(qbsProject, &QbsProject::projectParsingDone, - this, &QbsProjectManagerPlugin::parsingStateChanged); -} - -void QbsProjectManagerPlugin::currentProjectWasChanged(Project *project) -{ - m_currentProject = qobject_cast(project); - - updateReparseQbsAction(); -} - -void QbsProjectManagerPlugin::projectWasRemoved() -{ - m_editorNode = currentEditorNode(); - m_editorProject = currentEditorProject(); - - updateBuildActions(); + this, &QbsProjectManagerPlugin::projectChanged); } void QbsProjectManagerPlugin::updateContextActions() @@ -243,8 +228,7 @@ void QbsProjectManagerPlugin::updateContextActions() && node && node->isEnabled(); bool isFile = project && node && (node->nodeType() == NodeType::File); - bool isProduct = project && node - && dynamic_cast(node); + bool isProduct = project && node && dynamic_cast(node); QbsProjectNode *subproject = dynamic_cast(node); bool isSubproject = project && subproject && subproject != project->rootProjectNode(); @@ -256,9 +240,10 @@ void QbsProjectManagerPlugin::updateContextActions() void QbsProjectManagerPlugin::updateReparseQbsAction() { - m_reparseQbs->setEnabled(m_currentProject - && !BuildManager::isBuilding(m_currentProject) - && !m_currentProject->isParsing()); + QbsProject *project = qobject_cast(SessionManager::startupProject()); + m_reparseQbs->setEnabled(project + && !BuildManager::isBuilding(project) + && !project->isParsing()); } void QbsProjectManagerPlugin::updateBuildActions() @@ -272,23 +257,24 @@ void QbsProjectManagerPlugin::updateBuildActions() QString productName; QString subprojectName; - if (m_editorNode) { - enabled = m_editorProject - && !BuildManager::isBuilding(m_editorProject) - && !m_editorProject->isParsing(); + if (Node *editorNode = currentEditorNode()) { + QbsProject *editorProject = currentEditorProject(); + enabled = editorProject + && !BuildManager::isBuilding(editorProject) + && !editorProject->isParsing(); - fileName = m_editorNode->filePath().fileName(); - fileVisible = m_editorProject && m_editorNode && dynamic_cast(m_editorNode->parentProjectNode()); + fileName = editorNode->filePath().fileName(); + fileVisible = editorProject && editorNode && dynamic_cast(editorNode->parentProjectNode()); - QbsProductNode *productNode - = dynamic_cast(m_editorNode ? m_editorNode->parentProjectNode() : 0); + QbsProductNode *productNode = + dynamic_cast(editorNode ? editorNode->parentProjectNode() : 0); if (productNode) { productVisible = true; productName = productNode->displayName(); } - QbsProjectNode *subprojectNode - = dynamic_cast(productNode ? productNode->parentFolderNode() : 0); - if (subprojectNode && m_editorProject && subprojectNode != m_editorProject->rootProjectNode()) { + QbsProjectNode *subprojectNode = + dynamic_cast(productNode ? productNode->parentFolderNode() : 0); + if (subprojectNode && editorProject && subprojectNode != editorProject->rootProjectNode()) { subprojectVisible = true; subprojectName = subprojectNode->displayName(); } @@ -307,44 +293,20 @@ void QbsProjectManagerPlugin::updateBuildActions() m_buildSubproject->setParameter(subprojectName); } -void QbsProjectManagerPlugin::buildStateChanged(Project *project) -{ - if (project == m_currentProject) - updateReparseQbsAction(); - - if (project == ProjectTree::currentProject()) - updateContextActions(); - - m_editorNode = currentEditorNode(); - m_editorProject = currentEditorProject(); - if (project == m_editorProject) - updateBuildActions(); -} - -void QbsProjectManagerPlugin::parsingStateChanged() +void QbsProjectManagerPlugin::projectChanged() { QbsProject *project = qobject_cast(sender()); - if (!project || project == m_currentProject) + if (!project || project == SessionManager::startupProject()) updateReparseQbsAction(); if (!project || project == ProjectTree::currentProject()) updateContextActions(); - m_editorNode = currentEditorNode(); - m_editorProject = currentEditorProject(); - if (!project || project == m_editorProject) + if (!project || project == currentEditorProject()) updateBuildActions(); } -void QbsProjectManagerPlugin::currentEditorChanged() -{ - m_editorNode = currentEditorNode(); - m_editorProject = currentEditorProject(); - - updateBuildActions(); -} - void QbsProjectManagerPlugin::buildFileContextMenu() { Node *node = ProjectTree::currentNode(); @@ -356,10 +318,12 @@ void QbsProjectManagerPlugin::buildFileContextMenu() void QbsProjectManagerPlugin::buildFile() { - if (!m_editorProject || !m_editorNode) + Node *node = currentEditorNode(); + QbsProject *project = currentEditorProject(); + if (!project || !node) return; - buildSingleFile(m_editorProject, m_editorNode->filePath().toString()); + buildSingleFile(project, node->filePath().toString()); } void QbsProjectManagerPlugin::buildProductContextMenu() @@ -377,16 +341,19 @@ void QbsProjectManagerPlugin::buildProductContextMenu() void QbsProjectManagerPlugin::buildProduct() { - if (!m_editorProject || !m_editorNode) + Node *node = currentEditorNode(); + if (!node) return; - QbsProductNode *product = dynamic_cast(m_editorNode->parentProjectNode()); - + QbsProductNode *product = dynamic_cast(node->parentProjectNode()); if (!product) return; - buildProducts(m_editorProject, - QStringList(QbsProject::uniqueProductName(product->qbsProductData()))); + QbsProject *project = currentEditorProject(); + if (!project) + return; + + buildProducts(project, {QbsProject::uniqueProductName(product->qbsProductData())}); } void QbsProjectManagerPlugin::buildSubprojectContextMenu() @@ -408,12 +375,14 @@ void QbsProjectManagerPlugin::buildSubprojectContextMenu() void QbsProjectManagerPlugin::buildSubproject() { - if (!m_editorNode || !m_editorProject) + Node *editorNode = currentEditorNode(); + QbsProject *editorProject = currentEditorProject(); + if (!editorNode || !editorProject) return; QbsProjectNode *subproject = 0; - QbsBaseProjectNode *start = dynamic_cast(m_editorNode->parentProjectNode()); - while (start && start != m_editorProject->rootProjectNode()) { + QbsBaseProjectNode *start = dynamic_cast(editorNode->parentProjectNode()); + while (start && start != editorProject->rootProjectNode()) { QbsProjectNode *tmp = dynamic_cast(start); if (tmp) { subproject = tmp; @@ -429,7 +398,7 @@ void QbsProjectManagerPlugin::buildSubproject() foreach (const qbs::ProductData &data, subproject->qbsProjectData().allProducts()) toBuild << QbsProject::uniqueProductName(data); - buildProducts(m_editorProject, toBuild); + buildProducts(editorProject, toBuild); } void QbsProjectManagerPlugin::buildFiles(QbsProject *project, const QStringList &files, @@ -499,7 +468,7 @@ void QbsProjectManagerPlugin::reparseSelectedProject() void QbsProjectManagerPlugin::reparseCurrentProject() { - reparseProject(m_currentProject); + reparseProject(dynamic_cast(SessionManager::startupProject())); } void QbsProjectManagerPlugin::reparseProject(QbsProject *project) diff --git a/src/plugins/qbsprojectmanager/qbsprojectmanagerplugin.h b/src/plugins/qbsprojectmanager/qbsprojectmanagerplugin.h index 0f6cc38cb5c..cdff91de564 100644 --- a/src/plugins/qbsprojectmanager/qbsprojectmanagerplugin.h +++ b/src/plugins/qbsprojectmanager/qbsprojectmanagerplugin.h @@ -28,18 +28,7 @@ #include #include -#include - -QT_BEGIN_NAMESPACE -class QAction; -QT_END_NAMESPACE - -namespace ProjectExplorer { -class Project; -class ProjectExplorerPlugin; -class Node; -class Target; -} // namespace ProjectExplorer +namespace ProjectExplorer { class Project; } namespace QbsProjectManager { namespace Internal { @@ -58,11 +47,7 @@ public: private: void projectWasAdded(ProjectExplorer::Project *project); - void currentProjectWasChanged(ProjectExplorer::Project *project); - void projectWasRemoved(); - void buildStateChanged(ProjectExplorer::Project *project); - void parsingStateChanged(); - void currentEditorChanged(); + void projectChanged(); void buildFileContextMenu(); void buildFile(); @@ -92,11 +77,6 @@ private: Utils::ParameterAction *m_buildFile = nullptr; Utils::ParameterAction *m_buildProduct = nullptr; Utils::ParameterAction *m_buildSubproject = nullptr; - - Internal::QbsProject *m_currentProject = nullptr; - - Internal::QbsProject *m_editorProject = nullptr; - ProjectExplorer::Node *m_editorNode = nullptr; }; } // namespace Internal