forked from qt-creator/qt-creator
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 <orgads@gmail.com> Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
committed by
André Hartmann
parent
46a5133f4b
commit
6221746466
@@ -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;
|
||||
}
|
||||
const FileNode *fileNode = node ? node->asFileNode() : nullptr;
|
||||
|
||||
bool buildFilePossible = subProjectNode && fileNode && (fileNode->fileType() == FileType::Source);
|
||||
if (const FileNode *fileNode = node->asFileNode())
|
||||
enableBuildFileMenus(fileNode->filePath());
|
||||
}
|
||||
|
||||
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());
|
||||
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);
|
||||
enabled = !BuildManager::isBuilding(project);
|
||||
m_buildFileAction->setParameter(file.fileName());
|
||||
}
|
||||
}
|
||||
}
|
||||
m_buildFileAction->setVisible(visible);
|
||||
m_buildFileAction->setEnabled(enabled);
|
||||
m_buildFileContextMenu->setEnabled(visible && enabled);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user