[EnvVar]Mark and disable editing of user variables that are applied by a profile (#29451)

* [EnvVar] Mark profile variable in user variables

* Mark backup variables

* Add tooltip to icon, put in header and disable editing of applied var

* Use completed icon instead

* Better var name and comments

---------

Co-authored-by: Jaime Bernardo <jaime@janeasystems.com>
This commit is contained in:
Stefan Markovic 2023-10-27 12:59:52 +02:00 коммит произвёл GitHub
Родитель 1dde699688
Коммит 66f4f69841
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 34 добавлений и 3 удалений

Просмотреть файл

@ -24,10 +24,24 @@
<DataTemplate x:Key="VariableTemplate" x:DataType="models:Variable">
<controls:SettingsCard
CommandParameter="{x:Bind (models:Variable)}"
Header="{x:Bind Name, Mode=TwoWay}"
IsActionIconVisible="False"
IsClickEnabled="False"
Style="{StaticResource DefaultSettingsExpanderItemStyle}">
<controls:SettingsCard.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{x:Bind Name, Mode=TwoWay}" />
<FontIcon
Margin="6,0,6,0"
FontSize="16"
Foreground="{ThemeResource AccentTextFillColorPrimaryBrush}"
Glyph="&#xE930;"
Visibility="{x:Bind IsAppliedFromProfile, Converter={StaticResource BoolToVisibilityConverter}}">
<ToolTipService.ToolTip>
<TextBlock x:Uid="VariableIsAppliedByActiveProfileTooltip" TextWrapping="Wrap" />
</ToolTipService.ToolTip>
</FontIcon>
</StackPanel>
</controls:SettingsCard.Header>
<controls:SettingsCard.Description>
<StackPanel HorizontalAlignment="Left">
<ItemsControl
@ -52,7 +66,6 @@
Visibility="{x:Bind ShowAsList, Converter={StaticResource BoolToInvertedVisibilityConverter}}" />
</StackPanel>
</controls:SettingsCard.Description>
<Button
Content="{ui:FontIcon Glyph=&#xE712;}"
IsEnabled="{x:Bind IsEditable}"

Просмотреть файл

@ -28,12 +28,17 @@ namespace EnvironmentVariables.Models
[ObservableProperty]
private bool _applyToSystem;
[JsonIgnore]
[property: JsonIgnore]
[ObservableProperty]
private bool _isAppliedFromProfile; // Used to mark that a variable in a default set is applied by a profile. Used to disable editing / mark it in the UI.
[JsonIgnore]
public bool IsEditable
{
get
{
return ParentType != VariablesSetType.System || App.GetService<IElevationHelper>().IsElevated;
return (ParentType != VariablesSetType.System || App.GetService<IElevationHelper>().IsElevated) && !IsAppliedFromProfile;
}
}

Просмотреть файл

@ -280,4 +280,7 @@
<data name="StateProfileNotApplicableMsg" xml:space="preserve">
<value>Variables or backup variables are invalid.</value>
</data>
<data name="VariableIsAppliedByActiveProfileTooltip.Text" xml:space="preserve">
<value>This variable is written by the active profile</value>
</data>
</root>

Просмотреть файл

@ -67,6 +67,16 @@ namespace EnvironmentVariables.ViewModels
foreach (var variable in UserDefaultSet.Variables)
{
DefaultVariables.Variables.Add(variable);
if (AppliedProfile != null)
{
if (AppliedProfile.Variables.Where(
x => (x.Name.Equals(variable.Name, StringComparison.OrdinalIgnoreCase) && x.Values.Equals(variable.Values, StringComparison.OrdinalIgnoreCase))
|| variable.Name.Equals(EnvironmentVariablesHelper.GetBackupVariableName(x, AppliedProfile.Name), StringComparison.OrdinalIgnoreCase)).Any())
{
// If it's a user variable that's also in the profile or is a backup variable, mark it as applied from profile.
variable.IsAppliedFromProfile = true;
}
}
}
foreach (var variable in SystemDefaultSet.Variables)