diff --git a/src/plugins/cmakeprojectmanager/cmakelocatorfilter.cpp b/src/plugins/cmakeprojectmanager/cmakelocatorfilter.cpp index b6f33a754ff..9ea23469e15 100644 --- a/src/plugins/cmakeprojectmanager/cmakelocatorfilter.cpp +++ b/src/plugins/cmakeprojectmanager/cmakelocatorfilter.cpp @@ -47,11 +47,6 @@ using namespace Utils; CMakeTargetLocatorFilter::CMakeTargetLocatorFilter() { - setId("Build CMake target"); - setDisplayName(tr("Build CMake target")); - setShortcutString("cm"); - setPriority(High); - connect(SessionManager::instance(), &SessionManager::projectAdded, this, &CMakeTargetLocatorFilter::projectListUpdated); connect(SessionManager::instance(), &SessionManager::projectRemoved, @@ -89,23 +84,49 @@ QList CMakeTargetLocatorFilter::matchesFor(QFutureInte return m_result; } -void CMakeTargetLocatorFilter::accept(Core::LocatorFilterEntry selection, - QString *newText, int *selectionStart, int *selectionLength) const +void CMakeTargetLocatorFilter::refresh(QFutureInterface &future) +{ + Q_UNUSED(future) +} + +void CMakeTargetLocatorFilter::projectListUpdated() +{ + // Enable the filter if there's at least one CMake project + setEnabled(Utils::contains(SessionManager::projects(), [](Project *p) { return qobject_cast(p); })); +} + +// -------------------------------------------------------------------- +// BuildCMakeTargetLocatorFilter: +// -------------------------------------------------------------------- + +BuildCMakeTargetLocatorFilter::BuildCMakeTargetLocatorFilter() +{ + setId("Build CMake target"); + setDisplayName(tr("Build CMake target")); + setShortcutString("cm"); + setPriority(High); +} + +void BuildCMakeTargetLocatorFilter::accept(Core::LocatorFilterEntry selection, + QString *newText, + int *selectionStart, + int *selectionLength) const { Q_UNUSED(newText) Q_UNUSED(selectionStart) Q_UNUSED(selectionLength) // Get the project containing the target selected const auto cmakeProject = qobject_cast( - Utils::findOrDefault(SessionManager::projects(), [selection](Project *p) { - return p->projectFilePath().toString() == selection.internalData.toString(); - })); - if (!cmakeProject || !cmakeProject->activeTarget() || !cmakeProject->activeTarget()->activeBuildConfiguration()) + Utils::findOrDefault(SessionManager::projects(), [selection](Project *p) { + return p->projectFilePath().toString() == selection.internalData.toString(); + })); + if (!cmakeProject || !cmakeProject->activeTarget() + || !cmakeProject->activeTarget()->activeBuildConfiguration()) return; // Find the make step - BuildStepList *buildStepList = cmakeProject->activeTarget()->activeBuildConfiguration() - ->stepList(ProjectExplorer::Constants::BUILDSTEPS_BUILD); + BuildStepList *buildStepList = cmakeProject->activeTarget()->activeBuildConfiguration()->stepList( + ProjectExplorer::Constants::BUILDSTEPS_BUILD); auto buildStep = buildStepList->firstOfType(); if (!buildStep) return; @@ -119,14 +140,3 @@ void CMakeTargetLocatorFilter::accept(Core::LocatorFilterEntry selection, ProjectExplorerPlugin::buildProject(cmakeProject); buildStep->setBuildTarget(oldTarget); } - -void CMakeTargetLocatorFilter::refresh(QFutureInterface &future) -{ - Q_UNUSED(future) -} - -void CMakeTargetLocatorFilter::projectListUpdated() -{ - // Enable the filter if there's at least one CMake project - setEnabled(Utils::contains(SessionManager::projects(), [](Project *p) { return qobject_cast(p); })); -} diff --git a/src/plugins/cmakeprojectmanager/cmakelocatorfilter.h b/src/plugins/cmakeprojectmanager/cmakelocatorfilter.h index f07b56113b7..d68db1a4967 100644 --- a/src/plugins/cmakeprojectmanager/cmakelocatorfilter.h +++ b/src/plugins/cmakeprojectmanager/cmakelocatorfilter.h @@ -40,10 +40,6 @@ public: void prepareSearch(const QString &entry) override; QList matchesFor(QFutureInterface &future, const QString &entry) final; - void accept(Core::LocatorFilterEntry selection, - QString *newText, - int *selectionStart, - int *selectionLength) const final; void refresh(QFutureInterface &future) final; private: @@ -52,5 +48,18 @@ private: QList m_result; }; +class BuildCMakeTargetLocatorFilter : CMakeTargetLocatorFilter +{ + Q_OBJECT + +public: + BuildCMakeTargetLocatorFilter(); + + void accept(Core::LocatorFilterEntry selection, + QString *newText, + int *selectionStart, + int *selectionLength) const final; +}; + } // namespace Internal } // namespace CMakeProjectManager diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp b/src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp index 4a1aa92694f..facbcaa9f62 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp @@ -75,7 +75,7 @@ public: SimpleRunWorkerFactory runWorkerFactory; CMakeBuildConfigurationFactory buildConfigFactory; CMakeEditorFactory editorFactor; - CMakeTargetLocatorFilter locatorFiler; + BuildCMakeTargetLocatorFilter buildCMakeTargetLocatorFiler; CMakeKitAspect cmakeKitAspect; CMakeGeneratorKitAspect cmakeGeneratorKitAspect;