CMakeLocatorFilter: Remove the old matchesFor() implementation

Since the base class vanished, rename the filters so that they have
the common prefix now.

Change-Id: I164c7c17229f5c5b05649afe9e7aa79069a82f82
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Jarek Kobus
2023-04-24 21:03:18 +02:00
parent dab004b3c2
commit 7ce40a7691
3 changed files with 29 additions and 108 deletions

View File

@@ -21,11 +21,9 @@ using namespace Utils;
namespace CMakeProjectManager::Internal {
// --------------------------------------------------------------------
// CMakeTargetLocatorFilter:
// --------------------------------------------------------------------
using BuildAcceptor = std::function<void(const FilePath &, const QString &)>;
static LocatorMatcherTasks cmakeMatchers(const CMakeTargetLocatorFilter::BuildAcceptor &acceptor)
static LocatorMatcherTasks cmakeMatchers(const BuildAcceptor &acceptor)
{
using namespace Tasking;
@@ -77,79 +75,23 @@ static LocatorMatcherTasks cmakeMatchers(const CMakeTargetLocatorFilter::BuildAc
return {{Sync(onSetup), storage}};
}
CMakeTargetLocatorFilter::CMakeTargetLocatorFilter()
void setupFilter(ILocatorFilter *filter)
{
connect(ProjectManager::instance(), &ProjectManager::projectAdded,
this, &CMakeTargetLocatorFilter::projectListUpdated);
connect(ProjectManager::instance(), &ProjectManager::projectRemoved,
this, &CMakeTargetLocatorFilter::projectListUpdated);
// Initialize the filter
projectListUpdated();
}
void CMakeTargetLocatorFilter::prepareSearch(const QString &entry)
{
m_result.clear();
const QList<Project *> projects = ProjectManager::projects();
for (Project *p : projects) {
auto cmakeProject = qobject_cast<const CMakeProject *>(p);
if (!cmakeProject || !cmakeProject->activeTarget())
continue;
auto bs = qobject_cast<CMakeBuildSystem *>(cmakeProject->activeTarget()->buildSystem());
if (!bs)
continue;
const QList<CMakeBuildTarget> buildTargets = bs->buildTargets();
for (const CMakeBuildTarget &target : buildTargets) {
if (CMakeBuildSystem::filteredOutTarget(target))
continue;
const int index = target.title.indexOf(entry, 0, Qt::CaseInsensitive);
if (index >= 0) {
const FilePath path = target.backtrace.isEmpty() ? cmakeProject->projectFilePath()
: target.backtrace.last().path;
const int line = target.backtrace.isEmpty() ? 0 : target.backtrace.last().line;
const FilePath projectPath = cmakeProject->projectFilePath();
const QString displayName = target.title;
LocatorFilterEntry filterEntry;
filterEntry.displayName = displayName;
if (m_acceptor) {
filterEntry.acceptor = [projectPath, displayName, acceptor = m_acceptor] {
acceptor(projectPath, displayName);
return AcceptResult();
};
}
filterEntry.linkForEditor = {path, line};
filterEntry.extraInfo = path.shortNativePath();
filterEntry.highlightInfo = {index, int(entry.length())};
filterEntry.filePath = cmakeProject->projectFilePath();
m_result.append(filterEntry);
}
}
}
}
QList<LocatorFilterEntry> CMakeTargetLocatorFilter::matchesFor(
QFutureInterface<LocatorFilterEntry> &future, const QString &entry)
{
Q_UNUSED(future)
Q_UNUSED(entry)
return m_result;
}
void CMakeTargetLocatorFilter::projectListUpdated()
{
// Enable the filter if there's at least one CMake project
setEnabled(Utils::contains(ProjectManager::projects(),
[](Project *p) { return qobject_cast<CMakeProject *>(p); }));
const auto projectListUpdated = [filter] {
filter->setEnabled(Utils::contains(ProjectManager::projects(),
[](Project *p) { return qobject_cast<CMakeProject *>(p); }));
};
QObject::connect(ProjectManager::instance(), &ProjectManager::projectAdded,
filter, projectListUpdated);
QObject::connect(ProjectManager::instance(), &ProjectManager::projectRemoved,
filter, projectListUpdated);
}
// --------------------------------------------------------------------
// BuildCMakeTargetLocatorFilter:
// --------------------------------------------------------------------
static void buildAcceptor(const Utils::FilePath &projectPath, const QString &displayName)
static void buildAcceptor(const FilePath &projectPath, const QString &displayName)
{
// Get the project containing the target selected
const auto cmakeProject = qobject_cast<CMakeProject *>(
@@ -161,14 +103,14 @@ static void buildAcceptor(const Utils::FilePath &projectPath, const QString &dis
return;
// Find the make step
BuildStepList *buildStepList =
const BuildStepList *buildStepList =
cmakeProject->activeTarget()->activeBuildConfiguration()->buildSteps();
auto buildStep = buildStepList->firstOfType<CMakeBuildStep>();
const auto buildStep = buildStepList->firstOfType<CMakeBuildStep>();
if (!buildStep)
return;
// Change the make step to build only the given target
QStringList oldTargets = buildStep->buildTargets();
const QStringList oldTargets = buildStep->buildTargets();
buildStep->setBuildTargets({displayName});
// Build
@@ -176,17 +118,17 @@ static void buildAcceptor(const Utils::FilePath &projectPath, const QString &dis
buildStep->setBuildTargets(oldTargets);
}
BuildCMakeTargetLocatorFilter::BuildCMakeTargetLocatorFilter()
CMakeBuildTargetFilter::CMakeBuildTargetFilter()
{
setId("Build CMake target");
setDisplayName(Tr::tr("Build CMake Target"));
setDescription(Tr::tr("Builds a target of any open CMake project."));
setDefaultShortcutString("cm");
setPriority(High);
setBuildAcceptor(&buildAcceptor);
setupFilter(this);
}
Core::LocatorMatcherTasks BuildCMakeTargetLocatorFilter::matchers()
Core::LocatorMatcherTasks CMakeBuildTargetFilter::matchers()
{
return cmakeMatchers(&buildAcceptor);
}
@@ -195,18 +137,19 @@ Core::LocatorMatcherTasks BuildCMakeTargetLocatorFilter::matchers()
// OpenCMakeTargetLocatorFilter:
// --------------------------------------------------------------------
OpenCMakeTargetLocatorFilter::OpenCMakeTargetLocatorFilter()
CMakeOpenTargetFilter::CMakeOpenTargetFilter()
{
setId("Open CMake target definition");
setDisplayName(Tr::tr("Open CMake Target"));
setDescription(Tr::tr("Locates the definition of a target of any open CMake project."));
setDefaultShortcutString("cmo");
setPriority(Medium);
setupFilter(this);
}
Core::LocatorMatcherTasks OpenCMakeTargetLocatorFilter::matchers()
Core::LocatorMatcherTasks CMakeOpenTargetFilter::matchers()
{
return cmakeMatchers({});
}
} // CMakeProjectManager::Internal
} // namespace CMakeProjectManager::Internal

View File

@@ -7,44 +7,22 @@
namespace CMakeProjectManager::Internal {
// TODO: Remove the base class
class CMakeTargetLocatorFilter : public Core::ILocatorFilter
class CMakeBuildTargetFilter : Core::ILocatorFilter
{
public:
CMakeTargetLocatorFilter();
void prepareSearch(const QString &entry) override;
QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future,
const QString &entry) final;
using BuildAcceptor = std::function<void(const Utils::FilePath &, const QString &)>;
protected:
void setBuildAcceptor(const BuildAcceptor &acceptor) { m_acceptor = acceptor; }
private:
void projectListUpdated();
QList<Core::LocatorFilterEntry> m_result;
BuildAcceptor m_acceptor;
};
// TODO: Don't derive, flatten the hierarchy
class BuildCMakeTargetLocatorFilter : CMakeTargetLocatorFilter
{
public:
BuildCMakeTargetLocatorFilter();
CMakeBuildTargetFilter();
private:
Core::LocatorMatcherTasks matchers() final;
};
// TODO: Don't derive, flatten the hierarchy
class OpenCMakeTargetLocatorFilter : CMakeTargetLocatorFilter
class CMakeOpenTargetFilter : Core::ILocatorFilter
{
public:
OpenCMakeTargetLocatorFilter();
CMakeOpenTargetFilter();
private:
Core::LocatorMatcherTasks matchers() final;
};
} // CMakeProjectManager::Internal
} // namespace CMakeProjectManager::Internal

View File

@@ -81,8 +81,8 @@ public:
CMakeBuildConfigurationFactory buildConfigFactory;
CMakeEditorFactory editorFactor;
CMakeInstallStepFactory installStepFactory;
BuildCMakeTargetLocatorFilter buildCMakeTargetLocatorFilter;
OpenCMakeTargetLocatorFilter openCMakeTargetLocationFilter;
CMakeBuildTargetFilter cMakeBuildTargetFilter;
CMakeOpenTargetFilter cMakeOpenTargetFilter;
CMakeKitAspect cmakeKitAspect;
CMakeGeneratorKitAspect cmakeGeneratorKitAspect;