Skip to content

Commit

Permalink
[EnvVar]Mark and disable editing of user variables that are applied b…
Browse files Browse the repository at this point in the history
…y 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>
  • Loading branch information
stefansjfw and jaimecbernardo committed Oct 27, 2023
1 parent 1dde699 commit 66f4f69
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
Expand Up @@ -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
Expand All @@ -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}"
Expand Down
Expand Up @@ -28,12 +28,17 @@ public partial class Variable : ObservableObject, IJsonOnDeserialized
[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;
}
}

Expand Down
Expand Up @@ -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>
Expand Up @@ -67,6 +67,16 @@ private void LoadDefaultVariables()
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)
Expand Down

0 comments on commit 66f4f69

Please sign in to comment.