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()
|
const FilePath path = target.backtrace.isEmpty() ? cmakeProject->projectFilePath()
|
||||||
: target.backtrace.last().path;
|
: target.backtrace.last().path;
|
||||||
const int line = target.backtrace.isEmpty() ? 0 : target.backtrace.last().line;
|
const int line = target.backtrace.isEmpty() ? 0 : target.backtrace.last().line;
|
||||||
|
const FilePath projectPath = cmakeProject->projectFilePath();
|
||||||
LocatorFilterEntry filterEntry(this, target.title);
|
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.linkForEditor = {path, line};
|
||||||
filterEntry.extraInfo = path.shortNativePath();
|
filterEntry.extraInfo = path.shortNativePath();
|
||||||
filterEntry.highlightInfo = {index, int(entry.length())};
|
filterEntry.highlightInfo = {index, int(entry.length())};
|
||||||
@@ -96,17 +104,7 @@ BuildCMakeTargetLocatorFilter::BuildCMakeTargetLocatorFilter()
|
|||||||
setDescription(Tr::tr("Builds a target of any open CMake project."));
|
setDescription(Tr::tr("Builds a target of any open CMake project."));
|
||||||
setDefaultShortcutString("cm");
|
setDefaultShortcutString("cm");
|
||||||
setPriority(High);
|
setPriority(High);
|
||||||
}
|
setBuildAcceptor([](const Utils::FilePath &projectPath, const QString &displayName) {
|
||||||
|
|
||||||
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
|
// Get the project containing the target selected
|
||||||
const auto cmakeProject = qobject_cast<CMakeProject *>(
|
const auto cmakeProject = qobject_cast<CMakeProject *>(
|
||||||
Utils::findOrDefault(ProjectManager::projects(), [projectPath](Project *p) {
|
Utils::findOrDefault(ProjectManager::projects(), [projectPath](Project *p) {
|
||||||
@@ -125,11 +123,12 @@ void BuildCMakeTargetLocatorFilter::accept(const LocatorFilterEntry &selection,
|
|||||||
|
|
||||||
// Change the make step to build only the given target
|
// Change the make step to build only the given target
|
||||||
QStringList oldTargets = buildStep->buildTargets();
|
QStringList oldTargets = buildStep->buildTargets();
|
||||||
buildStep->setBuildTargets({selection.displayName});
|
buildStep->setBuildTargets({displayName});
|
||||||
|
|
||||||
// Build
|
// Build
|
||||||
BuildManager::buildProjectWithDependencies(cmakeProject);
|
BuildManager::buildProjectWithDependencies(cmakeProject);
|
||||||
buildStep->setBuildTargets(oldTargets);
|
buildStep->setBuildTargets(oldTargets);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
|
@@ -15,22 +15,21 @@ 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;
|
||||||
|
protected:
|
||||||
|
using BuildAcceptor = std::function<void(const Utils::FilePath &, const QString &)>;
|
||||||
|
void setBuildAcceptor(const BuildAcceptor &acceptor) { m_acceptor = acceptor; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void projectListUpdated();
|
void projectListUpdated();
|
||||||
|
|
||||||
QList<Core::LocatorFilterEntry> m_result;
|
QList<Core::LocatorFilterEntry> m_result;
|
||||||
|
BuildAcceptor m_acceptor;
|
||||||
};
|
};
|
||||||
|
|
||||||
class BuildCMakeTargetLocatorFilter : CMakeTargetLocatorFilter
|
class BuildCMakeTargetLocatorFilter : CMakeTargetLocatorFilter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BuildCMakeTargetLocatorFilter();
|
BuildCMakeTargetLocatorFilter();
|
||||||
|
|
||||||
void accept(const Core::LocatorFilterEntry &selection,
|
|
||||||
QString *newText,
|
|
||||||
int *selectionStart,
|
|
||||||
int *selectionLength) const final;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class OpenCMakeTargetLocatorFilter : CMakeTargetLocatorFilter
|
class OpenCMakeTargetLocatorFilter : CMakeTargetLocatorFilter
|
||||||
|
Reference in New Issue
Block a user