1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
// Copyright (C) 2025 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "dockerdeviceenvironmentaspect.h"
#include "dockertr.h"
#include <coreplugin/icore.h>
#include <projectexplorer/devicesupport/devicekitaspects.h>
#include <projectexplorer/devicesupport/idevice.h>
#include <projectexplorer/environmentaspectwidget.h>
#include <projectexplorer/environmentwidget.h>
#include <projectexplorer/kitmanager.h>
#include <utils/algorithm.h>
#include <utils/devicefileaccess.h>
#include <utils/layoutbuilder.h>
#include <utils/qtcassert.h>
#include <QMessageBox>
#include <QPushButton>
#include <QStandardItem>
using namespace ProjectExplorer;
using namespace Utils;
namespace Docker {
const char DEVICE_ENVIRONMENT_KEY[] = "RemoteEnvironment";
const char CHANGES_KEY[] = "UserChanges";
DockerDeviceEnvironmentAspect::DockerDeviceEnvironmentAspect(Utils::AspectContainer *parent)
: Utils::TypedAspect<QStringList>(parent)
{}
void DockerDeviceEnvironmentAspect::addToLayoutImpl(Layouting::Layout &parent)
{
undoable.setSilently(value());
using namespace Layouting;
// clang-format off
auto fetchBtn = Row {
st,
PushButton {
text(Tr::tr("Fetch Environment")),
onClicked(this, [this]{ emit fetchRequested(); })
},
st
}.emerge();
// clang-format on
auto envWidget = new EnvironmentWidget(nullptr, EnvironmentWidget::Type::TypeRemote, fetchBtn);
envWidget->setOpenTerminalFunc(nullptr);
envWidget->setUserChanges(EnvironmentItem::fromStringList(undoable.get()));
connect(
this, &DockerDeviceEnvironmentAspect::remoteEnvironmentChanged, envWidget, [this, envWidget] {
if (m_remoteEnvironment)
envWidget->setBaseEnvironment(*m_remoteEnvironment);
else
envWidget->setBaseEnvironment(Environment());
});
connect(&undoable.m_signal, &UndoSignaller::changed, envWidget, [this, envWidget] {
if (EnvironmentItem::toStringList(envWidget->userChanges()) != undoable.get()) {
envWidget->setUserChanges(EnvironmentItem::fromStringList(undoable.get()));
handleGuiChanged();
}
});
connect(envWidget, &EnvironmentWidget::userChangesChanged, this, [this, envWidget] {
undoable.set(undoStack(), EnvironmentItem::toStringList(envWidget->userChanges()));
handleGuiChanged();
});
if (m_remoteEnvironment)
envWidget->setBaseEnvironment(*m_remoteEnvironment);
registerSubWidget(envWidget);
addLabeledItem(parent, envWidget);
}
Utils::Environment DockerDeviceEnvironmentAspect::operator()() const
{
Environment result = m_remoteEnvironment.value_or(Environment());
result.modify(EnvironmentItem::fromStringList(value()));
return result;
}
bool DockerDeviceEnvironmentAspect::guiToBuffer()
{
const QStringList newValue = undoable.get();
if (newValue != m_buffer) {
m_buffer = newValue;
return true;
}
return false;
}
void DockerDeviceEnvironmentAspect::bufferToGui()
{
undoable.setWithoutUndo(m_buffer);
}
void DockerDeviceEnvironmentAspect::fromMap(const Utils::Store &map)
{
if (skipSave())
return;
Store subMap = storeFromVariant(map.value(settingsKey()));
if (subMap.contains(DEVICE_ENVIRONMENT_KEY)) {
const QStringList deviceEnv = subMap.value(DEVICE_ENVIRONMENT_KEY).toStringList();
NameValueDictionary envDict;
for (const QString &env : deviceEnv) {
const auto parts = env.split(QLatin1Char('='));
if (parts.size() == 2)
envDict.set(parts[0], parts[1]);
}
m_remoteEnvironment = Environment(envDict);
}
if (subMap.contains(CHANGES_KEY)) {
const QStringList changes = subMap.value(CHANGES_KEY).toStringList();
setValue(changes, BeQuiet);
}
}
void DockerDeviceEnvironmentAspect::toMap(Utils::Store &map) const
{
Store subMap;
saveToMap(subMap, value(), defaultValue(), CHANGES_KEY);
if (m_remoteEnvironment.has_value()) {
subMap.insert(DEVICE_ENVIRONMENT_KEY, m_remoteEnvironment->toStringList());
}
saveToMap(map, mapFromStore(subMap), QVariant(), settingsKey());
}
void DockerDeviceEnvironmentAspect::setRemoteEnvironment(const Utils::Environment &env)
{
m_remoteEnvironment = env;
emit remoteEnvironmentChanged();
}
} // namespace Docker
|