From 7ce40a76912b26589d2fa06869e51301b9051085 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Mon, 24 Apr 2023 21:03:18 +0200 Subject: [PATCH] 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 Reviewed-by: Qt CI Bot --- .../cmakelocatorfilter.cpp | 101 ++++-------------- .../cmakeprojectmanager/cmakelocatorfilter.h | 32 +----- .../cmakeprojectplugin.cpp | 4 +- 3 files changed, 29 insertions(+), 108 deletions(-) diff --git a/src/plugins/cmakeprojectmanager/cmakelocatorfilter.cpp b/src/plugins/cmakeprojectmanager/cmakelocatorfilter.cpp index 589a30d1ae2..2a6dba5b8e6 100644 --- a/src/plugins/cmakeprojectmanager/cmakelocatorfilter.cpp +++ b/src/plugins/cmakeprojectmanager/cmakelocatorfilter.cpp @@ -21,11 +21,9 @@ using namespace Utils; namespace CMakeProjectManager::Internal { -// -------------------------------------------------------------------- -// CMakeTargetLocatorFilter: -// -------------------------------------------------------------------- +using BuildAcceptor = std::function; -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 projects = ProjectManager::projects(); - for (Project *p : projects) { - auto cmakeProject = qobject_cast(p); - if (!cmakeProject || !cmakeProject->activeTarget()) - continue; - auto bs = qobject_cast(cmakeProject->activeTarget()->buildSystem()); - if (!bs) - continue; - - const QList 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 CMakeTargetLocatorFilter::matchesFor( - QFutureInterface &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(p); })); + const auto projectListUpdated = [filter] { + filter->setEnabled(Utils::contains(ProjectManager::projects(), + [](Project *p) { return qobject_cast(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( @@ -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(); + const auto buildStep = buildStepList->firstOfType(); 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 diff --git a/src/plugins/cmakeprojectmanager/cmakelocatorfilter.h b/src/plugins/cmakeprojectmanager/cmakelocatorfilter.h index 73b3212b3fd..73e0a9fe4ab 100644 --- a/src/plugins/cmakeprojectmanager/cmakelocatorfilter.h +++ b/src/plugins/cmakeprojectmanager/cmakelocatorfilter.h @@ -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 matchesFor(QFutureInterface &future, - const QString &entry) final; - using BuildAcceptor = std::function; -protected: - void setBuildAcceptor(const BuildAcceptor &acceptor) { m_acceptor = acceptor; } - -private: - void projectListUpdated(); - - QList 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 diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp b/src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp index bb0270d16ef..fd41c284455 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp @@ -81,8 +81,8 @@ public: CMakeBuildConfigurationFactory buildConfigFactory; CMakeEditorFactory editorFactor; CMakeInstallStepFactory installStepFactory; - BuildCMakeTargetLocatorFilter buildCMakeTargetLocatorFilter; - OpenCMakeTargetLocatorFilter openCMakeTargetLocationFilter; + CMakeBuildTargetFilter cMakeBuildTargetFilter; + CMakeOpenTargetFilter cMakeOpenTargetFilter; CMakeKitAspect cmakeKitAspect; CMakeGeneratorKitAspect cmakeGeneratorKitAspect;