ProjectExplorer: Add executable() accessor to RunConfiguration

Amends f6c276daf0, which was a quick fix for 4.9.

Change-Id: I94281af6a9a0d0bfe197ce836488f708d5bd677d
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Christian Kandeler
2019-05-23 18:10:34 +02:00
parent b7755b18c3
commit a9d2e14dca
7 changed files with 36 additions and 18 deletions

View File

@@ -256,7 +256,7 @@ Runnable CustomExecutableRunConfiguration::runnable() const
aspect<WorkingDirectoryAspect>()->workingDirectory(macroExpander());
Runnable r;
r.executable = aspect<ExecutableAspect>()->executable().toString();
r.executable = executable().toString();
r.commandLineArguments = aspect<ArgumentsAspect>()->arguments(macroExpander());
r.environment = aspect<EnvironmentAspect>()->environment();
r.workingDirectory = workingDirectory.toString();

View File

@@ -1614,14 +1614,8 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
tr("The currently active run configuration's executable (if applicable)."),
[]() -> QString {
if (Target *target = activeTarget()) {
if (RunConfiguration *rc = target->activeRunConfiguration()) {
// TODO: This duplicates code and is not always correct, but see
// QTCREATORBUG-18317.
// Solution: Re-introduce RunConfiguration::executable()?
if (auto executableAspect = rc->aspect<ExecutableAspect>())
return executableAspect->executable().toString();
return QString();
}
if (RunConfiguration *rc = target->activeRunConfiguration())
return rc->executable().toString();
}
return QString();
});

View File

@@ -200,6 +200,12 @@ RunConfiguration::RunConfiguration(Target *target, Core::Id id)
for (const AspectFactory &factory : theAspectFactories)
m_aspects.append(factory(target));
m_executableGetter = [this] {
if (const auto executableAspect = aspect<ExecutableAspect>())
return executableAspect->executable();
return FileName();
};
}
RunConfiguration::~RunConfiguration() = default;
@@ -321,6 +327,16 @@ QVariantMap RunConfiguration::toMap() const
return map;
}
void RunConfiguration::setExecutableGetter(const RunConfiguration::ExecutableGetter &exeGetter)
{
m_executableGetter = exeGetter;
}
FileName RunConfiguration::executable() const
{
return m_executableGetter();
}
BuildTargetInfo RunConfiguration::buildTargetInfo() const
{
return target()->buildTarget(m_buildKey);
@@ -376,8 +392,7 @@ bool RunConfiguration::fromMap(const QVariantMap &map)
Runnable RunConfiguration::runnable() const
{
Runnable r;
if (auto executableAspect = aspect<ExecutableAspect>())
r.executable = executableAspect->executable().toString();
r.executable = executable().toString();
if (auto argumentsAspect = aspect<ArgumentsAspect>())
r.commandLineArguments = argumentsAspect->arguments(macroExpander());
if (auto workingDirectoryAspect = aspect<WorkingDirectoryAspect>())

View File

@@ -160,6 +160,10 @@ public:
bool fromMap(const QVariantMap &map) override;
QVariantMap toMap() const override;
using ExecutableGetter = std::function<Utils::FileName()>;
void setExecutableGetter(const ExecutableGetter &exeGetter);
Utils::FileName executable() const;
virtual Runnable runnable() const;
// Return a handle to the build system target that created this run configuration.
@@ -210,6 +214,7 @@ private:
QString m_buildKey;
bool m_isEnabled = false;
std::function<Utils::OutputFormatter *(Project *)> m_outputFormatterCreator;
ExecutableGetter m_executableGetter;
};
class RunConfigurationCreationInfo

View File

@@ -279,6 +279,9 @@ PythonRunConfiguration::PythonRunConfiguration(Target *target, Core::Id id)
addAspect<TerminalAspect>();
setOutputFormatter<PythonOutputFormatter>();
setExecutableGetter([this] {
return FileName::fromString(aspect<InterpreterAspect>()->value());
});
connect(target, &Target::applicationTargetsChanged,
this, &PythonRunConfiguration::updateTargetInformation);
@@ -300,7 +303,7 @@ Runnable PythonRunConfiguration::runnable() const
QtcProcess::addArg(&r.commandLineArguments, mainScript());
QtcProcess::addArgs(&r.commandLineArguments,
aspect<ArgumentsAspect>()->arguments(macroExpander()));
r.executable = aspect<InterpreterAspect>()->value();
r.executable = executable().toString();
r.environment = aspect<EnvironmentAspect>()->environment();
return r;
}

View File

@@ -298,9 +298,11 @@ QmlProjectRunConfiguration::QmlProjectRunConfiguration(Target *target, Id id)
return envModifier(Environment());
});
setExecutableGetter([this] { return FileName::fromString(theExecutable()); });
m_qmlViewerAspect = addAspect<BaseStringAspect>();
m_qmlViewerAspect->setLabelText(tr("QML Viewer:"));
m_qmlViewerAspect->setPlaceHolderText(executable());
m_qmlViewerAspect->setPlaceHolderText(executable().toString());
m_qmlViewerAspect->setDisplayStyle(BaseStringAspect::LineEditDisplay);
m_qmlViewerAspect->setHistoryCompleter("QmlProjectManager.viewer.history");
@@ -314,7 +316,6 @@ QmlProjectRunConfiguration::QmlProjectRunConfiguration(Target *target, Id id)
this, &QmlProjectRunConfiguration::updateEnabledState);
setOutputFormatter<QtSupport::QtOutputFormatter>();
connect(target, &Target::kitChanged,
this, &QmlProjectRunConfiguration::updateEnabledState);
@@ -325,7 +326,7 @@ QmlProjectRunConfiguration::QmlProjectRunConfiguration(Target *target, Id id)
Runnable QmlProjectRunConfiguration::runnable() const
{
Runnable r;
r.executable = executable();
r.executable = executable().toString();
r.commandLineArguments = commandLineArguments();
r.environment = aspect<EnvironmentAspect>()->environment();
r.workingDirectory = static_cast<QmlProject *>(project())->targetDirectory(target()).toString();
@@ -338,7 +339,7 @@ QString QmlProjectRunConfiguration::disabledReason() const
return tr("No script file to execute.");
if (DeviceTypeKitAspect::deviceTypeId(target()->kit())
== ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE
&& !QFileInfo::exists(executable())) {
&& !executable().exists()) {
return tr("No qmlscene found.");
}
if (executable().isEmpty())
@@ -346,7 +347,7 @@ QString QmlProjectRunConfiguration::disabledReason() const
return RunConfiguration::disabledReason();
}
QString QmlProjectRunConfiguration::executable() const
QString QmlProjectRunConfiguration::theExecutable() const
{
const QString qmlViewer = m_qmlViewerAspect->value();
if (!qmlViewer.isEmpty())

View File

@@ -47,7 +47,7 @@ private:
void updateEnabledState() final;
QString mainScript() const;
QString executable() const;
QString theExecutable() const;
QString commandLineArguments() const;
ProjectExplorer::BaseStringAspect *m_qmlViewerAspect;