Commit 0264053d authored by hjk's avatar hjk

qmake: Avoid passing some context menu data by side channels

... and the need temporarily storing them by creating them when needed.

Change-Id: I930dd34bc7682f3d4fb40bd8da132f52ba32414b
Reviewed-by: Tobias Hunger's avatarTobias Hunger <tobias.hunger@qt.io>
parent 3e225628
......@@ -86,34 +86,37 @@ ProjectExplorer::Project *QmakeManager::openProject(const QString &fileName, QSt
return new QmakeProject(this, fileName);
}
ProjectExplorer::Node *QmakeManager::contextNode() const
Node *QmakeManager::contextNode()
{
return m_contextNode;
}
void QmakeManager::setContextNode(ProjectExplorer::Node *node)
{
m_contextNode = node;
Node *node = ProjectTree::currentNode();
if (!node)
return nullptr;
auto subPriFileNode = dynamic_cast<QmakePriFileNode *>(node);
return subPriFileNode ? subPriFileNode->proFileNode() : node->parentProjectNode();
}
ProjectExplorer::Project *QmakeManager::contextProject() const
QmakeProject *QmakeManager::contextProject()
{
return m_contextProject;
return qobject_cast<QmakeProject *>(ProjectTree::currentProject());
}
void QmakeManager::setContextProject(ProjectExplorer::Project *project)
FileNode *QmakeManager::contextFile()
{
m_contextProject = project;
}
Node *node = ProjectTree::currentNode();
ProjectExplorer::FileNode *QmakeManager::contextFile() const
{
return m_contextFile;
}
QmakeProFileNode *subProjectNode = nullptr;
if (node) {
auto subPriFileNode = dynamic_cast<QmakePriFileNode *>(node);
if (!subPriFileNode)
subPriFileNode = dynamic_cast<QmakePriFileNode *>(node->parentProjectNode());
if (subPriFileNode)
subProjectNode = subPriFileNode->proFileNode();
}
FileNode *fileNode = node ? node->asFileNode() : nullptr;
bool buildFilePossible = subProjectNode && fileNode
&& (fileNode->fileType() == ProjectExplorer::FileType::Source);
void QmakeManager::setContextFile(ProjectExplorer::FileNode *file)
{
m_contextFile = file;
return buildFilePossible ? fileNode : nullptr;
}
void QmakeManager::addLibrary()
......@@ -162,7 +165,7 @@ void QmakeManager::runQMake()
void QmakeManager::runQMakeContextMenu()
{
runQMakeImpl(m_contextProject, m_contextNode);
runQMakeImpl(contextProject(), contextNode());
}
void QmakeManager::runQMakeImpl(ProjectExplorer::Project *p, ProjectExplorer::Node *node)
......@@ -227,31 +230,28 @@ void QmakeManager::buildFile()
void QmakeManager::handleSubDirContextMenu(QmakeManager::Action action, bool isFileBuild)
{
handleSubDirContextMenu(action, isFileBuild, m_contextProject, m_contextNode, m_contextFile);
handleSubDirContextMenu(action, isFileBuild, contextProject(), contextNode(), contextFile());
}
void QmakeManager::handleSubDirContextMenu(QmakeManager::Action action, bool isFileBuild,
ProjectExplorer::Project *contextProject,
ProjectExplorer::Node *contextNode,
ProjectExplorer::FileNode *contextFile)
Project *contextProject, Node *contextNode, FileNode *contextFile)
{
QmakeProject *qmakeProject = qobject_cast<QmakeProject *>(contextProject);
QTC_ASSERT(qmakeProject, return);
QTC_ASSERT(contextProject, return);
Target *target = contextProject->activeTarget();
if (!target)
return;
if (!qmakeProject->activeTarget() ||
!qmakeProject->activeTarget()->activeBuildConfiguration())
return;
QmakeBuildConfiguration *bc = qobject_cast<QmakeBuildConfiguration *>(target->activeBuildConfiguration());
if (!bc)
return;
if (!contextNode || !contextFile)
isFileBuild = false;
QmakeBuildConfiguration *bc = qobject_cast<QmakeBuildConfiguration *>(qmakeProject->activeTarget()->activeBuildConfiguration());
if (!bc)
return;
if (contextNode) {
if (QmakePriFileNode *prifile = dynamic_cast<QmakePriFileNode *>(contextNode)) {
if (QmakeProFileNode *profile = prifile->proFileNode()) {
if (profile != qmakeProject->rootProjectNode() || isFileBuild)
if (profile != contextProject->rootProjectNode() || isFileBuild)
bc->setSubNodeBuild(profile);
}
}
......
......@@ -56,12 +56,9 @@ public:
ProjectExplorer::Project *openProject(const QString &fileName, QString *errorString) override;
// Context information used in the slot implementations
ProjectExplorer::Node *contextNode() const;
void setContextNode(ProjectExplorer::Node *node);
ProjectExplorer::Project *contextProject() const;
void setContextProject(ProjectExplorer::Project *project);
ProjectExplorer::FileNode *contextFile() const;
void setContextFile(ProjectExplorer::FileNode *file);
static ProjectExplorer::Node *contextNode();
static QmakeProject *contextProject();
static ProjectExplorer::FileNode *contextFile();
enum Action { BUILD, REBUILD, CLEAN };
......@@ -84,10 +81,6 @@ private:
ProjectExplorer::FileNode *contextFile);
void addLibraryImpl(const QString &fileName, TextEditor::BaseTextEditor *editor);
void runQMakeImpl(ProjectExplorer::Project *p, ProjectExplorer::Node *node);
ProjectExplorer::Node *m_contextNode = nullptr;
ProjectExplorer::Project *m_contextProject = nullptr;
ProjectExplorer::FileNode *m_contextFile = nullptr;
};
} // namespace QmakeProjectManager
......@@ -321,24 +321,12 @@ void QmakeProjectManagerPlugin::updateContextActions()
Project *project = ProjectTree::currentProject();
m_addLibraryActionContextMenu->setEnabled(dynamic_cast<QmakeProFileNode *>(node));
auto proFileNode = dynamic_cast<QmakeProFileNode *>(node);
auto qmakeProject = qobject_cast<QmakeProject *>(project);
QmakeProFileNode *subProjectNode = nullptr;
if (node) {
auto subPriFileNode = dynamic_cast<QmakePriFileNode *>(node);
if (!subPriFileNode)
subPriFileNode = dynamic_cast<QmakePriFileNode *>(node->parentProjectNode());
if (subPriFileNode)
subProjectNode = subPriFileNode->proFileNode();
}
ProjectExplorer::FileNode *fileNode = node ? node->asFileNode() : nullptr;
bool buildFilePossible = subProjectNode && fileNode
&& (fileNode->fileType() == ProjectExplorer::FileType::Source);
m_qmakeProjectManager->setContextNode(subProjectNode);
m_qmakeProjectManager->setContextProject(qmakeProject);
m_qmakeProjectManager->setContextFile(buildFilePossible ? fileNode : nullptr);
FileNode *proFileNode = QmakeManager::contextFile();
QmakeProject *qmakeProject = QmakeManager::contextProject();
Node *subProjectNode = QmakeManager::contextNode();
FileNode *fileNode = node ? node->asFileNode() : nullptr;
bool buildFilePossible = subProjectNode && fileNode && (fileNode->fileType() == FileType::Source);
bool subProjectActionsVisible = qmakeProject && subProjectNode && (subProjectNode != qmakeProject->rootProjectNode());
QString subProjectName;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment