CMake: Split up cmake's locator filter

Split up CMake's locator filter into a part that contains all
the logic to find targets and a part that handles the action.

This is so that the code used to search for targets can be reused
later.

Change-Id: Ife6c9fe6a6f1955bedaa1b9298630c052e17c33f
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Tobias Hunger
2019-07-24 13:48:24 +02:00
parent efc89ff60d
commit 979b0463e8
3 changed files with 48 additions and 29 deletions

View File

@@ -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<Core::LocatorFilterEntry> CMakeTargetLocatorFilter::matchesFor(QFutureInte
return m_result;
}
void CMakeTargetLocatorFilter::accept(Core::LocatorFilterEntry selection,
QString *newText, int *selectionStart, int *selectionLength) const
void CMakeTargetLocatorFilter::refresh(QFutureInterface<void> &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<CMakeProject *>(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<CMakeProject *>(
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<CMakeBuildStep>();
if (!buildStep)
return;
@@ -119,14 +140,3 @@ void CMakeTargetLocatorFilter::accept(Core::LocatorFilterEntry selection,
ProjectExplorerPlugin::buildProject(cmakeProject);
buildStep->setBuildTarget(oldTarget);
}
void CMakeTargetLocatorFilter::refresh(QFutureInterface<void> &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<CMakeProject *>(p); }));
}

View File

@@ -40,10 +40,6 @@ public:
void prepareSearch(const QString &entry) override;
QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future,
const QString &entry) final;
void accept(Core::LocatorFilterEntry selection,
QString *newText,
int *selectionStart,
int *selectionLength) const final;
void refresh(QFutureInterface<void> &future) final;
private:
@@ -52,5 +48,18 @@ private:
QList<Core::LocatorFilterEntry> 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

View File

@@ -75,7 +75,7 @@ public:
SimpleRunWorkerFactory<SimpleTargetRunner, CMakeRunConfiguration> runWorkerFactory;
CMakeBuildConfigurationFactory buildConfigFactory;
CMakeEditorFactory editorFactor;
CMakeTargetLocatorFilter locatorFiler;
BuildCMakeTargetLocatorFilter buildCMakeTargetLocatorFiler;
CMakeKitAspect cmakeKitAspect;
CMakeGeneratorKitAspect cmakeGeneratorKitAspect;