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>
|
registerRunConfiguration<Android::AndroidRunConfiguration>
|
||||||
("Qt4ProjectManager.AndroidRunConfiguration:");
|
("Qt4ProjectManager.AndroidRunConfiguration:");
|
||||||
addSupportedTargetDeviceType(Android::Constants::ANDROID_DEVICE_TYPE);
|
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(arguments);
|
||||||
Q_UNUSED(errorMessage);
|
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* {
|
RunControl::registerWorker(QML_PREVIEW_RUN_MODE, [](RunControl *runControl) -> RunWorker* {
|
||||||
const Runnable runnable = runControl->runConfiguration()->runnable();
|
const Runnable runnable = runControl->runConfiguration()->runnable();
|
||||||
return new AndroidQmlToolingSupport(runControl, runnable.executable, runnable.commandLineArguments);
|
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);
|
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,
|
TextEditor::SnippetProvider::registerGroup(Constants::C_NIMSNIPPETSGROUP_ID,
|
||||||
tr("Nim", "SnippetProvider"),
|
tr("Nim", "SnippetProvider"),
|
||||||
&NimEditorFactory::decorateEditor);
|
&NimEditorFactory::decorateEditor);
|
||||||
|
|||||||
@@ -101,6 +101,7 @@ NimRunConfigurationFactory::NimRunConfigurationFactory() : FixedRunConfiguration
|
|||||||
{
|
{
|
||||||
registerRunConfiguration<NimRunConfiguration>("Nim.NimRunConfiguration");
|
registerRunConfiguration<NimRunConfiguration>("Nim.NimRunConfiguration");
|
||||||
addSupportedProjectType(Constants::C_NIMPROJECT_ID);
|
addSupportedProjectType(Constants::C_NIMPROJECT_ID);
|
||||||
|
addRunWorkerFactory<SimpleTargetRunner>(ProjectExplorer::Constants::NORMAL_RUN_MODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // Nim
|
} // Nim
|
||||||
|
|||||||
@@ -520,6 +520,8 @@ RunConfigurationFactory::RunConfigurationFactory()
|
|||||||
RunConfigurationFactory::~RunConfigurationFactory()
|
RunConfigurationFactory::~RunConfigurationFactory()
|
||||||
{
|
{
|
||||||
g_runConfigurationFactories.removeOne(this);
|
g_runConfigurationFactories.removeOne(this);
|
||||||
|
qDeleteAll(m_ownedRunWorkerFactories);
|
||||||
|
m_ownedRunWorkerFactories.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString RunConfigurationFactory::decoratedTargetName(const QString targetName, Target *target)
|
QString RunConfigurationFactory::decoratedTargetName(const QString targetName, Target *target)
|
||||||
@@ -586,6 +588,16 @@ void RunConfigurationFactory::setDecorateDisplayNames(bool on)
|
|||||||
m_decorateDisplayNames = 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)
|
void RunConfigurationFactory::addSupportedProjectType(Core::Id id)
|
||||||
{
|
{
|
||||||
m_supportedProjectTypes.append(id);
|
m_supportedProjectTypes.append(id);
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ class RunConfiguration;
|
|||||||
class RunConfigurationCreationInfo;
|
class RunConfigurationCreationInfo;
|
||||||
class RunConfigWidget;
|
class RunConfigWidget;
|
||||||
class RunControl;
|
class RunControl;
|
||||||
|
class RunWorkerFactory;
|
||||||
class Target;
|
class Target;
|
||||||
|
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
@@ -301,13 +302,25 @@ protected:
|
|||||||
return new RunConfig(t, runConfigBaseId);
|
return new RunConfig(t, runConfigBaseId);
|
||||||
};
|
};
|
||||||
m_runConfigBaseId = runConfigBaseId;
|
m_runConfigBaseId = runConfigBaseId;
|
||||||
|
m_ownTypeChecker = [](RunConfiguration *runConfig) {
|
||||||
|
return qobject_cast<RunConfig *>(runConfig) != nullptr;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void addSupportedProjectType(Core::Id id);
|
void addSupportedProjectType(Core::Id id);
|
||||||
void addSupportedTargetDeviceType(Core::Id id);
|
void addSupportedTargetDeviceType(Core::Id id);
|
||||||
void setDecorateDisplayNames(bool on);
|
void setDecorateDisplayNames(bool on);
|
||||||
|
|
||||||
|
template<class Worker>
|
||||||
|
RunWorkerFactory *addRunWorkerFactory(Core::Id runMode)
|
||||||
|
{
|
||||||
|
return addRunWorkerFactoryHelper(runMode, [](RunControl *rc) { return new Worker(rc); });
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
RunWorkerFactory *addRunWorkerFactoryHelper
|
||||||
|
(Core::Id runMode, const std::function<RunWorker *(RunControl *)> &creator);
|
||||||
|
|
||||||
RunConfigurationFactory(const RunConfigurationFactory &) = delete;
|
RunConfigurationFactory(const RunConfigurationFactory &) = delete;
|
||||||
RunConfigurationFactory operator=(const RunConfigurationFactory &) = delete;
|
RunConfigurationFactory operator=(const RunConfigurationFactory &) = delete;
|
||||||
|
|
||||||
@@ -319,6 +332,8 @@ private:
|
|||||||
QList<Core::Id> m_supportedProjectTypes;
|
QList<Core::Id> m_supportedProjectTypes;
|
||||||
QList<Core::Id> m_supportedTargetDeviceTypes;
|
QList<Core::Id> m_supportedTargetDeviceTypes;
|
||||||
bool m_decorateDisplayNames = false;
|
bool m_decorateDisplayNames = false;
|
||||||
|
QList<RunWorkerFactory *> m_ownedRunWorkerFactories;
|
||||||
|
std::function<bool(RunConfiguration *)> m_ownTypeChecker;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PROJECTEXPLORER_EXPORT FixedRunConfigurationFactory : public RunConfigurationFactory
|
class PROJECTEXPLORER_EXPORT FixedRunConfigurationFactory : public RunConfigurationFactory
|
||||||
@@ -421,14 +436,6 @@ public:
|
|||||||
m_producer = [](RunControl *rc) { return new Worker(rc); };
|
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;
|
bool canRun(RunConfiguration *runConfiguration, Core::Id runMode) const;
|
||||||
|
|
||||||
void setPriority(int priority);
|
void setPriority(int priority);
|
||||||
@@ -536,15 +543,6 @@ public:
|
|||||||
factory->addConstraint(constraint);
|
factory->addConstraint(constraint);
|
||||||
factory->setPriority(priority);
|
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);
|
static WorkerCreator producer(RunConfiguration *runConfiguration, Core::Id runMode);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user