Skip to content

Commit

Permalink
Update PreferencesViewModel.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
zeusongit committed Jan 10, 2024
1 parent 83b1162 commit 52f1016
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/DynamoCoreWpf/ViewModels/Menu/PreferencesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,14 @@ public string SelectedUnits

if (UseHostScaleUnits && IsDynamoRevit) return;

var result = Enum.TryParse(selectedUnits, out Configurations.Units currentUnit);
var enUnit = LocalizedUnitsMap.FirstOrDefault(x => x.Key == selectedUnits).Value;
var result = Enum.TryParse(enUnit, out Configurations.Units currentUnit);
if (!result) return;

if (Configurations.SupportedUnits.TryGetValue(currentUnit, out double units))
{
// Update preferences setting and update the grapic helpers
preferenceSettings.GraphicScaleUnit = value;
preferenceSettings.GraphicScaleUnit = currentUnit.ToString();
preferenceSettings.GridScaleFactor = (float)units;
dynamoViewModel.UpdateGraphicHelpersScaleCommand.Execute(null);

Expand Down Expand Up @@ -1291,6 +1292,12 @@ public bool importSettingsContent(string content)
return setSettings(newPreferences);
}

/// <summary>
/// The dictionary that contains the localized resource strings for Units.
/// This is done to avoid a breaking change that is storing the selected unit in settings file in english language.
/// </summary>
private Dictionary<string, string> LocalizedUnitsMap;

/// <summary>
/// Returns localized resource strings for Units
/// </summary>
Expand Down Expand Up @@ -1392,6 +1399,12 @@ public PreferencesViewModel(DynamoViewModel dynamoViewModel)
LanguagesList = Configurations.SupportedLocaleDic.Keys.ToObservableCollection();
SelectedLanguage = Configurations.SupportedLocaleDic.FirstOrDefault(x => x.Value == preferenceSettings.Locale).Key;

LocalizedUnitsMap = new Dictionary<string, string>();
foreach (var unit in Configurations.SupportedUnits)
{
LocalizedUnitsMap.Add(GetLocalizedUnits(unit.Key), unit.Key.ToString());
}

// Chose the scaling unit, if option is allowed by user
UnitList = Configurations.SupportedUnits.Keys.Select(x => GetLocalizedUnits(x)).ToObservableCollection();
SelectedUnits = GetLocalizedUnits(Configurations.SupportedUnits.FirstOrDefault(x => x.Key.ToString() == preferenceSettings.GraphicScaleUnit).Key);
Expand Down

0 comments on commit 52f1016

Please sign in to comment.