forked from qt-creator/qt-creator
RunConfigurationLocatorFilter: Use Acceptor for LocatorFilterEntry
Change-Id: Ia48aa149ee2c4cd3653ba7a4313f1578034ad9d8 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -41,6 +41,7 @@
|
|||||||
#include "devicesupport/sshsettings.h"
|
#include "devicesupport/sshsettings.h"
|
||||||
#include "devicesupport/sshsettingspage.h"
|
#include "devicesupport/sshsettingspage.h"
|
||||||
#include "editorsettingspropertiespage.h"
|
#include "editorsettingspropertiespage.h"
|
||||||
|
#include "environmentaspect.h"
|
||||||
#include "filesinallprojectsfind.h"
|
#include "filesinallprojectsfind.h"
|
||||||
#include "jsonwizard/jsonwizardfactory.h"
|
#include "jsonwizard/jsonwizardfactory.h"
|
||||||
#include "jsonwizard/jsonwizardgeneratorfactory.h"
|
#include "jsonwizard/jsonwizardgeneratorfactory.h"
|
||||||
@@ -65,7 +66,6 @@
|
|||||||
#include "projecttreewidget.h"
|
#include "projecttreewidget.h"
|
||||||
#include "projectwindow.h"
|
#include "projectwindow.h"
|
||||||
#include "removetaskhandler.h"
|
#include "removetaskhandler.h"
|
||||||
#include "runconfigurationaspects.h"
|
|
||||||
#include "sanitizerparser.h"
|
#include "sanitizerparser.h"
|
||||||
#include "selectablefilesmodel.h"
|
#include "selectablefilesmodel.h"
|
||||||
#include "session.h"
|
#include "session.h"
|
||||||
@@ -416,32 +416,26 @@ 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) override;
|
const QString &entry) override;
|
||||||
|
protected:
|
||||||
|
using RunAcceptor = std::function<void(RunConfiguration *)>;
|
||||||
|
void setRunAcceptor(const RunAcceptor &acceptor) { m_acceptor = acceptor; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void targetListUpdated();
|
void targetListUpdated();
|
||||||
QList<Core::LocatorFilterEntry> m_result;
|
QList<Core::LocatorFilterEntry> m_result;
|
||||||
|
RunAcceptor m_acceptor;
|
||||||
};
|
};
|
||||||
|
|
||||||
class RunRunConfigurationLocatorFilter final : public RunConfigurationLocatorFilter
|
class RunRunConfigurationLocatorFilter final : public RunConfigurationLocatorFilter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RunRunConfigurationLocatorFilter();
|
RunRunConfigurationLocatorFilter();
|
||||||
|
|
||||||
void accept(const Core::LocatorFilterEntry &selection,
|
|
||||||
QString *newText,
|
|
||||||
int *selectionStart,
|
|
||||||
int *selectionLength) const final;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class SwitchToRunConfigurationLocatorFilter final : public RunConfigurationLocatorFilter
|
class SwitchToRunConfigurationLocatorFilter final : public RunConfigurationLocatorFilter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SwitchToRunConfigurationLocatorFilter();
|
SwitchToRunConfigurationLocatorFilter();
|
||||||
|
|
||||||
void accept(const Core::LocatorFilterEntry &selection,
|
|
||||||
QString *newText,
|
|
||||||
int *selectionStart,
|
|
||||||
int *selectionLength) const final;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class ProjectExplorerPluginPrivate : public QObject
|
class ProjectExplorerPluginPrivate : public QObject
|
||||||
@@ -4400,6 +4394,17 @@ RunConfigurationLocatorFilter::RunConfigurationLocatorFilter()
|
|||||||
targetListUpdated();
|
targetListUpdated();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static RunConfiguration *runConfigurationForDisplayName(const QString &displayName)
|
||||||
|
{
|
||||||
|
const Target *target = ProjectManager::startupTarget();
|
||||||
|
if (!target)
|
||||||
|
return nullptr;
|
||||||
|
const QList<RunConfiguration *> runconfigs = target->runConfigurations();
|
||||||
|
return Utils::findOrDefault(runconfigs, [displayName](RunConfiguration *rc) {
|
||||||
|
return rc->displayName() == displayName;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void RunConfigurationLocatorFilter::prepareSearch(const QString &entry)
|
void RunConfigurationLocatorFilter::prepareSearch(const QString &entry)
|
||||||
{
|
{
|
||||||
m_result.clear();
|
m_result.clear();
|
||||||
@@ -4407,8 +4412,18 @@ void RunConfigurationLocatorFilter::prepareSearch(const QString &entry)
|
|||||||
if (!target)
|
if (!target)
|
||||||
return;
|
return;
|
||||||
for (auto rc : target->runConfigurations()) {
|
for (auto rc : target->runConfigurations()) {
|
||||||
if (rc->displayName().contains(entry, Qt::CaseInsensitive))
|
if (rc->displayName().contains(entry, Qt::CaseInsensitive)) {
|
||||||
m_result.append(LocatorFilterEntry(this, rc->displayName()));
|
LocatorFilterEntry entry;
|
||||||
|
entry.displayName = rc->displayName();
|
||||||
|
entry.acceptor = [name = entry.displayName, acceptor = m_acceptor] {
|
||||||
|
RunConfiguration *config = runConfigurationForDisplayName(name);
|
||||||
|
if (!config)
|
||||||
|
return AcceptResult();
|
||||||
|
acceptor(config);
|
||||||
|
return AcceptResult();
|
||||||
|
};
|
||||||
|
m_result.append(entry);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4425,17 +4440,6 @@ void RunConfigurationLocatorFilter::targetListUpdated()
|
|||||||
setEnabled(ProjectManager::startupProject()); // at least one project opened
|
setEnabled(ProjectManager::startupProject()); // at least one project opened
|
||||||
}
|
}
|
||||||
|
|
||||||
static RunConfiguration *runConfigurationForDisplayName(const QString &displayName)
|
|
||||||
{
|
|
||||||
const Project *project = ProjectManager::instance()->startupProject();
|
|
||||||
if (!project)
|
|
||||||
return nullptr;
|
|
||||||
const QList<RunConfiguration *> runconfigs = project->activeTarget()->runConfigurations();
|
|
||||||
return Utils::findOrDefault(runconfigs, [displayName](RunConfiguration *rc) {
|
|
||||||
return rc->displayName() == displayName;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
RunRunConfigurationLocatorFilter::RunRunConfigurationLocatorFilter()
|
RunRunConfigurationLocatorFilter::RunRunConfigurationLocatorFilter()
|
||||||
{
|
{
|
||||||
setId("Run run configuration");
|
setId("Run run configuration");
|
||||||
@@ -4443,20 +4447,10 @@ RunRunConfigurationLocatorFilter::RunRunConfigurationLocatorFilter()
|
|||||||
setDescription(Tr::tr("Runs a run configuration of the active project."));
|
setDescription(Tr::tr("Runs a run configuration of the active project."));
|
||||||
setDefaultShortcutString("rr");
|
setDefaultShortcutString("rr");
|
||||||
setPriority(Medium);
|
setPriority(Medium);
|
||||||
}
|
setRunAcceptor([](RunConfiguration *config) {
|
||||||
|
if (!BuildManager::isBuilding(config->project()))
|
||||||
void RunRunConfigurationLocatorFilter::accept(const LocatorFilterEntry &selection, QString *newText,
|
ProjectExplorerPlugin::runRunConfiguration(config, Constants::NORMAL_RUN_MODE, true);
|
||||||
int *selectionStart, int *selectionLength) const
|
});
|
||||||
{
|
|
||||||
Q_UNUSED(newText)
|
|
||||||
Q_UNUSED(selectionStart)
|
|
||||||
Q_UNUSED(selectionLength)
|
|
||||||
|
|
||||||
RunConfiguration *toStart = runConfigurationForDisplayName(selection.displayName);
|
|
||||||
if (!toStart)
|
|
||||||
return;
|
|
||||||
if (!BuildManager::isBuilding(toStart->project()))
|
|
||||||
ProjectExplorerPlugin::runRunConfiguration(toStart, Constants::NORMAL_RUN_MODE, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SwitchToRunConfigurationLocatorFilter::SwitchToRunConfigurationLocatorFilter()
|
SwitchToRunConfigurationLocatorFilter::SwitchToRunConfigurationLocatorFilter()
|
||||||
@@ -4466,27 +4460,15 @@ SwitchToRunConfigurationLocatorFilter::SwitchToRunConfigurationLocatorFilter()
|
|||||||
setDescription(Tr::tr("Switches the active run configuration of the active project."));
|
setDescription(Tr::tr("Switches the active run configuration of the active project."));
|
||||||
setDefaultShortcutString("sr");
|
setDefaultShortcutString("sr");
|
||||||
setPriority(Medium);
|
setPriority(Medium);
|
||||||
}
|
setRunAcceptor([](RunConfiguration *config) {
|
||||||
|
ProjectManager::startupTarget()->setActiveRunConfiguration(config);
|
||||||
void SwitchToRunConfigurationLocatorFilter::accept(const LocatorFilterEntry &selection,
|
QTimer::singleShot(200, ICore::mainWindow(), [displayName = config->displayName()] {
|
||||||
QString *newText, int *selectionStart,
|
if (auto ks = ICore::mainWindow()->findChild<QWidget *>("KitSelector.Button")) {
|
||||||
int *selectionLength) const
|
Utils::ToolTip::show(ks->mapToGlobal(QPoint{25, 25}),
|
||||||
{
|
Tr::tr("Switched run configuration to\n%1").arg(displayName),
|
||||||
Q_UNUSED(newText)
|
ICore::dialogParent());
|
||||||
Q_UNUSED(selectionStart)
|
}
|
||||||
Q_UNUSED(selectionLength)
|
});
|
||||||
|
|
||||||
RunConfiguration *toSwitchTo = runConfigurationForDisplayName(selection.displayName);
|
|
||||||
if (!toSwitchTo)
|
|
||||||
return;
|
|
||||||
|
|
||||||
ProjectManager::startupTarget()->setActiveRunConfiguration(toSwitchTo);
|
|
||||||
QTimer::singleShot(200, this, [displayName = selection.displayName] {
|
|
||||||
if (auto ks = ICore::mainWindow()->findChild<QWidget *>("KitSelector.Button")) {
|
|
||||||
Utils::ToolTip::show(ks->mapToGlobal(QPoint{25, 25}),
|
|
||||||
Tr::tr("Switched run configuration to\n%1").arg(displayName),
|
|
||||||
ICore::dialogParent());
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user