forked from qt-creator/qt-creator
ProjectExplorer: Optionally show run environment in app output pane
Fixes: QTCREATORBUG-28427 Change-Id: I1022a377d3728ad5e91fa62514082110b86db9f4 Reviewed-by: hjk <hjk@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -2284,6 +2284,7 @@ public:
|
||||
ConfigureEnvironmentAspect::ConfigureEnvironmentAspect(ProjectExplorer::Target *target)
|
||||
{
|
||||
setIsLocal(true);
|
||||
setAllowPrintOnRun(false);
|
||||
setConfigWidgetCreator(
|
||||
[this, target] { return new ConfigureEnvironmentAspectWidget(this, target); });
|
||||
addSupportedBaseEnvironment(Tr::tr("Clean Environment"), {});
|
||||
|
@@ -12,6 +12,7 @@
|
||||
using namespace Utils;
|
||||
|
||||
namespace ProjectExplorer {
|
||||
const char PRINT_ON_RUN_KEY[] = "PE.EnvironmentAspect.PrintOnRun";
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// EnvironmentAspect:
|
||||
@@ -105,12 +106,14 @@ void EnvironmentAspect::fromMap(const QVariantMap &map)
|
||||
{
|
||||
m_base = map.value(QLatin1String(BASE_KEY), -1).toInt();
|
||||
m_userChanges = Utils::EnvironmentItem::fromStringList(map.value(QLatin1String(CHANGES_KEY)).toStringList());
|
||||
m_printOnRun = map.value(PRINT_ON_RUN_KEY).toBool();
|
||||
}
|
||||
|
||||
void EnvironmentAspect::toMap(QVariantMap &data) const
|
||||
{
|
||||
data.insert(QLatin1String(BASE_KEY), m_base);
|
||||
data.insert(QLatin1String(CHANGES_KEY), Utils::EnvironmentItem::toStringList(m_userChanges));
|
||||
data.insert(PRINT_ON_RUN_KEY, m_printOnRun);
|
||||
}
|
||||
|
||||
QString EnvironmentAspect::currentDisplayName() const
|
||||
|
@@ -48,6 +48,10 @@ public:
|
||||
|
||||
bool isLocal() const { return m_isLocal; }
|
||||
|
||||
bool isPrintOnRunAllowed() const { return m_allowPrintOnRun; }
|
||||
bool isPrintOnRunEnabled() const { return m_printOnRun; }
|
||||
void setPrintOnRun(bool enabled) { m_printOnRun = enabled; }
|
||||
|
||||
struct Data : BaseAspect::Data
|
||||
{
|
||||
Utils::Environment environment;
|
||||
@@ -66,6 +70,7 @@ protected:
|
||||
void toMap(QVariantMap &map) const override;
|
||||
|
||||
void setIsLocal(bool local) { m_isLocal = local; }
|
||||
void setAllowPrintOnRun(bool allow) { m_allowPrintOnRun = allow; }
|
||||
|
||||
static constexpr char BASE_KEY[] = "PE.EnvironmentAspect.Base";
|
||||
static constexpr char CHANGES_KEY[] = "PE.EnvironmentAspect.Changes";
|
||||
@@ -84,6 +89,8 @@ private:
|
||||
QList<BaseEnvironment> m_baseEnvironments;
|
||||
int m_base = -1;
|
||||
bool m_isLocal = false;
|
||||
bool m_allowPrintOnRun = true;
|
||||
bool m_printOnRun = false;
|
||||
};
|
||||
|
||||
} // namespace ProjectExplorer
|
||||
|
@@ -9,6 +9,7 @@
|
||||
#include <utils/environment.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
@@ -63,6 +64,14 @@ EnvironmentAspectWidget::EnvironmentAspectWidget(EnvironmentAspect *aspect)
|
||||
m_environmentWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
topLayout->addWidget(m_environmentWidget);
|
||||
|
||||
if (m_aspect->isPrintOnRunAllowed()) {
|
||||
const auto printOnRunCheckBox = new QCheckBox(Tr::tr("Show in output pane when running"));
|
||||
printOnRunCheckBox->setChecked(m_aspect->isPrintOnRunEnabled());
|
||||
connect(printOnRunCheckBox, &QCheckBox::toggled,
|
||||
m_aspect, &EnvironmentAspect::setPrintOnRun);
|
||||
topLayout->addWidget(printOnRunCheckBox);
|
||||
}
|
||||
|
||||
connect(m_environmentWidget, &EnvironmentWidget::userChangesChanged,
|
||||
this, &EnvironmentAspectWidget::userChangesEdited);
|
||||
|
||||
|
@@ -298,6 +298,13 @@ CommandLine RunConfiguration::commandLine() const
|
||||
return m_commandLineGetter();
|
||||
}
|
||||
|
||||
bool RunConfiguration::isPrintEnvironmentEnabled() const
|
||||
{
|
||||
if (const auto envAspect = aspect<EnvironmentAspect>())
|
||||
return envAspect->isPrintOnRunEnabled();
|
||||
return false;
|
||||
}
|
||||
|
||||
void RunConfiguration::setRunnableModifier(const RunnableModifier &runnableModifier)
|
||||
{
|
||||
m_runnableModifier = runnableModifier;
|
||||
|
@@ -116,6 +116,7 @@ public:
|
||||
using CommandLineGetter = std::function<Utils::CommandLine()>;
|
||||
void setCommandLineGetter(const CommandLineGetter &cmdGetter);
|
||||
Utils::CommandLine commandLine() const;
|
||||
bool isPrintEnvironmentEnabled() const;
|
||||
|
||||
using RunnableModifier = std::function<void(Runnable &)>;
|
||||
void setRunnableModifier(const RunnableModifier &extraModifier);
|
||||
|
@@ -255,9 +255,9 @@ public:
|
||||
// A handle to the actual application process.
|
||||
ProcessHandle applicationProcessHandle;
|
||||
|
||||
RunControlState state = RunControlState::Initialized;
|
||||
|
||||
QList<QPointer<RunWorker>> m_workers;
|
||||
RunControlState state = RunControlState::Initialized;
|
||||
bool printEnvironment = false;
|
||||
};
|
||||
|
||||
class RunControlPrivate : public QObject, public RunControlPrivateData
|
||||
@@ -334,6 +334,7 @@ void RunControl::copyDataFromRunConfiguration(RunConfiguration *runConfig)
|
||||
d->buildKey = runConfig->buildKey();
|
||||
d->settingsData = runConfig->settingsData();
|
||||
d->aspectData = runConfig->aspectData();
|
||||
d->printEnvironment = runConfig->isPrintEnvironmentEnabled();
|
||||
|
||||
setTarget(runConfig->target());
|
||||
|
||||
@@ -817,6 +818,11 @@ Utils::Id RunControl::runMode() const
|
||||
return d->runMode;
|
||||
}
|
||||
|
||||
bool RunControl::isPrintEnvironmentEnabled() const
|
||||
{
|
||||
return d->printEnvironment;
|
||||
}
|
||||
|
||||
const Runnable &RunControl::runnable() const
|
||||
{
|
||||
return d->runnable;
|
||||
@@ -1436,6 +1442,15 @@ void SimpleTargetRunner::start()
|
||||
|
||||
const QString msg = Tr::tr("Starting %1...").arg(d->m_command.displayName());
|
||||
appendMessage(msg, NormalMessageFormat);
|
||||
if (runControl()->isPrintEnvironmentEnabled()) {
|
||||
appendMessage(Tr::tr("Environment:"), NormalMessageFormat);
|
||||
runControl()->runnable().environment
|
||||
.forEachEntry([this](const QString &key, const QString &value, bool enabled) {
|
||||
if (enabled)
|
||||
appendMessage(key + '=' + value, StdOutFormat);
|
||||
});
|
||||
appendMessage({}, StdOutFormat);
|
||||
}
|
||||
|
||||
const bool isDesktop = !d->m_command.executable().needsDevice();
|
||||
if (isDesktop && d->m_command.isEmpty()) {
|
||||
|
@@ -205,6 +205,7 @@ public:
|
||||
|
||||
void setupFormatter(Utils::OutputFormatter *formatter) const;
|
||||
Utils::Id runMode() const;
|
||||
bool isPrintEnvironmentEnabled() const;
|
||||
|
||||
const Runnable &runnable() const;
|
||||
|
||||
|
Reference in New Issue
Block a user