forked from qt-creator/qt-creator
ProjectExplorer: Make WorkingDirectoryAspect less dependent on runconfig
This was one of the genuine users of the run config pointer in the aspect base class. Instead of using that stored pointer to retrieve the relevant environment aspect pointer later, pass and store this env aspect pointer at construction time. Change-Id: Icbdeb9ad0fe341e4003fb544c542064801aa170f Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
@@ -49,7 +49,7 @@ BareMetalCustomRunConfiguration::BareMetalCustomRunConfiguration(Target *target,
|
|||||||
exeAspect->setExpectedKind(PathChooser::Any);
|
exeAspect->setExpectedKind(PathChooser::Any);
|
||||||
|
|
||||||
addAspect<ArgumentsAspect>();
|
addAspect<ArgumentsAspect>();
|
||||||
addAspect<WorkingDirectoryAspect>();
|
addAspect<WorkingDirectoryAspect>(nullptr);
|
||||||
|
|
||||||
setDefaultDisplayName(RunConfigurationFactory::decoratedTargetName(tr("Custom Executable"), target));
|
setDefaultDisplayName(RunConfigurationFactory::decoratedTargetName(tr("Custom Executable"), target));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,10 +53,11 @@ CMakeRunConfiguration::CMakeRunConfiguration(Target *target, Core::Id id)
|
|||||||
if (qt)
|
if (qt)
|
||||||
env.prependOrSetPath(qt->qmakeProperty("QT_INSTALL_BINS"));
|
env.prependOrSetPath(qt->qmakeProperty("QT_INSTALL_BINS"));
|
||||||
};
|
};
|
||||||
addAspect<LocalEnvironmentAspect>(cmakeRunEnvironmentModifier);
|
auto envAspect = addAspect<LocalEnvironmentAspect>(cmakeRunEnvironmentModifier);
|
||||||
|
|
||||||
addAspect<ExecutableAspect>();
|
addAspect<ExecutableAspect>();
|
||||||
addAspect<ArgumentsAspect>();
|
addAspect<ArgumentsAspect>();
|
||||||
addAspect<WorkingDirectoryAspect>();
|
addAspect<WorkingDirectoryAspect>(envAspect);
|
||||||
addAspect<TerminalAspect>();
|
addAspect<TerminalAspect>();
|
||||||
|
|
||||||
connect(target->project(), &Project::parsingFinished,
|
connect(target->project(), &Project::parsingFinished,
|
||||||
|
|||||||
@@ -44,10 +44,11 @@ namespace Nim {
|
|||||||
NimRunConfiguration::NimRunConfiguration(Target *target, Core::Id id)
|
NimRunConfiguration::NimRunConfiguration(Target *target, Core::Id id)
|
||||||
: RunConfiguration(target, id)
|
: RunConfiguration(target, id)
|
||||||
{
|
{
|
||||||
|
auto envAspect = addAspect<LocalEnvironmentAspect>(LocalEnvironmentAspect::BaseEnvironmentModifier());
|
||||||
|
|
||||||
addAspect<ExecutableAspect>();
|
addAspect<ExecutableAspect>();
|
||||||
addAspect<ArgumentsAspect>();
|
addAspect<ArgumentsAspect>();
|
||||||
addAspect<WorkingDirectoryAspect>();
|
addAspect<WorkingDirectoryAspect>(envAspect);
|
||||||
addAspect<LocalEnvironmentAspect>(LocalEnvironmentAspect::BaseEnvironmentModifier());
|
|
||||||
addAspect<TerminalAspect>();
|
addAspect<TerminalAspect>();
|
||||||
|
|
||||||
setDisplayName(tr("Current Build Target"));
|
setDisplayName(tr("Current Build Target"));
|
||||||
|
|||||||
@@ -86,7 +86,10 @@ private:
|
|||||||
|
|
||||||
CustomExecutableDialog::CustomExecutableDialog(RunConfiguration *rc)
|
CustomExecutableDialog::CustomExecutableDialog(RunConfiguration *rc)
|
||||||
: QDialog(Core::ICore::dialogParent()),
|
: QDialog(Core::ICore::dialogParent()),
|
||||||
m_rc(rc), m_arguments(rc), m_workingDirectory(rc), m_terminal(rc)
|
m_rc(rc),
|
||||||
|
m_arguments(rc),
|
||||||
|
m_workingDirectory(rc, rc->extraAspect<EnvironmentAspect>()),
|
||||||
|
m_terminal(rc)
|
||||||
{
|
{
|
||||||
auto vbox = new QVBoxLayout(this);
|
auto vbox = new QVBoxLayout(this);
|
||||||
vbox->addWidget(new QLabel(tr("Could not find the executable, please specify one.")));
|
vbox->addWidget(new QLabel(tr("Could not find the executable, please specify one.")));
|
||||||
@@ -185,7 +188,7 @@ CustomExecutableRunConfiguration::CustomExecutableRunConfiguration(Target *targe
|
|||||||
exeAspect->setEnvironment(envAspect->environment());
|
exeAspect->setEnvironment(envAspect->environment());
|
||||||
|
|
||||||
addAspect<ArgumentsAspect>();
|
addAspect<ArgumentsAspect>();
|
||||||
addAspect<WorkingDirectoryAspect>();
|
addAspect<WorkingDirectoryAspect>(envAspect);
|
||||||
addAspect<TerminalAspect>();
|
addAspect<TerminalAspect>();
|
||||||
|
|
||||||
connect(envAspect, &EnvironmentAspect::environmentChanged,
|
connect(envAspect, &EnvironmentAspect::environmentChanged,
|
||||||
|
|||||||
@@ -115,8 +115,10 @@ bool TerminalAspect::isUserSet() const
|
|||||||
\class ProjectExplorer::WorkingDirectoryAspect
|
\class ProjectExplorer::WorkingDirectoryAspect
|
||||||
*/
|
*/
|
||||||
|
|
||||||
WorkingDirectoryAspect::WorkingDirectoryAspect(RunConfiguration *runConfig)
|
WorkingDirectoryAspect::WorkingDirectoryAspect(RunConfiguration *runConfig,
|
||||||
: IRunConfigurationAspect(runConfig)
|
EnvironmentAspect *envAspect)
|
||||||
|
: IRunConfigurationAspect(runConfig),
|
||||||
|
m_envAspect(envAspect)
|
||||||
{
|
{
|
||||||
setDisplayName(tr("Working Directory"));
|
setDisplayName(tr("Working Directory"));
|
||||||
setId("WorkingDirectoryAspect");
|
setId("WorkingDirectoryAspect");
|
||||||
@@ -145,11 +147,11 @@ void WorkingDirectoryAspect::addToConfigurationLayout(QFormLayout *layout)
|
|||||||
|
|
||||||
m_resetButton->setEnabled(m_workingDirectory != m_defaultWorkingDirectory);
|
m_resetButton->setEnabled(m_workingDirectory != m_defaultWorkingDirectory);
|
||||||
|
|
||||||
if (auto envAspect = runConfiguration()->extraAspect<EnvironmentAspect>()) {
|
if (m_envAspect) {
|
||||||
connect(envAspect, &EnvironmentAspect::environmentChanged, m_chooser.data(), [this, envAspect] {
|
connect(m_envAspect, &EnvironmentAspect::environmentChanged, m_chooser.data(), [this] {
|
||||||
m_chooser->setEnvironment(envAspect->environment());
|
m_chooser->setEnvironment(m_envAspect->environment());
|
||||||
});
|
});
|
||||||
m_chooser->setEnvironment(envAspect->environment());
|
m_chooser->setEnvironment(m_envAspect->environment());
|
||||||
}
|
}
|
||||||
|
|
||||||
auto hbox = new QHBoxLayout;
|
auto hbox = new QHBoxLayout;
|
||||||
@@ -190,9 +192,8 @@ void WorkingDirectoryAspect::toMap(QVariantMap &data) const
|
|||||||
|
|
||||||
FileName WorkingDirectoryAspect::workingDirectory() const
|
FileName WorkingDirectoryAspect::workingDirectory() const
|
||||||
{
|
{
|
||||||
auto envAspect = runConfiguration()->extraAspect<EnvironmentAspect>();
|
const Utils::Environment env = m_envAspect ? m_envAspect->environment()
|
||||||
const Utils::Environment env = envAspect ? envAspect->environment()
|
: Utils::Environment::systemEnvironment();
|
||||||
: Utils::Environment::systemEnvironment();
|
|
||||||
const QString macroExpanded
|
const QString macroExpanded
|
||||||
= runConfiguration()->macroExpander()->expandProcessArgs(m_workingDirectory.toUserOutput());
|
= runConfiguration()->macroExpander()->expandProcessArgs(m_workingDirectory.toUserOutput());
|
||||||
return FileName::fromString(PathChooser::expandedDirectory(macroExpanded, env, QString()));
|
return FileName::fromString(PathChooser::expandedDirectory(macroExpanded, env, QString()));
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
#include "runconfiguration.h"
|
#include "runconfiguration.h"
|
||||||
#include "applicationlauncher.h"
|
#include "applicationlauncher.h"
|
||||||
|
#include "environmentaspect.h"
|
||||||
|
|
||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
#include <utils/pathchooser.h>
|
#include <utils/pathchooser.h>
|
||||||
@@ -70,7 +71,8 @@ class PROJECTEXPLORER_EXPORT WorkingDirectoryAspect : public IRunConfigurationAs
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit WorkingDirectoryAspect(RunConfiguration *runConfig);
|
WorkingDirectoryAspect(RunConfiguration *runConfig,
|
||||||
|
EnvironmentAspect *envAspect = nullptr);
|
||||||
|
|
||||||
void addToConfigurationLayout(QFormLayout *layout) override;
|
void addToConfigurationLayout(QFormLayout *layout) override;
|
||||||
|
|
||||||
@@ -87,6 +89,7 @@ private:
|
|||||||
void resetPath();
|
void resetPath();
|
||||||
QString keyForDefaultWd() const;
|
QString keyForDefaultWd() const;
|
||||||
|
|
||||||
|
EnvironmentAspect * const m_envAspect = nullptr;
|
||||||
Utils::FileName m_workingDirectory;
|
Utils::FileName m_workingDirectory;
|
||||||
Utils::FileName m_defaultWorkingDirectory;
|
Utils::FileName m_defaultWorkingDirectory;
|
||||||
QPointer<Utils::PathChooser> m_chooser;
|
QPointer<Utils::PathChooser> m_chooser;
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ QbsRunConfiguration::QbsRunConfiguration(Target *target, Core::Id id)
|
|||||||
|
|
||||||
addAspect<ExecutableAspect>();
|
addAspect<ExecutableAspect>();
|
||||||
addAspect<ArgumentsAspect>();
|
addAspect<ArgumentsAspect>();
|
||||||
addAspect<WorkingDirectoryAspect>();
|
addAspect<WorkingDirectoryAspect>(envAspect);
|
||||||
addAspect<TerminalAspect>();
|
addAspect<TerminalAspect>();
|
||||||
|
|
||||||
setOutputFormatter<QtSupport::QtOutputFormatter>();
|
setOutputFormatter<QtSupport::QtOutputFormatter>();
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ DesktopQmakeRunConfiguration::DesktopQmakeRunConfiguration(Target *target, Core:
|
|||||||
|
|
||||||
addAspect<ExecutableAspect>();
|
addAspect<ExecutableAspect>();
|
||||||
addAspect<ArgumentsAspect>();
|
addAspect<ArgumentsAspect>();
|
||||||
addAspect<WorkingDirectoryAspect>();
|
addAspect<WorkingDirectoryAspect>(envAspect);
|
||||||
addAspect<TerminalAspect>();
|
addAspect<TerminalAspect>();
|
||||||
|
|
||||||
setOutputFormatter<QtSupport::QtOutputFormatter>();
|
setOutputFormatter<QtSupport::QtOutputFormatter>();
|
||||||
|
|||||||
Reference in New Issue
Block a user