forked from qt-creator/qt-creator
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:
@@ -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,8 +84,33 @@ 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)
|
||||
@@ -100,12 +120,13 @@ void CMakeTargetLocatorFilter::accept(Core::LocatorFilterEntry selection,
|
||||
Utils::findOrDefault(SessionManager::projects(), [selection](Project *p) {
|
||||
return p->projectFilePath().toString() == selection.internalData.toString();
|
||||
}));
|
||||
if (!cmakeProject || !cmakeProject->activeTarget() || !cmakeProject->activeTarget()->activeBuildConfiguration())
|
||||
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); }));
|
||||
}
|
||||
|
@@ -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
|
||||
|
@@ -75,7 +75,7 @@ public:
|
||||
SimpleRunWorkerFactory<SimpleTargetRunner, CMakeRunConfiguration> runWorkerFactory;
|
||||
CMakeBuildConfigurationFactory buildConfigFactory;
|
||||
CMakeEditorFactory editorFactor;
|
||||
CMakeTargetLocatorFilter locatorFiler;
|
||||
BuildCMakeTargetLocatorFilter buildCMakeTargetLocatorFiler;
|
||||
|
||||
CMakeKitAspect cmakeKitAspect;
|
||||
CMakeGeneratorKitAspect cmakeGeneratorKitAspect;
|
||||
|
Reference in New Issue
Block a user