Fix duplicate variables handling

Fix user variable handling and preview
This commit is contained in:
Stefan Markovic
2023-10-04 16:44:30 +02:00
parent 6717fea41e
commit bb684d30a0
5 changed files with 15 additions and 7 deletions

View File

@@ -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(),
};
}

View File

@@ -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);
}
}

View File

@@ -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);

View File

@@ -6,7 +6,9 @@ namespace EnvironmentVariables.Models
{
public enum VariablesSetType
{
User = 0,
Path = 0,
Duplicate,
User,
System,
Profile,
}

View File

@@ -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)