ProjectExplorer: Streamline use of WorkerFactories

Change-Id: I58693457f6441f6992cae61365a58b3d2d933986
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2017-07-18 14:55:54 +02:00
parent 1d682f2144
commit 9523f1f899

View File

@@ -1982,22 +1982,6 @@ void ProjectExplorerPluginPrivate::buildStateChanged(Project * pro)
updateActions(); updateActions();
} }
// NBS TODO implement more than one runner
using RunControlFactory = std::function<RunControl *(RunConfiguration *, Core::Id, QString *)>;
static RunControlFactory findRunControlFactory(RunConfiguration *config, Core::Id mode)
{
if (auto producer = RunControl::producer(config, mode)) {
return [producer, config](RunConfiguration *rc, Id runMode, QString *) {
auto runControl = new RunControl(rc, runMode);
(void) producer(runControl);
return runControl;
};
}
return {};
}
void ProjectExplorerPluginPrivate::executeRunConfiguration(RunConfiguration *runConfiguration, Core::Id runMode) void ProjectExplorerPluginPrivate::executeRunConfiguration(RunConfiguration *runConfiguration, Core::Id runMode)
{ {
if (!runConfiguration->isConfigured()) { if (!runConfiguration->isConfigured()) {
@@ -2015,17 +1999,15 @@ void ProjectExplorerPluginPrivate::executeRunConfiguration(RunConfiguration *run
} }
} }
if (RunControlFactory runControlFactory = findRunControlFactory(runConfiguration, runMode)) { RunControl::WorkerCreator producer = RunControl::producer(runConfiguration, runMode);
emit m_instance->aboutToExecuteProject(runConfiguration->target()->project(), runMode);
QString errorMessage; QTC_ASSERT(producer, return);
RunControl *control = runControlFactory(runConfiguration, runMode, &errorMessage); auto runControl = new RunControl(runConfiguration, runMode);
if (!control) { (void) producer(runControl);
m_instance->showRunErrorMessage(errorMessage);
return; emit m_instance->aboutToExecuteProject(runConfiguration->target()->project(), runMode);
}
startRunControl(control); startRunControl(runControl);
}
} }
void ProjectExplorerPlugin::showRunErrorMessage(const QString &errorMessage) void ProjectExplorerPlugin::showRunErrorMessage(const QString &errorMessage)
@@ -2793,7 +2775,8 @@ bool ProjectExplorerPlugin::canRunStartupProject(Core::Id runMode, QString *whyN
} }
// shouldn't actually be shown to the user... // shouldn't actually be shown to the user...
if (!findRunControlFactory(activeRC, runMode)) { RunControl::WorkerCreator producer = RunControl::producer(activeRC, runMode);
if (!producer) {
if (whyNot) if (whyNot)
*whyNot = tr("Cannot run \"%1\".").arg(activeRC->displayName()); *whyNot = tr("Cannot run \"%1\".").arg(activeRC->displayName());
return false; return false;