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()
|
CMakeTargetLocatorFilter::CMakeTargetLocatorFilter()
|
||||||
{
|
{
|
||||||
setId("Build CMake target");
|
|
||||||
setDisplayName(tr("Build CMake target"));
|
|
||||||
setShortcutString("cm");
|
|
||||||
setPriority(High);
|
|
||||||
|
|
||||||
connect(SessionManager::instance(), &SessionManager::projectAdded,
|
connect(SessionManager::instance(), &SessionManager::projectAdded,
|
||||||
this, &CMakeTargetLocatorFilter::projectListUpdated);
|
this, &CMakeTargetLocatorFilter::projectListUpdated);
|
||||||
connect(SessionManager::instance(), &SessionManager::projectRemoved,
|
connect(SessionManager::instance(), &SessionManager::projectRemoved,
|
||||||
@@ -89,23 +84,49 @@ QList<Core::LocatorFilterEntry> CMakeTargetLocatorFilter::matchesFor(QFutureInte
|
|||||||
return m_result;
|
return m_result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMakeTargetLocatorFilter::accept(Core::LocatorFilterEntry selection,
|
void CMakeTargetLocatorFilter::refresh(QFutureInterface<void> &future)
|
||||||
QString *newText, int *selectionStart, int *selectionLength) const
|
{
|
||||||
|
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(newText)
|
||||||
Q_UNUSED(selectionStart)
|
Q_UNUSED(selectionStart)
|
||||||
Q_UNUSED(selectionLength)
|
Q_UNUSED(selectionLength)
|
||||||
// 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 *>(
|
||||||
Utils::findOrDefault(SessionManager::projects(), [selection](Project *p) {
|
Utils::findOrDefault(SessionManager::projects(), [selection](Project *p) {
|
||||||
return p->projectFilePath().toString() == selection.internalData.toString();
|
return p->projectFilePath().toString() == selection.internalData.toString();
|
||||||
}));
|
}));
|
||||||
if (!cmakeProject || !cmakeProject->activeTarget() || !cmakeProject->activeTarget()->activeBuildConfiguration())
|
if (!cmakeProject || !cmakeProject->activeTarget()
|
||||||
|
|| !cmakeProject->activeTarget()->activeBuildConfiguration())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Find the make step
|
// Find the make step
|
||||||
BuildStepList *buildStepList = cmakeProject->activeTarget()->activeBuildConfiguration()
|
BuildStepList *buildStepList = cmakeProject->activeTarget()->activeBuildConfiguration()->stepList(
|
||||||
->stepList(ProjectExplorer::Constants::BUILDSTEPS_BUILD);
|
ProjectExplorer::Constants::BUILDSTEPS_BUILD);
|
||||||
auto buildStep = buildStepList->firstOfType<CMakeBuildStep>();
|
auto buildStep = buildStepList->firstOfType<CMakeBuildStep>();
|
||||||
if (!buildStep)
|
if (!buildStep)
|
||||||
return;
|
return;
|
||||||
@@ -119,14 +140,3 @@ void CMakeTargetLocatorFilter::accept(Core::LocatorFilterEntry selection,
|
|||||||
ProjectExplorerPlugin::buildProject(cmakeProject);
|
ProjectExplorerPlugin::buildProject(cmakeProject);
|
||||||
buildStep->setBuildTarget(oldTarget);
|
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;
|
void prepareSearch(const QString &entry) override;
|
||||||
QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future,
|
QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future,
|
||||||
const QString &entry) final;
|
const QString &entry) final;
|
||||||
void accept(Core::LocatorFilterEntry selection,
|
|
||||||
QString *newText,
|
|
||||||
int *selectionStart,
|
|
||||||
int *selectionLength) const final;
|
|
||||||
void refresh(QFutureInterface<void> &future) final;
|
void refresh(QFutureInterface<void> &future) final;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -52,5 +48,18 @@ private:
|
|||||||
QList<Core::LocatorFilterEntry> m_result;
|
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 Internal
|
||||||
} // namespace CMakeProjectManager
|
} // namespace CMakeProjectManager
|
||||||
|
@@ -75,7 +75,7 @@ public:
|
|||||||
SimpleRunWorkerFactory<SimpleTargetRunner, CMakeRunConfiguration> runWorkerFactory;
|
SimpleRunWorkerFactory<SimpleTargetRunner, CMakeRunConfiguration> runWorkerFactory;
|
||||||
CMakeBuildConfigurationFactory buildConfigFactory;
|
CMakeBuildConfigurationFactory buildConfigFactory;
|
||||||
CMakeEditorFactory editorFactor;
|
CMakeEditorFactory editorFactor;
|
||||||
CMakeTargetLocatorFilter locatorFiler;
|
BuildCMakeTargetLocatorFilter buildCMakeTargetLocatorFiler;
|
||||||
|
|
||||||
CMakeKitAspect cmakeKitAspect;
|
CMakeKitAspect cmakeKitAspect;
|
||||||
CMakeGeneratorKitAspect cmakeGeneratorKitAspect;
|
CMakeGeneratorKitAspect cmakeGeneratorKitAspect;
|
||||||
|
Reference in New Issue
Block a user