2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2013-01-29 16:46:04 +01:00
|
|
|
|
|
|
|
|
#include "environmentaspectwidget.h"
|
|
|
|
|
|
|
|
|
|
#include "environmentwidget.h"
|
2023-01-13 12:38:22 +01:00
|
|
|
#include "projectexplorertr.h"
|
2013-01-29 16:46:04 +01:00
|
|
|
|
|
|
|
|
#include <utils/environment.h>
|
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2023-04-24 17:25:13 +02:00
|
|
|
#include <QCheckBox>
|
2013-01-29 16:46:04 +01:00
|
|
|
#include <QComboBox>
|
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
|
|
namespace ProjectExplorer {
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
// EnvironmentAspectWidget:
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
|
2022-05-27 11:39:18 +02:00
|
|
|
EnvironmentAspectWidget::EnvironmentAspectWidget(EnvironmentAspect *aspect)
|
|
|
|
|
: m_aspect(aspect)
|
2013-01-29 16:46:04 +01:00
|
|
|
{
|
|
|
|
|
QTC_CHECK(m_aspect);
|
|
|
|
|
|
|
|
|
|
setContentsMargins(0, 0, 0, 0);
|
2016-04-13 15:52:14 +02:00
|
|
|
auto topLayout = new QVBoxLayout(this);
|
2019-10-01 17:49:33 +02:00
|
|
|
topLayout->setContentsMargins(0, 0, 0, 25);
|
2013-01-29 16:46:04 +01:00
|
|
|
|
2016-04-13 15:52:14 +02:00
|
|
|
auto baseEnvironmentWidget = new QWidget;
|
2022-05-27 11:39:18 +02:00
|
|
|
m_baseLayout = new QHBoxLayout(baseEnvironmentWidget);
|
|
|
|
|
m_baseLayout->setContentsMargins(0, 0, 0, 0);
|
2023-01-02 20:03:41 +01:00
|
|
|
|
|
|
|
|
auto label = [aspect]() {
|
|
|
|
|
if (aspect->labelText().isEmpty())
|
|
|
|
|
aspect->setLabelText(Tr::tr("Base environment for this run configuration:"));
|
|
|
|
|
aspect->setupLabel();
|
|
|
|
|
return aspect->label();
|
|
|
|
|
};
|
|
|
|
|
m_baseLayout->addWidget(label());
|
2019-03-07 10:10:22 +01:00
|
|
|
|
2013-01-29 16:46:04 +01:00
|
|
|
m_baseEnvironmentComboBox = new QComboBox;
|
2019-03-07 10:10:22 +01:00
|
|
|
for (const QString &displayName : m_aspect->displayNames())
|
|
|
|
|
m_baseEnvironmentComboBox->addItem(displayName);
|
2013-01-29 16:46:04 +01:00
|
|
|
if (m_baseEnvironmentComboBox->count() == 1)
|
|
|
|
|
m_baseEnvironmentComboBox->setEnabled(false);
|
2019-03-07 10:10:22 +01:00
|
|
|
m_baseEnvironmentComboBox->setCurrentIndex(m_aspect->baseEnvironmentBase());
|
2013-01-29 16:46:04 +01:00
|
|
|
|
2022-07-19 22:42:48 +02:00
|
|
|
connect(m_baseEnvironmentComboBox, &QComboBox::currentIndexChanged,
|
2016-01-29 16:38:37 +02:00
|
|
|
this, &EnvironmentAspectWidget::baseEnvironmentSelected);
|
2013-01-29 16:46:04 +01:00
|
|
|
|
2022-05-27 11:39:18 +02:00
|
|
|
m_baseLayout->addWidget(m_baseEnvironmentComboBox);
|
|
|
|
|
m_baseLayout->addStretch(10);
|
2013-01-29 16:46:04 +01:00
|
|
|
|
2019-03-12 17:56:24 +01:00
|
|
|
const EnvironmentWidget::Type widgetType = aspect->isLocal()
|
|
|
|
|
? EnvironmentWidget::TypeLocal : EnvironmentWidget::TypeRemote;
|
|
|
|
|
m_environmentWidget = new EnvironmentWidget(this, widgetType, baseEnvironmentWidget);
|
2019-11-05 11:30:22 +01:00
|
|
|
m_environmentWidget->setBaseEnvironment(m_aspect->modifiedBaseEnvironment());
|
2019-03-07 10:10:22 +01:00
|
|
|
m_environmentWidget->setBaseEnvironmentText(m_aspect->currentDisplayName());
|
2013-01-29 16:46:04 +01:00
|
|
|
m_environmentWidget->setUserChanges(m_aspect->userEnvironmentChanges());
|
|
|
|
|
m_environmentWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
|
|
|
|
topLayout->addWidget(m_environmentWidget);
|
|
|
|
|
|
2023-04-24 17:25:13 +02:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-29 16:38:37 +02:00
|
|
|
connect(m_environmentWidget, &EnvironmentWidget::userChangesChanged,
|
|
|
|
|
this, &EnvironmentAspectWidget::userChangesEdited);
|
2013-01-29 16:46:04 +01:00
|
|
|
|
2016-01-29 16:38:37 +02:00
|
|
|
connect(m_aspect, &EnvironmentAspect::baseEnvironmentChanged,
|
|
|
|
|
this, &EnvironmentAspectWidget::changeBaseEnvironment);
|
|
|
|
|
connect(m_aspect, &EnvironmentAspect::userEnvironmentChangesChanged,
|
|
|
|
|
this, &EnvironmentAspectWidget::changeUserChanges);
|
|
|
|
|
connect(m_aspect, &EnvironmentAspect::environmentChanged,
|
|
|
|
|
this, &EnvironmentAspectWidget::environmentChanged);
|
2013-01-29 16:46:04 +01:00
|
|
|
}
|
|
|
|
|
|
2022-05-27 11:39:18 +02:00
|
|
|
void EnvironmentAspectWidget::addWidget(QWidget *widget)
|
2013-01-29 16:46:04 +01:00
|
|
|
{
|
2022-05-27 11:39:18 +02:00
|
|
|
m_baseLayout->addWidget(widget);
|
2013-01-29 16:46:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EnvironmentAspectWidget::baseEnvironmentSelected(int idx)
|
|
|
|
|
{
|
2022-07-21 08:52:49 +02:00
|
|
|
const Utils::GuardLocker locker(m_ignoreChanges);
|
2019-03-07 10:10:22 +01:00
|
|
|
m_aspect->setBaseEnvironmentBase(idx);
|
2019-11-05 11:30:22 +01:00
|
|
|
m_environmentWidget->setBaseEnvironment(m_aspect->modifiedBaseEnvironment());
|
2019-03-07 10:10:22 +01:00
|
|
|
m_environmentWidget->setBaseEnvironmentText(m_aspect->currentDisplayName());
|
2013-01-29 16:46:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EnvironmentAspectWidget::changeBaseEnvironment()
|
|
|
|
|
{
|
2022-07-21 08:52:49 +02:00
|
|
|
if (m_ignoreChanges.isLocked())
|
2013-01-29 16:46:04 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
int base = m_aspect->baseEnvironmentBase();
|
|
|
|
|
for (int i = 0; i < m_baseEnvironmentComboBox->count(); ++i) {
|
|
|
|
|
if (m_baseEnvironmentComboBox->itemData(i).toInt() == base)
|
|
|
|
|
m_baseEnvironmentComboBox->setCurrentIndex(i);
|
|
|
|
|
}
|
2019-03-07 10:10:22 +01:00
|
|
|
m_environmentWidget->setBaseEnvironmentText(m_aspect->currentDisplayName());
|
2019-11-05 11:30:22 +01:00
|
|
|
m_environmentWidget->setBaseEnvironment(m_aspect->modifiedBaseEnvironment());
|
2013-01-29 16:46:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EnvironmentAspectWidget::userChangesEdited()
|
|
|
|
|
{
|
2022-07-21 08:52:49 +02:00
|
|
|
const Utils::GuardLocker locker(m_ignoreChanges);
|
2013-01-29 16:46:04 +01:00
|
|
|
m_aspect->setUserEnvironmentChanges(m_environmentWidget->userChanges());
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-07 16:51:22 +02:00
|
|
|
void EnvironmentAspectWidget::changeUserChanges(Utils::EnvironmentItems changes)
|
2013-01-29 16:46:04 +01:00
|
|
|
{
|
2022-07-21 08:52:49 +02:00
|
|
|
if (m_ignoreChanges.isLocked())
|
2013-01-29 16:46:04 +01:00
|
|
|
return;
|
|
|
|
|
m_environmentWidget->setUserChanges(changes);
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-04 18:23:28 +02:00
|
|
|
void EnvironmentAspectWidget::environmentChanged()
|
|
|
|
|
{
|
2022-07-21 08:52:49 +02:00
|
|
|
if (m_ignoreChanges.isLocked())
|
2013-07-04 18:23:28 +02:00
|
|
|
return;
|
2019-11-05 11:30:22 +01:00
|
|
|
m_environmentWidget->setBaseEnvironment(m_aspect->modifiedBaseEnvironment());
|
2013-07-04 18:23:28 +02:00
|
|
|
}
|
|
|
|
|
|
2013-01-29 16:46:04 +01:00
|
|
|
} // namespace ProjectExplorer
|