Commit 62217464 authored by Andre Hartmann's avatar Andre Hartmann Committed by André Hartmann

Qmake: Fix Build File (context) menu for non-source files

Enable Build File for source or header files only and
de-duplicate the corresponding code.

Before, the menus were incorrectly enabled for e.g. .pro
and .ui files also: While the menu was already hidden for
these  non-source files in updateContextActions(), the
following  call to updateBuildFileAction() did enable it
again.

Task-number: QTCREATORBUG-19098
Change-Id: I87f40e64ab044b33be9c465d1c5dfa36c3cf1260
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
Reviewed-by: Tobias Hunger's avatarTobias Hunger <tobias.hunger@qt.io>
parent 46a5133f
......@@ -335,15 +335,17 @@ void QmakeProjectManagerPlugin::updateContextActions()
m_addLibraryActionContextMenu->setEnabled(proFileNode);
QmakeProject *qmakeProject = qobject_cast<QmakeProject *>(QmakeManager::contextProject());
QmakeProFileNode *subProjectNode = nullptr;
disableBuildFileMenus();
if (node) {
auto subPriFileNode = dynamic_cast<const QmakePriFileNode *>(node);
if (!subPriFileNode)
subPriFileNode = dynamic_cast<QmakePriFileNode *>(node->parentProjectNode());
subProjectNode = subPriFileNode ? subPriFileNode->proFileNode() : nullptr;
if (const FileNode *fileNode = node->asFileNode())
enableBuildFileMenus(fileNode->filePath());
}
const FileNode *fileNode = node ? node->asFileNode() : nullptr;
bool buildFilePossible = subProjectNode && fileNode && (fileNode->fileType() == FileType::Source);
bool subProjectActionsVisible = false;
if (qmakeProject && subProjectNode) {
if (QmakeProFileNode *rootNode = qmakeProject->rootProjectNode())
......@@ -358,7 +360,6 @@ void QmakeProjectManagerPlugin::updateContextActions()
m_rebuildSubProjectAction->setParameter(subProjectName);
m_cleanSubProjectAction->setParameter(subProjectName);
m_buildSubProjectContextMenu->setParameter(proFileNode ? proFileNode->displayName() : QString());
m_buildFileAction->setParameter(buildFilePossible ? fileNode->filePath().fileName() : QString());
auto buildConfiguration = (qmakeProject && qmakeProject->activeTarget()) ?
static_cast<QmakeBuildConfiguration *>(qmakeProject->activeTarget()->activeBuildConfiguration()) : nullptr;
......@@ -373,7 +374,6 @@ void QmakeProjectManagerPlugin::updateContextActions()
m_subProjectRebuildSeparator->setVisible(subProjectActionsVisible && isProjectNode);
m_rebuildSubProjectContextMenu->setVisible(subProjectActionsVisible && isProjectNode);
m_cleanSubProjectContextMenu->setVisible(subProjectActionsVisible && isProjectNode);
m_buildFileAction->setVisible(buildFilePossible);
m_buildSubProjectAction->setEnabled(enabled);
m_rebuildSubProjectAction->setEnabled(enabled);
......@@ -383,8 +383,6 @@ void QmakeProjectManagerPlugin::updateContextActions()
m_cleanSubProjectContextMenu->setEnabled(enabled && isProjectNode);
m_runQMakeActionContextMenu->setEnabled(isProjectNode && !isBuilding
&& buildConfiguration->qmakeStep());
m_buildFileAction->setEnabled(buildFilePossible && !isBuilding);
m_buildFileContextMenu->setEnabled(buildFilePossible && !isBuilding);
}
void QmakeProjectManagerPlugin::buildStateChanged(ProjectExplorer::Project *pro)
......@@ -397,21 +395,39 @@ void QmakeProjectManagerPlugin::buildStateChanged(ProjectExplorer::Project *pro)
}
void QmakeProjectManagerPlugin::updateBuildFileAction()
{
disableBuildFileMenus();
if (IDocument *currentDocument = EditorManager::currentDocument())
enableBuildFileMenus(currentDocument->filePath());
}
void QmakeProjectManagerPlugin::disableBuildFileMenus()
{
m_buildFileAction->setVisible(false);
m_buildFileAction->setEnabled(false);
m_buildFileAction->setParameter(QString());
m_buildFileContextMenu->setEnabled(false);
}
void QmakeProjectManagerPlugin::enableBuildFileMenus(const Utils::FileName &file)
{
bool visible = false;
bool enabled = false;
if (IDocument *currentDocument= EditorManager::currentDocument()) {
Utils::FileName file = currentDocument->filePath();
Node *node = SessionManager::nodeForFile(file);
Project *project = SessionManager::projectForFile(file);
m_buildFileAction->setParameter(file.fileName());
visible = qobject_cast<QmakeProject *>(project)
&& node
&& dynamic_cast<QmakePriFileNode *>(node->parentProjectNode());
enabled = !BuildManager::isBuilding(project);
if (Node *node = SessionManager::nodeForFile(file)) {
if (Project *project = SessionManager::projectForFile(file)) {
if (const FileNode *fileNode = node->asFileNode()) {
const FileType type = fileNode->fileType();
visible = qobject_cast<QmakeProject *>(project)
&& dynamic_cast<QmakePriFileNode *>(node->parentProjectNode())
&& (type == FileType::Source || type == FileType::Header);
enabled = !BuildManager::isBuilding(project);
m_buildFileAction->setParameter(file.fileName());
}
}
}
m_buildFileAction->setVisible(visible);
m_buildFileAction->setEnabled(enabled);
m_buildFileContextMenu->setEnabled(visible && enabled);
}
......@@ -36,7 +36,10 @@ namespace ProjectExplorer {
class Project;
class Target;
}
namespace Utils { class ParameterAction; }
namespace Utils {
class FileName;
class ParameterAction;
}
namespace QmakeProjectManager {
......@@ -70,6 +73,8 @@ private:
void updateContextActions();
void buildStateChanged(ProjectExplorer::Project *pro);
void updateBuildFileAction();
void disableBuildFileMenus();
void enableBuildFileMenus(const Utils::FileName &file);
QmakeManager *m_qmakeProjectManager = nullptr;
QmakeProject *m_previousStartupProject = nullptr;
......
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