forked from qt-creator/qt-creator
ProjectExplorer: Simplify standard run control construction
A lot of the target-and-tool specific run controls nowadays have something like a single main RunWorker. This patch removes the need to have user-implemented RunControlFactories in those cases and adjusts local run, remote linux, python and nim to take advantage. There's more potential use downstream. Change-Id: Ie2d2f839b8be1fad2be3b79e21de3c0e475d88cf Reviewed-by: Christian Kandeler <christian.kandeler@qt.io> Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -655,30 +655,6 @@ bool PythonProjectNode::renameFile(const QString &filePath, const QString &newFi
|
||||
return m_project->renameFile(filePath, newFilePath);
|
||||
}
|
||||
|
||||
// PythonRunControlFactory
|
||||
|
||||
class PythonRunControlFactory : public IRunControlFactory
|
||||
{
|
||||
public:
|
||||
bool canRun(RunConfiguration *runConfiguration, Core::Id mode) const override;
|
||||
RunControl *create(RunConfiguration *runConfiguration, Core::Id mode, QString *errorMessage) override;
|
||||
};
|
||||
|
||||
bool PythonRunControlFactory::canRun(RunConfiguration *runConfiguration, Core::Id mode) const
|
||||
{
|
||||
auto rc = dynamic_cast<PythonRunConfiguration *>(runConfiguration);
|
||||
return mode == ProjectExplorer::Constants::NORMAL_RUN_MODE && rc && !rc->interpreter().isEmpty();
|
||||
}
|
||||
|
||||
RunControl *PythonRunControlFactory::create(RunConfiguration *runConfiguration, Core::Id mode, QString *errorMessage)
|
||||
{
|
||||
Q_UNUSED(errorMessage)
|
||||
QTC_ASSERT(canRun(runConfiguration, mode), return 0);
|
||||
auto runControl = new RunControl(runConfiguration, mode);
|
||||
(void) new SimpleTargetRunner(runControl);
|
||||
return runControl;
|
||||
}
|
||||
|
||||
// PythonRunConfigurationWidget
|
||||
|
||||
void PythonRunConfigurationWidget::setInterpreter(const QString &interpreter)
|
||||
@@ -713,7 +689,12 @@ bool PythonEditorPlugin::initialize(const QStringList &arguments, QString *error
|
||||
|
||||
addAutoReleasedObject(new PythonEditorFactory);
|
||||
addAutoReleasedObject(new PythonRunConfigurationFactory);
|
||||
addAutoReleasedObject(new PythonRunControlFactory);
|
||||
|
||||
auto constraint = [](RunConfiguration *runConfiguration) {
|
||||
auto rc = dynamic_cast<PythonRunConfiguration *>(runConfiguration);
|
||||
return rc && !rc->interpreter().isEmpty();
|
||||
};
|
||||
RunControl::registerWorker<SimpleTargetRunner>(ProjectExplorer::Constants::NORMAL_RUN_MODE, constraint);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user