### Description of the changes: **1) Do not set units to default values if they already have valid values** This fixes the actual issue. `UnitConverter::InitializeSelectedUnits()` ( this function resets all units to their default units if available for the current category ) gets called after `UnitConverterViewModel::RestoreUserPreferences()` ( this function restores user preferences ). So Calculator has been restoring saved values, and then overriding the restored values with default values. I modified `InitializeSelectedUnits()` so that we only initialize units only when they are not already set to valid units for the current category. **2) Removed `m_isFirstTime`** I noticed that we are calling `RestoreUserPreferences()` twice when Calculator starts up, and the function is restoring the same value both times The below happens when Calculator starts up 1) On startup, in `UnitConverterViewModel::InitializeView()`, `RestoreUserPreferences()` is called. 2) `RestoreUserPreferences()` in turn triggers `OnUnitChanged()` 3) During the first call to `OnUnitChanged()`, m_IsFirstTime is `True`, so we call `RestoreUserPreferences()` again while also setting `m_IsFirstTime` to `False`. 4) `RestoreUserPreference()` again triggers `OnUnitChanged()` 5) During the second call to `OnUnitChanged()`, m_IsFirstTime is `False`, so we call `SaveUserPreferences()` I think we should only call `SaveUserPreferences()` inside `OnUnitChanged()` since we already restored user preferences during view initialization. I can't really think of a reason to restore units after view has been initialized. This led me to just delete `m_isFirstTime`. ### How changes were validated: Manually tested that units and the current category are properly selected when you quit and start Calculator.   ## Fixes #445. |
||
---|---|---|
.. | ||
build | ||
CalcManager | ||
Calculator | ||
CalculatorUITestFramework | ||
CalculatorUITests | ||
CalculatorUnitTests | ||
CalcViewModel | ||
Calculator.sln | ||
CMakeLists.txt | ||
nuget.config | ||
Settings.XamlStyler |