forked from qt-creator/qt-creator
ProjectExplorer: Add RunConfigFactory::addRunWorkerFactory convienience
There is a recurring special case that certain run controls depend on the presence of specific RunConfiguration (which in turn has it's own restriction on e.g. target or project types) but have no further restrictions. Make it easy to handle that case. Change-Id: I2e86f366591b02003f720dcc00b4c52bb2f34e00 Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
@@ -70,6 +70,10 @@ public:
|
||||
registerRunConfiguration<Android::AndroidRunConfiguration>
|
||||
("Qt4ProjectManager.AndroidRunConfiguration:");
|
||||
addSupportedTargetDeviceType(Android::Constants::ANDROID_DEVICE_TYPE);
|
||||
addRunWorkerFactory<AndroidRunSupport>(NORMAL_RUN_MODE);
|
||||
addRunWorkerFactory<AndroidDebugSupport>(DEBUG_RUN_MODE);
|
||||
addRunWorkerFactory<AndroidQmlToolingSupport>(QML_PROFILER_RUN_MODE);
|
||||
addRunWorkerFactory<AndroidQmlToolingSupport>(QML_PREVIEW_RUN_MODE);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -100,13 +104,6 @@ bool AndroidPlugin::initialize(const QStringList &arguments, QString *errorMessa
|
||||
Q_UNUSED(arguments);
|
||||
Q_UNUSED(errorMessage);
|
||||
|
||||
RunControl::registerWorker<AndroidRunConfiguration, AndroidRunSupport>(NORMAL_RUN_MODE);
|
||||
RunControl::registerWorker<AndroidRunConfiguration, AndroidDebugSupport>(DEBUG_RUN_MODE);
|
||||
RunControl::registerWorker<AndroidRunConfiguration, AndroidQmlToolingSupport>(
|
||||
QML_PROFILER_RUN_MODE);
|
||||
RunControl::registerWorker<AndroidRunConfiguration, AndroidQmlToolingSupport>(
|
||||
QML_PREVIEW_RUN_MODE);
|
||||
|
||||
RunControl::registerWorker(QML_PREVIEW_RUN_MODE, [](RunControl *runControl) -> RunWorker* {
|
||||
const Runnable runnable = runControl->runConfiguration()->runnable();
|
||||
return new AndroidQmlToolingSupport(runControl, runnable.executable, runnable.commandLineArguments);
|
||||
|
||||
@@ -76,9 +76,6 @@ bool NimPlugin::initialize(const QStringList &arguments, QString *errorMessage)
|
||||
|
||||
ToolChainManager::registerLanguage(Constants::C_NIMLANGUAGE_ID, Constants::C_NIMLANGUAGE_NAME);
|
||||
|
||||
RunControl::registerWorker<NimRunConfiguration, SimpleTargetRunner>
|
||||
(ProjectExplorer::Constants::NORMAL_RUN_MODE);
|
||||
|
||||
TextEditor::SnippetProvider::registerGroup(Constants::C_NIMSNIPPETSGROUP_ID,
|
||||
tr("Nim", "SnippetProvider"),
|
||||
&NimEditorFactory::decorateEditor);
|
||||
|
||||
@@ -101,6 +101,7 @@ NimRunConfigurationFactory::NimRunConfigurationFactory() : FixedRunConfiguration
|
||||
{
|
||||
registerRunConfiguration<NimRunConfiguration>("Nim.NimRunConfiguration");
|
||||
addSupportedProjectType(Constants::C_NIMPROJECT_ID);
|
||||
addRunWorkerFactory<SimpleTargetRunner>(ProjectExplorer::Constants::NORMAL_RUN_MODE);
|
||||
}
|
||||
|
||||
} // Nim
|
||||
|
||||
@@ -520,6 +520,8 @@ RunConfigurationFactory::RunConfigurationFactory()
|
||||
RunConfigurationFactory::~RunConfigurationFactory()
|
||||
{
|
||||
g_runConfigurationFactories.removeOne(this);
|
||||
qDeleteAll(m_ownedRunWorkerFactories);
|
||||
m_ownedRunWorkerFactories.clear();
|
||||
}
|
||||
|
||||
QString RunConfigurationFactory::decoratedTargetName(const QString targetName, Target *target)
|
||||
@@ -586,6 +588,16 @@ void RunConfigurationFactory::setDecorateDisplayNames(bool on)
|
||||
m_decorateDisplayNames = on;
|
||||
}
|
||||
|
||||
RunWorkerFactory *RunConfigurationFactory::addRunWorkerFactoryHelper
|
||||
(Core::Id runMode, const std::function<RunWorker *(RunControl *)> &creator)
|
||||
{
|
||||
auto factory = new RunWorkerFactory;
|
||||
factory->addConstraint(m_ownTypeChecker);
|
||||
factory->addSupportedRunMode(runMode);
|
||||
factory->setProducer(creator);
|
||||
return factory;
|
||||
}
|
||||
|
||||
void RunConfigurationFactory::addSupportedProjectType(Core::Id id)
|
||||
{
|
||||
m_supportedProjectTypes.append(id);
|
||||
|
||||
@@ -59,6 +59,7 @@ class RunConfiguration;
|
||||
class RunConfigurationCreationInfo;
|
||||
class RunConfigWidget;
|
||||
class RunControl;
|
||||
class RunWorkerFactory;
|
||||
class Target;
|
||||
|
||||
namespace Internal {
|
||||
@@ -301,13 +302,25 @@ protected:
|
||||
return new RunConfig(t, runConfigBaseId);
|
||||
};
|
||||
m_runConfigBaseId = runConfigBaseId;
|
||||
m_ownTypeChecker = [](RunConfiguration *runConfig) {
|
||||
return qobject_cast<RunConfig *>(runConfig) != nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
void addSupportedProjectType(Core::Id id);
|
||||
void addSupportedTargetDeviceType(Core::Id id);
|
||||
void setDecorateDisplayNames(bool on);
|
||||
|
||||
template<class Worker>
|
||||
RunWorkerFactory *addRunWorkerFactory(Core::Id runMode)
|
||||
{
|
||||
return addRunWorkerFactoryHelper(runMode, [](RunControl *rc) { return new Worker(rc); });
|
||||
}
|
||||
|
||||
private:
|
||||
RunWorkerFactory *addRunWorkerFactoryHelper
|
||||
(Core::Id runMode, const std::function<RunWorker *(RunControl *)> &creator);
|
||||
|
||||
RunConfigurationFactory(const RunConfigurationFactory &) = delete;
|
||||
RunConfigurationFactory operator=(const RunConfigurationFactory &) = delete;
|
||||
|
||||
@@ -319,6 +332,8 @@ private:
|
||||
QList<Core::Id> m_supportedProjectTypes;
|
||||
QList<Core::Id> m_supportedTargetDeviceTypes;
|
||||
bool m_decorateDisplayNames = false;
|
||||
QList<RunWorkerFactory *> m_ownedRunWorkerFactories;
|
||||
std::function<bool(RunConfiguration *)> m_ownTypeChecker;
|
||||
};
|
||||
|
||||
class PROJECTEXPLORER_EXPORT FixedRunConfigurationFactory : public RunConfigurationFactory
|
||||
@@ -421,14 +436,6 @@ public:
|
||||
m_producer = [](RunControl *rc) { return new Worker(rc); };
|
||||
}
|
||||
|
||||
template <class RunConfig>
|
||||
void setSupportedRunConfiguration()
|
||||
{
|
||||
m_constraints.append([](RunConfiguration *runConfig) {
|
||||
return qobject_cast<RunConfig *>(runConfig) != nullptr;
|
||||
});
|
||||
}
|
||||
|
||||
bool canRun(RunConfiguration *runConfiguration, Core::Id runMode) const;
|
||||
|
||||
void setPriority(int priority);
|
||||
@@ -536,15 +543,6 @@ public:
|
||||
factory->addConstraint(constraint);
|
||||
factory->setPriority(priority);
|
||||
}
|
||||
template <class Config, class Worker>
|
||||
static void registerWorker(Core::Id runMode, int priority = 0)
|
||||
{
|
||||
auto factory = new RunWorkerFactory;
|
||||
factory->registerRunWorker<Worker>();
|
||||
factory->addSupportedRunMode(runMode);
|
||||
factory->setSupportedRunConfiguration<Config>();
|
||||
factory->setPriority(priority);
|
||||
}
|
||||
|
||||
static WorkerCreator producer(RunConfiguration *runConfiguration, Core::Id runMode);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user