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 { namespace CMakeProjectManager::Internal {
// -------------------------------------------------------------------- using BuildAcceptor = std::function<void(const FilePath &, const QString &)>;
// CMakeTargetLocatorFilter:
// --------------------------------------------------------------------
static LocatorMatcherTasks cmakeMatchers(const CMakeTargetLocatorFilter::BuildAcceptor &acceptor) static LocatorMatcherTasks cmakeMatchers(const BuildAcceptor &acceptor)
{ {
using namespace Tasking; using namespace Tasking;
@@ -77,79 +75,23 @@ static LocatorMatcherTasks cmakeMatchers(const CMakeTargetLocatorFilter::BuildAc
return {{Sync(onSetup), storage}}; return {{Sync(onSetup), storage}};
} }
CMakeTargetLocatorFilter::CMakeTargetLocatorFilter() void setupFilter(ILocatorFilter *filter)
{ {
connect(ProjectManager::instance(), &ProjectManager::projectAdded, const auto projectListUpdated = [filter] {
this, &CMakeTargetLocatorFilter::projectListUpdated); filter->setEnabled(Utils::contains(ProjectManager::projects(),
connect(ProjectManager::instance(), &ProjectManager::projectRemoved, [](Project *p) { return qobject_cast<CMakeProject *>(p); }));
this, &CMakeTargetLocatorFilter::projectListUpdated); };
QObject::connect(ProjectManager::instance(), &ProjectManager::projectAdded,
// Initialize the filter filter, projectListUpdated);
projectListUpdated(); QObject::connect(ProjectManager::instance(), &ProjectManager::projectRemoved,
} 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); }));
} }
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// BuildCMakeTargetLocatorFilter: // 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 // Get the project containing the target selected
const auto cmakeProject = qobject_cast<CMakeProject *>( const auto cmakeProject = qobject_cast<CMakeProject *>(
@@ -161,14 +103,14 @@ static void buildAcceptor(const Utils::FilePath &projectPath, const QString &dis
return; return;
// Find the make step // Find the make step
BuildStepList *buildStepList = const BuildStepList *buildStepList =
cmakeProject->activeTarget()->activeBuildConfiguration()->buildSteps(); cmakeProject->activeTarget()->activeBuildConfiguration()->buildSteps();
auto buildStep = buildStepList->firstOfType<CMakeBuildStep>(); const auto buildStep = buildStepList->firstOfType<CMakeBuildStep>();
if (!buildStep) if (!buildStep)
return; return;
// Change the make step to build only the given target // Change the make step to build only the given target
QStringList oldTargets = buildStep->buildTargets(); const QStringList oldTargets = buildStep->buildTargets();
buildStep->setBuildTargets({displayName}); buildStep->setBuildTargets({displayName});
// Build // Build
@@ -176,17 +118,17 @@ static void buildAcceptor(const Utils::FilePath &projectPath, const QString &dis
buildStep->setBuildTargets(oldTargets); buildStep->setBuildTargets(oldTargets);
} }
BuildCMakeTargetLocatorFilter::BuildCMakeTargetLocatorFilter() CMakeBuildTargetFilter::CMakeBuildTargetFilter()
{ {
setId("Build CMake target"); setId("Build CMake target");
setDisplayName(Tr::tr("Build CMake Target")); setDisplayName(Tr::tr("Build CMake Target"));
setDescription(Tr::tr("Builds a target of any open CMake project.")); setDescription(Tr::tr("Builds a target of any open CMake project."));
setDefaultShortcutString("cm"); setDefaultShortcutString("cm");
setPriority(High); setPriority(High);
setBuildAcceptor(&buildAcceptor); setupFilter(this);
} }
Core::LocatorMatcherTasks BuildCMakeTargetLocatorFilter::matchers() Core::LocatorMatcherTasks CMakeBuildTargetFilter::matchers()
{ {
return cmakeMatchers(&buildAcceptor); return cmakeMatchers(&buildAcceptor);
} }
@@ -195,18 +137,19 @@ Core::LocatorMatcherTasks BuildCMakeTargetLocatorFilter::matchers()
// OpenCMakeTargetLocatorFilter: // OpenCMakeTargetLocatorFilter:
// -------------------------------------------------------------------- // --------------------------------------------------------------------
OpenCMakeTargetLocatorFilter::OpenCMakeTargetLocatorFilter() CMakeOpenTargetFilter::CMakeOpenTargetFilter()
{ {
setId("Open CMake target definition"); setId("Open CMake target definition");
setDisplayName(Tr::tr("Open CMake Target")); setDisplayName(Tr::tr("Open CMake Target"));
setDescription(Tr::tr("Locates the definition of a target of any open CMake project.")); setDescription(Tr::tr("Locates the definition of a target of any open CMake project."));
setDefaultShortcutString("cmo"); setDefaultShortcutString("cmo");
setPriority(Medium); setPriority(Medium);
setupFilter(this);
} }
Core::LocatorMatcherTasks OpenCMakeTargetLocatorFilter::matchers() Core::LocatorMatcherTasks CMakeOpenTargetFilter::matchers()
{ {
return cmakeMatchers({}); return cmakeMatchers({});
} }
} // CMakeProjectManager::Internal } // namespace CMakeProjectManager::Internal

View File

@@ -7,44 +7,22 @@
namespace CMakeProjectManager::Internal { namespace CMakeProjectManager::Internal {
// TODO: Remove the base class class CMakeBuildTargetFilter : Core::ILocatorFilter
class CMakeTargetLocatorFilter : public Core::ILocatorFilter
{ {
public: public:
CMakeTargetLocatorFilter(); CMakeBuildTargetFilter();
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();
private: private:
Core::LocatorMatcherTasks matchers() final; Core::LocatorMatcherTasks matchers() final;
}; };
// TODO: Don't derive, flatten the hierarchy class CMakeOpenTargetFilter : Core::ILocatorFilter
class OpenCMakeTargetLocatorFilter : CMakeTargetLocatorFilter
{ {
public: public:
OpenCMakeTargetLocatorFilter(); CMakeOpenTargetFilter();
private: private:
Core::LocatorMatcherTasks matchers() final; Core::LocatorMatcherTasks matchers() final;
}; };
} // CMakeProjectManager::Internal } // namespace CMakeProjectManager::Internal

View File

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