forked from qt-creator/qt-creator
CMake: Store more information in CMakeTargetLocationFilter
Change-Id: I8bca4d6b591ccdf890c971e86e2e43dbf859eb44 Reviewed-by: Cristian Adam <cristian.adam@qt.io> Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -24,6 +24,7 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "cmakelocatorfilter.h"
|
#include "cmakelocatorfilter.h"
|
||||||
|
#include "cmakebuildconfiguration.h"
|
||||||
#include "cmakebuildstep.h"
|
#include "cmakebuildstep.h"
|
||||||
#include "cmakeproject.h"
|
#include "cmakeproject.h"
|
||||||
|
|
||||||
@@ -62,15 +63,30 @@ void CMakeTargetLocatorFilter::prepareSearch(const QString &entry)
|
|||||||
const QList<Project *> projects = SessionManager::projects();
|
const QList<Project *> projects = SessionManager::projects();
|
||||||
for (Project *p : projects) {
|
for (Project *p : projects) {
|
||||||
auto cmakeProject = qobject_cast<const CMakeProject *>(p);
|
auto cmakeProject = qobject_cast<const CMakeProject *>(p);
|
||||||
if (!cmakeProject)
|
if (!cmakeProject || !cmakeProject->activeTarget())
|
||||||
continue;
|
continue;
|
||||||
const QStringList buildTargetTitles = cmakeProject->buildTargetTitles();
|
auto bc = qobject_cast<CMakeBuildConfiguration *>(
|
||||||
for (const QString &title : buildTargetTitles) {
|
cmakeProject->activeTarget()->activeBuildConfiguration());
|
||||||
const int index = title.indexOf(entry);
|
if (!bc)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
const QList<CMakeBuildTarget> buildTargets = bc->buildTargets();
|
||||||
|
for (const CMakeBuildTarget &target : buildTargets) {
|
||||||
|
const int index = target.title.indexOf(entry);
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
Core::LocatorFilterEntry filterEntry(this, title, cmakeProject->projectFilePath().toString());
|
const FilePath path = target.definitionFile.isEmpty()
|
||||||
filterEntry.extraInfo = cmakeProject->projectFilePath().shortNativePath();
|
? cmakeProject->projectFilePath()
|
||||||
|
: target.definitionFile;
|
||||||
|
QVariantMap extraData;
|
||||||
|
extraData.insert("project", cmakeProject->projectFilePath().toString());
|
||||||
|
extraData.insert("line", target.definitionLine);
|
||||||
|
extraData.insert("file", path.toString());
|
||||||
|
|
||||||
|
Core::LocatorFilterEntry filterEntry(this, target.title, extraData);
|
||||||
|
filterEntry.extraInfo = path.shortNativePath();
|
||||||
filterEntry.highlightInfo = {index, entry.length()};
|
filterEntry.highlightInfo = {index, entry.length()};
|
||||||
|
filterEntry.fileName = path.toString();
|
||||||
|
|
||||||
m_result.append(filterEntry);
|
m_result.append(filterEntry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -115,10 +131,14 @@ void BuildCMakeTargetLocatorFilter::accept(Core::LocatorFilterEntry selection,
|
|||||||
Q_UNUSED(newText)
|
Q_UNUSED(newText)
|
||||||
Q_UNUSED(selectionStart)
|
Q_UNUSED(selectionStart)
|
||||||
Q_UNUSED(selectionLength)
|
Q_UNUSED(selectionLength)
|
||||||
|
|
||||||
|
const QVariantMap extraData = selection.internalData.toMap();
|
||||||
|
const FilePath projectPath = FilePath::fromString(extraData.value("project").toString());
|
||||||
|
|
||||||
// Get the project containing the target selected
|
// Get the project containing the target selected
|
||||||
const auto cmakeProject = qobject_cast<CMakeProject *>(
|
const auto cmakeProject = qobject_cast<CMakeProject *>(
|
||||||
Utils::findOrDefault(SessionManager::projects(), [selection](Project *p) {
|
Utils::findOrDefault(SessionManager::projects(), [projectPath](Project *p) {
|
||||||
return p->projectFilePath().toString() == selection.internalData.toString();
|
return p->projectFilePath() == projectPath;
|
||||||
}));
|
}));
|
||||||
if (!cmakeProject || !cmakeProject->activeTarget()
|
if (!cmakeProject || !cmakeProject->activeTarget()
|
||||||
|| !cmakeProject->activeTarget()->activeBuildConfiguration())
|
|| !cmakeProject->activeTarget()->activeBuildConfiguration())
|
||||||
|
Reference in New Issue
Block a user