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);
|
m_addLibraryActionContextMenu->setEnabled(proFileNode);
|
||||||
QmakeProject *qmakeProject = qobject_cast<QmakeProject *>(QmakeManager::contextProject());
|
QmakeProject *qmakeProject = qobject_cast<QmakeProject *>(QmakeManager::contextProject());
|
||||||
QmakeProFileNode *subProjectNode = nullptr;
|
QmakeProFileNode *subProjectNode = nullptr;
|
||||||
|
disableBuildFileMenus();
|
||||||
if (node) {
|
if (node) {
|
||||||
auto subPriFileNode = dynamic_cast<const QmakePriFileNode *>(node);
|
auto subPriFileNode = dynamic_cast<const QmakePriFileNode *>(node);
|
||||||
if (!subPriFileNode)
|
if (!subPriFileNode)
|
||||||
subPriFileNode = dynamic_cast<QmakePriFileNode *>(node->parentProjectNode());
|
subPriFileNode = dynamic_cast<QmakePriFileNode *>(node->parentProjectNode());
|
||||||
subProjectNode = subPriFileNode ? subPriFileNode->proFileNode() : nullptr;
|
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;
|
bool subProjectActionsVisible = false;
|
||||||
if (qmakeProject && subProjectNode) {
|
if (qmakeProject && subProjectNode) {
|
||||||
if (QmakeProFileNode *rootNode = qmakeProject->rootProjectNode())
|
if (QmakeProFileNode *rootNode = qmakeProject->rootProjectNode())
|
||||||
@@ -358,7 +360,6 @@ void QmakeProjectManagerPlugin::updateContextActions()
|
|||||||
m_rebuildSubProjectAction->setParameter(subProjectName);
|
m_rebuildSubProjectAction->setParameter(subProjectName);
|
||||||
m_cleanSubProjectAction->setParameter(subProjectName);
|
m_cleanSubProjectAction->setParameter(subProjectName);
|
||||||
m_buildSubProjectContextMenu->setParameter(proFileNode ? proFileNode->displayName() : QString());
|
m_buildSubProjectContextMenu->setParameter(proFileNode ? proFileNode->displayName() : QString());
|
||||||
m_buildFileAction->setParameter(buildFilePossible ? fileNode->filePath().fileName() : QString());
|
|
||||||
|
|
||||||
auto buildConfiguration = (qmakeProject && qmakeProject->activeTarget()) ?
|
auto buildConfiguration = (qmakeProject && qmakeProject->activeTarget()) ?
|
||||||
static_cast<QmakeBuildConfiguration *>(qmakeProject->activeTarget()->activeBuildConfiguration()) : nullptr;
|
static_cast<QmakeBuildConfiguration *>(qmakeProject->activeTarget()->activeBuildConfiguration()) : nullptr;
|
||||||
@@ -373,7 +374,6 @@ void QmakeProjectManagerPlugin::updateContextActions()
|
|||||||
m_subProjectRebuildSeparator->setVisible(subProjectActionsVisible && isProjectNode);
|
m_subProjectRebuildSeparator->setVisible(subProjectActionsVisible && isProjectNode);
|
||||||
m_rebuildSubProjectContextMenu->setVisible(subProjectActionsVisible && isProjectNode);
|
m_rebuildSubProjectContextMenu->setVisible(subProjectActionsVisible && isProjectNode);
|
||||||
m_cleanSubProjectContextMenu->setVisible(subProjectActionsVisible && isProjectNode);
|
m_cleanSubProjectContextMenu->setVisible(subProjectActionsVisible && isProjectNode);
|
||||||
m_buildFileAction->setVisible(buildFilePossible);
|
|
||||||
|
|
||||||
m_buildSubProjectAction->setEnabled(enabled);
|
m_buildSubProjectAction->setEnabled(enabled);
|
||||||
m_rebuildSubProjectAction->setEnabled(enabled);
|
m_rebuildSubProjectAction->setEnabled(enabled);
|
||||||
@@ -383,8 +383,6 @@ void QmakeProjectManagerPlugin::updateContextActions()
|
|||||||
m_cleanSubProjectContextMenu->setEnabled(enabled && isProjectNode);
|
m_cleanSubProjectContextMenu->setEnabled(enabled && isProjectNode);
|
||||||
m_runQMakeActionContextMenu->setEnabled(isProjectNode && !isBuilding
|
m_runQMakeActionContextMenu->setEnabled(isProjectNode && !isBuilding
|
||||||
&& buildConfiguration->qmakeStep());
|
&& buildConfiguration->qmakeStep());
|
||||||
m_buildFileAction->setEnabled(buildFilePossible && !isBuilding);
|
|
||||||
m_buildFileContextMenu->setEnabled(buildFilePossible && !isBuilding);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmakeProjectManagerPlugin::buildStateChanged(ProjectExplorer::Project *pro)
|
void QmakeProjectManagerPlugin::buildStateChanged(ProjectExplorer::Project *pro)
|
||||||
@@ -397,21 +395,39 @@ void QmakeProjectManagerPlugin::buildStateChanged(ProjectExplorer::Project *pro)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void QmakeProjectManagerPlugin::updateBuildFileAction()
|
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 visible = false;
|
||||||
bool enabled = false;
|
bool enabled = false;
|
||||||
|
|
||||||
if (IDocument *currentDocument= EditorManager::currentDocument()) {
|
if (Node *node = SessionManager::nodeForFile(file)) {
|
||||||
Utils::FileName file = currentDocument->filePath();
|
if (Project *project = SessionManager::projectForFile(file)) {
|
||||||
Node *node = SessionManager::nodeForFile(file);
|
if (const FileNode *fileNode = node->asFileNode()) {
|
||||||
Project *project = SessionManager::projectForFile(file);
|
const FileType type = fileNode->fileType();
|
||||||
m_buildFileAction->setParameter(file.fileName());
|
visible = qobject_cast<QmakeProject *>(project)
|
||||||
visible = qobject_cast<QmakeProject *>(project)
|
&& dynamic_cast<QmakePriFileNode *>(node->parentProjectNode())
|
||||||
&& node
|
&& (type == FileType::Source || type == FileType::Header);
|
||||||
&& dynamic_cast<QmakePriFileNode *>(node->parentProjectNode());
|
|
||||||
|
|
||||||
enabled = !BuildManager::isBuilding(project);
|
enabled = !BuildManager::isBuilding(project);
|
||||||
|
m_buildFileAction->setParameter(file.fileName());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
m_buildFileAction->setVisible(visible);
|
m_buildFileAction->setVisible(visible);
|
||||||
m_buildFileAction->setEnabled(enabled);
|
m_buildFileAction->setEnabled(enabled);
|
||||||
|
m_buildFileContextMenu->setEnabled(visible && enabled);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,10 @@ namespace ProjectExplorer {
|
|||||||
class Project;
|
class Project;
|
||||||
class Target;
|
class Target;
|
||||||
}
|
}
|
||||||
namespace Utils { class ParameterAction; }
|
namespace Utils {
|
||||||
|
class FileName;
|
||||||
|
class ParameterAction;
|
||||||
|
}
|
||||||
|
|
||||||
namespace QmakeProjectManager {
|
namespace QmakeProjectManager {
|
||||||
|
|
||||||
@@ -70,6 +73,8 @@ private:
|
|||||||
void updateContextActions();
|
void updateContextActions();
|
||||||
void buildStateChanged(ProjectExplorer::Project *pro);
|
void buildStateChanged(ProjectExplorer::Project *pro);
|
||||||
void updateBuildFileAction();
|
void updateBuildFileAction();
|
||||||
|
void disableBuildFileMenus();
|
||||||
|
void enableBuildFileMenus(const Utils::FileName &file);
|
||||||
|
|
||||||
QmakeManager *m_qmakeProjectManager = nullptr;
|
QmakeManager *m_qmakeProjectManager = nullptr;
|
||||||
QmakeProject *m_previousStartupProject = nullptr;
|
QmakeProject *m_previousStartupProject = nullptr;
|
||||||
|
|||||||
Reference in New Issue
Block a user