forked from qt-creator/qt-creator
ProjectExplorer: Simplify retrieval of WorkingDirectoryAspect values
Drop the macroExpander argument, at the cost of complicating internal ProjectConfiguration setup a bit. Simpler code at the user side. Change-Id: Ie9ea0b719f6e402b44d9ba7ce6047aa4e15441fe Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -98,8 +98,7 @@ bool CustomExecutableRunConfiguration::isEnabled() const
|
||||
|
||||
Runnable CustomExecutableRunConfiguration::runnable() const
|
||||
{
|
||||
FilePath workingDirectory =
|
||||
aspect<WorkingDirectoryAspect>()->workingDirectory(macroExpander());
|
||||
const FilePath workingDirectory = aspect<WorkingDirectoryAspect>()->workingDirectory();
|
||||
|
||||
Runnable r;
|
||||
r.command = commandLine();
|
||||
|
@@ -145,6 +145,12 @@ void ProjectConfiguration::acquaintAspects()
|
||||
aspect->acquaintSiblings(m_aspects);
|
||||
}
|
||||
|
||||
void ProjectConfiguration::doPostInit()
|
||||
{
|
||||
for (const std::function<void()> &postInit : qAsConst(m_postInit))
|
||||
postInit();
|
||||
}
|
||||
|
||||
FilePath ProjectConfiguration::mapFromBuildDeviceToGlobalPath(const FilePath &path) const
|
||||
{
|
||||
IDevice::ConstPtr dev = BuildDeviceKitAspect::device(kit());
|
||||
|
@@ -91,6 +91,9 @@ public:
|
||||
|
||||
Utils::FilePath mapFromBuildDeviceToGlobalPath(const Utils::FilePath &path) const;
|
||||
|
||||
void addPostInit(const std::function<void()> &fixup) { m_postInit.append(fixup); }
|
||||
void doPostInit();
|
||||
|
||||
signals:
|
||||
void displayNameChanged();
|
||||
void toolTipChanged();
|
||||
@@ -103,6 +106,7 @@ private:
|
||||
const Utils::Id m_id;
|
||||
Utils::DisplayName m_displayName;
|
||||
QString m_toolTip;
|
||||
QList<std::function<void()>> m_postInit;
|
||||
};
|
||||
|
||||
// helper function:
|
||||
|
@@ -1966,7 +1966,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
|
||||
[] {
|
||||
if (const RunConfiguration * const rc = activeRunConfiguration()) {
|
||||
if (const auto wdAspect = rc->aspect<WorkingDirectoryAspect>())
|
||||
return wdAspect->workingDirectory(rc->macroExpander()).toString();
|
||||
return wdAspect->workingDirectory().toString();
|
||||
}
|
||||
return QString();
|
||||
});
|
||||
|
@@ -197,7 +197,7 @@ RunConfiguration::RunConfiguration(Target *target, Utils::Id id)
|
||||
tr("The run configuration's working directory"),
|
||||
[this] {
|
||||
const auto wdAspect = aspect<WorkingDirectoryAspect>();
|
||||
return wdAspect ? wdAspect->workingDirectory(&m_expander).toString() : QString();
|
||||
return wdAspect ? wdAspect->workingDirectory().toString() : QString();
|
||||
});
|
||||
m_expander.registerVariable("RunConfig:Name", tr("The run configuration's name."),
|
||||
[this] { return displayName(); });
|
||||
@@ -215,6 +215,11 @@ RunConfiguration::RunConfiguration(Target *target, Utils::Id id)
|
||||
arguments = argumentsAspect->arguments(macroExpander());
|
||||
return CommandLine{executable, arguments, CommandLine::Raw};
|
||||
};
|
||||
|
||||
addPostInit([this] {
|
||||
if (const auto wdAspect = aspect<WorkingDirectoryAspect>())
|
||||
wdAspect->setMacroExpander(&m_expander);
|
||||
});
|
||||
}
|
||||
|
||||
RunConfiguration::~RunConfiguration() = default;
|
||||
@@ -233,8 +238,6 @@ bool RunConfiguration::isEnabled() const
|
||||
|
||||
QWidget *RunConfiguration::createConfigurationWidget()
|
||||
{
|
||||
if (const auto wdAspect = aspect<WorkingDirectoryAspect>())
|
||||
wdAspect->setMacroExpanderProvider([this] { return &m_expander; });
|
||||
Layouting::Form builder;
|
||||
for (BaseAspect *aspect : qAsConst(m_aspects)) {
|
||||
if (aspect->isVisible())
|
||||
@@ -402,7 +405,7 @@ Runnable RunConfiguration::runnable() const
|
||||
Runnable r;
|
||||
r.command = commandLine();
|
||||
if (auto workingDirectoryAspect = aspect<WorkingDirectoryAspect>())
|
||||
r.workingDirectory = workingDirectoryAspect->workingDirectory(macroExpander());
|
||||
r.workingDirectory = workingDirectoryAspect->workingDirectory();
|
||||
if (auto environmentAspect = aspect<EnvironmentAspect>())
|
||||
r.environment = environmentAspect->environment();
|
||||
if (m_runnableModifier)
|
||||
@@ -571,6 +574,7 @@ RunConfiguration *RunConfigurationFactory::create(Target *target) const
|
||||
rc->m_aspects.registerAspect(factory(target));
|
||||
|
||||
rc->acquaintAspects();
|
||||
rc->doPostInit();
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
@@ -176,8 +176,8 @@ void WorkingDirectoryAspect::addToLayout(LayoutBuilder &builder)
|
||||
{
|
||||
QTC_CHECK(!m_chooser);
|
||||
m_chooser = new PathChooser;
|
||||
if (m_expanderProvider)
|
||||
m_chooser->setMacroExpander(m_expanderProvider());
|
||||
if (QTC_GUARD(m_macroExpander))
|
||||
m_chooser->setMacroExpander(m_macroExpander);
|
||||
m_chooser->setHistoryCompleter(settingsKey());
|
||||
m_chooser->setExpectedKind(Utils::PathChooser::Directory);
|
||||
m_chooser->setPromptDialogTitle(tr("Select Working Directory"));
|
||||
@@ -246,14 +246,12 @@ void WorkingDirectoryAspect::toMap(QVariantMap &data) const
|
||||
|
||||
Macros in the value are expanded using \a expander.
|
||||
*/
|
||||
FilePath WorkingDirectoryAspect::workingDirectory(const MacroExpander *expander) const
|
||||
FilePath WorkingDirectoryAspect::workingDirectory() const
|
||||
{
|
||||
const Environment env = m_envAspect ? m_envAspect->environment()
|
||||
: Environment::systemEnvironment();
|
||||
FilePath res = m_workingDirectory;
|
||||
QString workingDir = m_workingDirectory.path();
|
||||
if (expander)
|
||||
workingDir = expander->expandProcessArgs(workingDir);
|
||||
const QString workingDir = m_workingDirectory.path();
|
||||
res.setPath(PathChooser::expandedDirectory(workingDir, env, QString()));
|
||||
return res;
|
||||
}
|
||||
@@ -293,9 +291,9 @@ void WorkingDirectoryAspect::setDefaultWorkingDirectory(const FilePath &defaultW
|
||||
}
|
||||
}
|
||||
|
||||
void WorkingDirectoryAspect::setMacroExpanderProvider(const MacroExpanderProvider &expanderProvider)
|
||||
void WorkingDirectoryAspect::setMacroExpander(MacroExpander *macroExpander)
|
||||
{
|
||||
m_expanderProvider = expanderProvider;
|
||||
m_macroExpander = macroExpander;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@@ -78,11 +78,11 @@ public:
|
||||
void addToLayout(Utils::LayoutBuilder &builder) override;
|
||||
void acquaintSiblings(const Utils::AspectContainer &) override;
|
||||
|
||||
Utils::FilePath workingDirectory(const Utils::MacroExpander *expander) const;
|
||||
Utils::FilePath workingDirectory() const;
|
||||
Utils::FilePath defaultWorkingDirectory() const;
|
||||
Utils::FilePath unexpandedWorkingDirectory() const;
|
||||
void setDefaultWorkingDirectory(const Utils::FilePath &defaultWorkingDirectory);
|
||||
void setMacroExpanderProvider(const Utils::MacroExpanderProvider &expanderProvider);
|
||||
void setMacroExpander(Utils::MacroExpander *macroExpander);
|
||||
Utils::PathChooser *pathChooser() const;
|
||||
|
||||
private:
|
||||
@@ -96,7 +96,7 @@ private:
|
||||
Utils::FilePath m_defaultWorkingDirectory;
|
||||
QPointer<Utils::PathChooser> m_chooser;
|
||||
QPointer<QToolButton> m_resetButton;
|
||||
Utils::MacroExpanderProvider m_expanderProvider;
|
||||
Utils::MacroExpander *m_macroExpander = nullptr;
|
||||
};
|
||||
|
||||
class PROJECTEXPLORER_EXPORT ArgumentsAspect : public Utils::BaseAspect
|
||||
|
@@ -203,7 +203,7 @@ Target::Target(Project *project, Kit *k, _constructor_tag) :
|
||||
[this] {
|
||||
if (RunConfiguration * const rc = activeRunConfiguration()) {
|
||||
if (const auto wdAspect = rc->aspect<WorkingDirectoryAspect>())
|
||||
return wdAspect->workingDirectory(&d->m_macroExpander).toString();
|
||||
return wdAspect->workingDirectory().toString();
|
||||
}
|
||||
return QString();
|
||||
}, false);
|
||||
|
Reference in New Issue
Block a user