mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-22 14:13:30 -07:00
Do not set units to default values if they already have valid values.
This commit is contained in:
parent
af41a183a7
commit
f9b403fbc7
1 changed files with 10 additions and 2 deletions
|
@ -922,17 +922,25 @@ void UnitConverter::InitializeSelectedUnits()
|
||||||
vector<Unit> curUnits = itr->second;
|
vector<Unit> curUnits = itr->second;
|
||||||
if (!curUnits.empty())
|
if (!curUnits.empty())
|
||||||
{
|
{
|
||||||
|
bool isFromRestored = find(curUnits.begin(), curUnits.end(), m_fromType) != curUnits.end();
|
||||||
|
bool isToRestored = find(curUnits.begin(), curUnits.end(), m_toType) != curUnits.end();
|
||||||
|
|
||||||
|
if (isFromRestored && isToRestored)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
bool conversionSourceSet = false;
|
bool conversionSourceSet = false;
|
||||||
bool conversionTargetSet = false;
|
bool conversionTargetSet = false;
|
||||||
for (const Unit& cur : curUnits)
|
for (const Unit& cur : curUnits)
|
||||||
{
|
{
|
||||||
if (!conversionSourceSet && cur.isConversionSource)
|
if (!conversionSourceSet && cur.isConversionSource && !isFromRestored)
|
||||||
{
|
{
|
||||||
m_fromType = cur;
|
m_fromType = cur;
|
||||||
conversionSourceSet = true;
|
conversionSourceSet = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!conversionTargetSet && cur.isConversionTarget)
|
if (!conversionTargetSet && cur.isConversionTarget && !isToRestored)
|
||||||
{
|
{
|
||||||
m_toType = cur;
|
m_toType = cur;
|
||||||
conversionTargetSet = true;
|
conversionTargetSet = true;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue