mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-11 14:02:24 +02:00
[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:
@@ -24,10 +24,24 @@
|
|||||||
<DataTemplate x:Key="VariableTemplate" x:DataType="models:Variable">
|
<DataTemplate x:Key="VariableTemplate" x:DataType="models:Variable">
|
||||||
<controls:SettingsCard
|
<controls:SettingsCard
|
||||||
CommandParameter="{x:Bind (models:Variable)}"
|
CommandParameter="{x:Bind (models:Variable)}"
|
||||||
Header="{x:Bind Name, Mode=TwoWay}"
|
|
||||||
IsActionIconVisible="False"
|
IsActionIconVisible="False"
|
||||||
IsClickEnabled="False"
|
IsClickEnabled="False"
|
||||||
Style="{StaticResource DefaultSettingsExpanderItemStyle}">
|
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=""
|
||||||
|
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>
|
<controls:SettingsCard.Description>
|
||||||
<StackPanel HorizontalAlignment="Left">
|
<StackPanel HorizontalAlignment="Left">
|
||||||
<ItemsControl
|
<ItemsControl
|
||||||
@@ -52,7 +66,6 @@
|
|||||||
Visibility="{x:Bind ShowAsList, Converter={StaticResource BoolToInvertedVisibilityConverter}}" />
|
Visibility="{x:Bind ShowAsList, Converter={StaticResource BoolToInvertedVisibilityConverter}}" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</controls:SettingsCard.Description>
|
</controls:SettingsCard.Description>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
Content="{ui:FontIcon Glyph=}"
|
Content="{ui:FontIcon Glyph=}"
|
||||||
IsEnabled="{x:Bind IsEditable}"
|
IsEnabled="{x:Bind IsEditable}"
|
||||||
|
|||||||
@@ -28,12 +28,17 @@ namespace EnvironmentVariables.Models
|
|||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private bool _applyToSystem;
|
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]
|
[JsonIgnore]
|
||||||
public bool IsEditable
|
public bool IsEditable
|
||||||
{
|
{
|
||||||
get
|
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">
|
<data name="StateProfileNotApplicableMsg" xml:space="preserve">
|
||||||
<value>Variables or backup variables are invalid.</value>
|
<value>Variables or backup variables are invalid.</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="VariableIsAppliedByActiveProfileTooltip.Text" xml:space="preserve">
|
||||||
|
<value>This variable is written by the active profile</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -67,6 +67,16 @@ namespace EnvironmentVariables.ViewModels
|
|||||||
foreach (var variable in UserDefaultSet.Variables)
|
foreach (var variable in UserDefaultSet.Variables)
|
||||||
{
|
{
|
||||||
DefaultVariables.Variables.Add(variable);
|
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)
|
foreach (var variable in SystemDefaultSet.Variables)
|
||||||
|
|||||||
Reference in New Issue
Block a user