forked from qt-creator/qt-creator
CMakeTargetLocatorFilter: Use Acceptor for LocatorFilterEntry
Change-Id: I5f82853bab8fdc38ae0793e9865c6d1da10f8ccd Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Cristian Adam <cristian.adam@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -57,8 +57,16 @@ void CMakeTargetLocatorFilter::prepareSearch(const QString &entry)
|
||||
const FilePath path = target.backtrace.isEmpty() ? cmakeProject->projectFilePath()
|
||||
: target.backtrace.last().path;
|
||||
const int line = target.backtrace.isEmpty() ? 0 : target.backtrace.last().line;
|
||||
|
||||
LocatorFilterEntry filterEntry(this, target.title);
|
||||
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())};
|
||||
@@ -96,40 +104,31 @@ BuildCMakeTargetLocatorFilter::BuildCMakeTargetLocatorFilter()
|
||||
setDescription(Tr::tr("Builds a target of any open CMake project."));
|
||||
setDefaultShortcutString("cm");
|
||||
setPriority(High);
|
||||
}
|
||||
setBuildAcceptor([](const Utils::FilePath &projectPath, const QString &displayName) {
|
||||
// Get the project containing the target selected
|
||||
const auto cmakeProject = qobject_cast<CMakeProject *>(
|
||||
Utils::findOrDefault(ProjectManager::projects(), [projectPath](Project *p) {
|
||||
return p->projectFilePath() == projectPath;
|
||||
}));
|
||||
if (!cmakeProject || !cmakeProject->activeTarget()
|
||||
|| !cmakeProject->activeTarget()->activeBuildConfiguration())
|
||||
return;
|
||||
|
||||
void BuildCMakeTargetLocatorFilter::accept(const LocatorFilterEntry &selection, QString *newText,
|
||||
int *selectionStart, int *selectionLength) const
|
||||
{
|
||||
Q_UNUSED(newText)
|
||||
Q_UNUSED(selectionStart)
|
||||
Q_UNUSED(selectionLength)
|
||||
|
||||
const FilePath projectPath = selection.filePath;
|
||||
|
||||
// Get the project containing the target selected
|
||||
const auto cmakeProject = qobject_cast<CMakeProject *>(
|
||||
Utils::findOrDefault(ProjectManager::projects(), [projectPath](Project *p) {
|
||||
return p->projectFilePath() == projectPath;
|
||||
}));
|
||||
if (!cmakeProject || !cmakeProject->activeTarget()
|
||||
|| !cmakeProject->activeTarget()->activeBuildConfiguration())
|
||||
return;
|
||||
|
||||
// Find the make step
|
||||
BuildStepList *buildStepList =
|
||||
// Find the make step
|
||||
BuildStepList *buildStepList =
|
||||
cmakeProject->activeTarget()->activeBuildConfiguration()->buildSteps();
|
||||
auto buildStep = buildStepList->firstOfType<CMakeBuildStep>();
|
||||
if (!buildStep)
|
||||
return;
|
||||
auto buildStep = buildStepList->firstOfType<CMakeBuildStep>();
|
||||
if (!buildStep)
|
||||
return;
|
||||
|
||||
// Change the make step to build only the given target
|
||||
QStringList oldTargets = buildStep->buildTargets();
|
||||
buildStep->setBuildTargets({selection.displayName});
|
||||
// Change the make step to build only the given target
|
||||
QStringList oldTargets = buildStep->buildTargets();
|
||||
buildStep->setBuildTargets({displayName});
|
||||
|
||||
// Build
|
||||
BuildManager::buildProjectWithDependencies(cmakeProject);
|
||||
buildStep->setBuildTargets(oldTargets);
|
||||
// Build
|
||||
BuildManager::buildProjectWithDependencies(cmakeProject);
|
||||
buildStep->setBuildTargets(oldTargets);
|
||||
});
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
@@ -15,22 +15,21 @@ public:
|
||||
void prepareSearch(const QString &entry) override;
|
||||
QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future,
|
||||
const QString &entry) final;
|
||||
protected:
|
||||
using BuildAcceptor = std::function<void(const Utils::FilePath &, const QString &)>;
|
||||
void setBuildAcceptor(const BuildAcceptor &acceptor) { m_acceptor = acceptor; }
|
||||
|
||||
private:
|
||||
void projectListUpdated();
|
||||
|
||||
QList<Core::LocatorFilterEntry> m_result;
|
||||
BuildAcceptor m_acceptor;
|
||||
};
|
||||
|
||||
class BuildCMakeTargetLocatorFilter : CMakeTargetLocatorFilter
|
||||
{
|
||||
public:
|
||||
BuildCMakeTargetLocatorFilter();
|
||||
|
||||
void accept(const Core::LocatorFilterEntry &selection,
|
||||
QString *newText,
|
||||
int *selectionStart,
|
||||
int *selectionLength) const final;
|
||||
};
|
||||
|
||||
class OpenCMakeTargetLocatorFilter : CMakeTargetLocatorFilter
|
||||
|
Reference in New Issue
Block a user