forked from qt-creator/qt-creator
Utils: Retain more high level information on EnvironmentChange::Item
Change-Id: I78df3cf7ae767d6baeed46f03587ee21875c8315 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -433,44 +433,61 @@ optional<EnvironmentProvider> EnvironmentProvider::provider(const QByteArray &id
|
|||||||
|
|
||||||
void EnvironmentChange::addSetValue(const QString &key, const QString &value)
|
void EnvironmentChange::addSetValue(const QString &key, const QString &value)
|
||||||
{
|
{
|
||||||
m_changeItems.append([key, value](Environment &env) { env.set(key, value); });
|
m_changeItems.append({Item::SetValue, QVariant::fromValue(QPair<QString, QString>(key, value))});
|
||||||
}
|
}
|
||||||
|
|
||||||
void EnvironmentChange::addUnsetValue(const QString &key)
|
void EnvironmentChange::addUnsetValue(const QString &key)
|
||||||
{
|
{
|
||||||
m_changeItems.append([key](Environment &env) { env.unset(key); });
|
m_changeItems.append({Item::UnsetValue, key});
|
||||||
}
|
}
|
||||||
|
|
||||||
void EnvironmentChange::addPrependToPath(const FilePaths &values)
|
void EnvironmentChange::addPrependToPath(const FilePaths &values)
|
||||||
{
|
{
|
||||||
for (int i = values.size(); --i >= 0; ) {
|
for (int i = values.size(); --i >= 0; ) {
|
||||||
const FilePath value = values.at(i);
|
const FilePath value = values.at(i);
|
||||||
m_changeItems.append([value](Environment &env) { env.prependOrSetPath(value); });
|
m_changeItems.append({Item::PrependToPath, value.toVariant()});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EnvironmentChange::addAppendToPath(const FilePaths &values)
|
void EnvironmentChange::addAppendToPath(const FilePaths &values)
|
||||||
{
|
{
|
||||||
for (const FilePath &value : values)
|
for (const FilePath &value : values)
|
||||||
m_changeItems.append([value](Environment &env) { env.appendOrSetPath(value); });
|
m_changeItems.append({Item::AppendToPath, value.toVariant()});
|
||||||
}
|
|
||||||
|
|
||||||
void EnvironmentChange::addModify(const NameValueItems &items)
|
|
||||||
{
|
|
||||||
m_changeItems.append([items](Environment &env) { env.modify(items); });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EnvironmentChange EnvironmentChange::fromFixedEnvironment(const Environment &fixedEnv)
|
EnvironmentChange EnvironmentChange::fromFixedEnvironment(const Environment &fixedEnv)
|
||||||
{
|
{
|
||||||
EnvironmentChange change;
|
EnvironmentChange change;
|
||||||
change.m_changeItems.append([fixedEnv](Environment &env) { env = fixedEnv; });
|
change.m_changeItems.append({Item::SetFixedEnvironment, QVariant::fromValue(fixedEnv)});
|
||||||
return change;
|
return change;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EnvironmentChange::applyToEnvironment(Environment &env) const
|
void EnvironmentChange::applyToEnvironment(Environment &env) const
|
||||||
{
|
{
|
||||||
for (const Item &item : m_changeItems)
|
for (const Item &item : m_changeItems) {
|
||||||
item(env);
|
switch (item.type) {
|
||||||
|
case Item::SetSystemEnvironment:
|
||||||
|
env = Environment::systemEnvironment();
|
||||||
|
break;
|
||||||
|
case Item::SetFixedEnvironment:
|
||||||
|
env = item.data.value<Environment>();
|
||||||
|
break;
|
||||||
|
case Item::SetValue: {
|
||||||
|
auto data = item.data.value<QPair<QString, QString>>();
|
||||||
|
env.set(data.first, data.second);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Item::UnsetValue:
|
||||||
|
env.unset(item.data.toString());
|
||||||
|
break;
|
||||||
|
case Item::PrependToPath:
|
||||||
|
env.prependOrSetPath(FilePath::fromVariant(item.data));
|
||||||
|
break;
|
||||||
|
case Item::AppendToPath:
|
||||||
|
env.appendOrSetPath(FilePath::fromVariant(item.data));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Utils
|
} // namespace Utils
|
||||||
|
@@ -132,10 +132,24 @@ private:
|
|||||||
class QTCREATOR_UTILS_EXPORT EnvironmentChange final
|
class QTCREATOR_UTILS_EXPORT EnvironmentChange final
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using Item = std::function<void(Environment &)>;
|
|
||||||
|
|
||||||
EnvironmentChange() = default;
|
EnvironmentChange() = default;
|
||||||
|
|
||||||
|
class Item final
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum Type {
|
||||||
|
SetSystemEnvironment,
|
||||||
|
SetFixedEnvironment,
|
||||||
|
SetValue,
|
||||||
|
UnsetValue,
|
||||||
|
PrependToPath,
|
||||||
|
AppendToPath,
|
||||||
|
};
|
||||||
|
|
||||||
|
Type type;
|
||||||
|
QVariant data;
|
||||||
|
};
|
||||||
|
|
||||||
static EnvironmentChange fromFixedEnvironment(const Environment &fixedEnv);
|
static EnvironmentChange fromFixedEnvironment(const Environment &fixedEnv);
|
||||||
|
|
||||||
void applyToEnvironment(Environment &) const;
|
void applyToEnvironment(Environment &) const;
|
||||||
@@ -144,8 +158,6 @@ public:
|
|||||||
void addUnsetValue(const QString &key);
|
void addUnsetValue(const QString &key);
|
||||||
void addPrependToPath(const FilePaths &values);
|
void addPrependToPath(const FilePaths &values);
|
||||||
void addAppendToPath(const FilePaths &values);
|
void addAppendToPath(const FilePaths &values);
|
||||||
void addModify(const NameValueItems &items);
|
|
||||||
void addChange(const Item &item) { m_changeItems.append(item); }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<Item> m_changeItems;
|
QList<Item> m_changeItems;
|
||||||
|
Reference in New Issue
Block a user