forked from qt-creator/qt-creator
CppTools: Prioritize project parts with selectedForBuilding=true
...when selecting one for the editor document. This flag is only set by the QmakeProject. Change-Id: I648886e12148bd1ebeccca52d9faaf4b528597c9 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
committed by
David Schulz
parent
0718f536a7
commit
9861a58400
@@ -31,12 +31,29 @@
|
||||
namespace CppTools {
|
||||
namespace Internal {
|
||||
|
||||
static ProjectPart::Ptr selectFromActiveProject(const QList<ProjectPart::Ptr> &projectParts,
|
||||
const ProjectExplorer::Project *activeProject)
|
||||
static int priority(const ProjectPart &projectPart, const ProjectExplorer::Project *activeProject)
|
||||
{
|
||||
return Utils::findOr(projectParts, projectParts.first(), [&](const ProjectPart::Ptr &projectPart){
|
||||
return projectPart->project == activeProject;
|
||||
});
|
||||
int thePriority = 0;
|
||||
|
||||
if (projectPart.project == activeProject)
|
||||
thePriority += 10;
|
||||
|
||||
if (projectPart.selectedForBuilding)
|
||||
thePriority += 1;
|
||||
|
||||
return thePriority;
|
||||
}
|
||||
|
||||
static ProjectPart::Ptr chooseFromMultiple(const QList<ProjectPart::Ptr> &projectParts,
|
||||
const ProjectExplorer::Project *activeProject)
|
||||
{
|
||||
QList<ProjectPart::Ptr> projectPartsPrioritized = projectParts;
|
||||
const auto lessThan = [activeProject] (const ProjectPart::Ptr &p1, const ProjectPart::Ptr &p2) {
|
||||
return priority(*p1, activeProject) > priority(*p2, activeProject);
|
||||
};
|
||||
std::stable_sort(projectPartsPrioritized.begin(), projectPartsPrioritized.end(), lessThan);
|
||||
|
||||
return projectPartsPrioritized.first();
|
||||
}
|
||||
|
||||
ProjectPart::Ptr ProjectPartChooser::choose(const QString &filePath,
|
||||
@@ -68,10 +85,10 @@ ProjectPart::Ptr ProjectPartChooser::choose(const QString &filePath,
|
||||
// Fall-back step 2: Use fall-back part from the model manager:
|
||||
projectPart = m_fallbackProjectPart();
|
||||
else
|
||||
projectPart = selectFromActiveProject(projectParts, activeProject);
|
||||
projectPart = chooseFromMultiple(projectParts, activeProject);
|
||||
} else {
|
||||
if (projectHasChanged || !projectParts.contains(projectPart))
|
||||
projectPart = selectFromActiveProject(projectParts, activeProject);
|
||||
projectPart = chooseFromMultiple(projectParts, activeProject);
|
||||
}
|
||||
|
||||
return projectPart;
|
||||
|
@@ -89,6 +89,20 @@ TEST_F(ProjectPartChooser, ForMultipleChooseFromActiveProject)
|
||||
ASSERT_THAT(chosen, Eq(secondProjectPart));
|
||||
}
|
||||
|
||||
TEST_F(ProjectPartChooser, ForMultiplePreferSelectedForBuilding)
|
||||
{
|
||||
const ProjectPart::Ptr firstProjectPart{new ProjectPart};
|
||||
const ProjectPart::Ptr secondProjectPart{new ProjectPart};
|
||||
firstProjectPart->selectedForBuilding = false;
|
||||
secondProjectPart->selectedForBuilding = true;
|
||||
projectPartsForFile += firstProjectPart;
|
||||
projectPartsForFile += secondProjectPart;
|
||||
|
||||
const ProjectPart::Ptr chosen = choose();
|
||||
|
||||
ASSERT_THAT(chosen, Eq(secondProjectPart));
|
||||
}
|
||||
|
||||
TEST_F(ProjectPartChooser, ForMultipleFromDependenciesChooseFromActiveProject)
|
||||
{
|
||||
const QList<ProjectPart::Ptr> projectParts = createProjectPartsWithDifferentProjects();
|
||||
|
Reference in New Issue
Block a user