mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 03:37:59 +01:00
Fix duplicate variables handling
Fix user variable handling and preview
This commit is contained in:
@@ -18,6 +18,8 @@ public class VariableTypeToGlyphConverter : IValueConverter
|
||||
VariablesSetType.User => "\uE77B",
|
||||
VariablesSetType.System => "\uE977",
|
||||
VariablesSetType.Profile => "\uEDE3",
|
||||
VariablesSetType.Path => "\uE8AC",
|
||||
VariablesSetType.Duplicate => "\uE8C8",
|
||||
_ => throw new NotImplementedException(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace EnvironmentVariables.Helpers
|
||||
var key = variable.Key as string;
|
||||
if (key.Equals(variableName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return new Variable(variableName, userVariables[key] as string, VariablesSetType.User);
|
||||
return new Variable(key, userVariables[key] as string, VariablesSetType.User);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace EnvironmentVariables.Helpers
|
||||
var key = variable.Key as string;
|
||||
if (key.Equals(variableName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return new Variable(variableName, userVariables[key] as string, VariablesSetType.System);
|
||||
return new Variable(key, systemVariables[key] as string, VariablesSetType.System);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace EnvironmentVariables.Models
|
||||
var variableToOverride = EnvironmentVariablesHelper.GetExisting(variable.Name);
|
||||
|
||||
// It exists. Rename it to preserve it.
|
||||
if (variableToOverride != null)
|
||||
if (variableToOverride != null && variableToOverride.ParentType == VariablesSetType.User)
|
||||
{
|
||||
variableToOverride.Name = EnvironmentVariablesHelper.GetBackupVariableName(variableToOverride, this.Name);
|
||||
|
||||
|
||||
@@ -6,7 +6,9 @@ namespace EnvironmentVariables.Models
|
||||
{
|
||||
public enum VariablesSetType
|
||||
{
|
||||
User = 0,
|
||||
Path = 0,
|
||||
Duplicate,
|
||||
User,
|
||||
System,
|
||||
Profile,
|
||||
}
|
||||
|
||||
@@ -140,6 +140,7 @@ namespace EnvironmentVariables.ViewModels
|
||||
if (!string.IsNullOrEmpty(userPath.Name) && !string.IsNullOrEmpty(systemPath.Name))
|
||||
{
|
||||
var clone = systemPath.Clone();
|
||||
clone.ParentType = VariablesSetType.Path;
|
||||
clone.Values += ";" + userPath.Values;
|
||||
variables.Remove(userPath);
|
||||
variables.Insert(variables.IndexOf(systemPath), clone);
|
||||
@@ -155,13 +156,15 @@ namespace EnvironmentVariables.ViewModels
|
||||
var userVar = duplicate.ElementAt(0);
|
||||
var systemVar = duplicate.ElementAt(1);
|
||||
|
||||
var clone = systemVar.Clone();
|
||||
clone.Values = userVar.Values;
|
||||
var clone = userVar.Clone();
|
||||
clone.ParentType = VariablesSetType.Duplicate;
|
||||
clone.Name = systemVar.Name;
|
||||
variables.Insert(variables.IndexOf(userVar), clone);
|
||||
variables.Remove(userVar);
|
||||
variables.Insert(variables.IndexOf(systemVar), clone);
|
||||
variables.Remove(systemVar);
|
||||
}
|
||||
|
||||
variables = variables.OrderBy(x => x.ParentType).ToList();
|
||||
AppliedVariables = new ObservableCollection<Variable>(variables);
|
||||
}
|
||||
|
||||
@@ -179,6 +182,7 @@ namespace EnvironmentVariables.ViewModels
|
||||
}
|
||||
|
||||
EnvironmentVariablesHelper.SetVariable(variable);
|
||||
PopulateAppliedVariables();
|
||||
}
|
||||
|
||||
internal void EditVariable(Variable original, Variable edited, ProfileVariablesSet variablesSet)
|
||||
|
||||
Reference in New Issue
Block a user