mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-22 14:13:30 -07:00
Don't call Reset/Clear when users refresh currency rates v2
This commit is contained in:
parent
4b6b8fa8fa
commit
ec534e43e9
4 changed files with 35 additions and 12 deletions
|
@ -63,6 +63,7 @@ UnitConverter::UnitConverter(_In_ const shared_ptr<IConverterDataLoader>& dataLo
|
||||||
unquoteConversions[L"{sc}"] = L';';
|
unquoteConversions[L"{sc}"] = L';';
|
||||||
unquoteConversions[L"{lb}"] = LEFTESCAPECHAR;
|
unquoteConversions[L"{lb}"] = LEFTESCAPECHAR;
|
||||||
unquoteConversions[L"{rb}"] = RIGHTESCAPECHAR;
|
unquoteConversions[L"{rb}"] = RIGHTESCAPECHAR;
|
||||||
|
ClearValues();
|
||||||
Reset();
|
Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -836,7 +837,6 @@ void UnitConverter::Reset()
|
||||||
{
|
{
|
||||||
m_categories = m_dataLoader->LoadOrderedCategories();
|
m_categories = m_dataLoader->LoadOrderedCategories();
|
||||||
|
|
||||||
ClearValues();
|
|
||||||
m_switchedActive = false;
|
m_switchedActive = false;
|
||||||
|
|
||||||
if (m_categories.empty())
|
if (m_categories.empty())
|
||||||
|
@ -881,7 +881,6 @@ void UnitConverter::Reset()
|
||||||
}
|
}
|
||||||
|
|
||||||
InitializeSelectedUnits();
|
InitializeSelectedUnits();
|
||||||
Calculate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -972,11 +971,20 @@ bool UnitConverter::AnyUnitIsEmpty()
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void UnitConverter::Calculate()
|
void UnitConverter::Calculate()
|
||||||
{
|
{
|
||||||
unordered_map<Unit, ConversionData, UnitHash> conversionTable = m_ratioMap[m_fromType];
|
if (AnyUnitIsEmpty())
|
||||||
double returnValue = stod(m_currentDisplay);
|
|
||||||
if (AnyUnitIsEmpty() || (conversionTable[m_toType].ratio == 1.0 && conversionTable[m_toType].offset == 0.0))
|
|
||||||
{
|
{
|
||||||
m_returnDisplay = m_currentDisplay;
|
m_returnDisplay = m_currentDisplay;
|
||||||
|
m_returnHasDecimal = m_currentHasDecimal;
|
||||||
|
TrimString(m_returnDisplay);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
unordered_map<Unit, ConversionData, UnitHash> conversionTable = m_ratioMap[m_fromType];
|
||||||
|
double returnValue = stod(m_currentDisplay);
|
||||||
|
if (conversionTable[m_toType].ratio == 1.0 && conversionTable[m_toType].offset == 0.0)
|
||||||
|
{
|
||||||
|
m_returnDisplay = m_currentDisplay;
|
||||||
|
m_returnHasDecimal = m_currentHasDecimal;
|
||||||
TrimString(m_returnDisplay);
|
TrimString(m_returnDisplay);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1015,9 +1023,8 @@ void UnitConverter::Calculate()
|
||||||
m_returnDisplay = returnString;
|
m_returnDisplay = returnString;
|
||||||
TrimString(m_returnDisplay);
|
TrimString(m_returnDisplay);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
m_returnHasDecimal = (m_returnDisplay.find(L'.') != m_returnDisplay.npos);
|
m_returnHasDecimal = (m_returnDisplay.find(L'.') != m_returnDisplay.npos);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -1078,3 +1085,10 @@ void UnitConverter::UpdateViewModel()
|
||||||
m_vmCallback->DisplayCallback(m_currentDisplay, m_returnDisplay);
|
m_vmCallback->DisplayCallback(m_currentDisplay, m_returnDisplay);
|
||||||
m_vmCallback->SuggestedValueCallback(CalculateSuggested());
|
m_vmCallback->SuggestedValueCallback(CalculateSuggested());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UnitConverter::ResetCategoriesAndRatio()
|
||||||
|
{
|
||||||
|
Reset();
|
||||||
|
Calculate();
|
||||||
|
UpdateViewModel();
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
// Licensed under the MIT License.
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
@ -195,6 +195,7 @@ namespace UnitConversionManager
|
||||||
virtual void SetViewModelCallback(_In_ const std::shared_ptr<IUnitConverterVMCallback>& newCallback) = 0;
|
virtual void SetViewModelCallback(_In_ const std::shared_ptr<IUnitConverterVMCallback>& newCallback) = 0;
|
||||||
virtual void SetViewModelCurrencyCallback(_In_ const std::shared_ptr<IViewModelCurrencyCallback>& newCallback) = 0;
|
virtual void SetViewModelCurrencyCallback(_In_ const std::shared_ptr<IViewModelCurrencyCallback>& newCallback) = 0;
|
||||||
virtual concurrency::task<std::pair<bool, std::wstring>> RefreshCurrencyRatios() = 0;
|
virtual concurrency::task<std::pair<bool, std::wstring>> RefreshCurrencyRatios() = 0;
|
||||||
|
virtual void ResetCategoriesAndRatio() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class UnitConverter : public IUnitConverter, public std::enable_shared_from_this<UnitConverter>
|
class UnitConverter : public IUnitConverter, public std::enable_shared_from_this<UnitConverter>
|
||||||
|
@ -220,6 +221,7 @@ namespace UnitConversionManager
|
||||||
concurrency::task<std::pair<bool, std::wstring>> RefreshCurrencyRatios() override;
|
concurrency::task<std::pair<bool, std::wstring>> RefreshCurrencyRatios() override;
|
||||||
// IUnitConverter
|
// IUnitConverter
|
||||||
|
|
||||||
|
void ResetCategoriesAndRatio();
|
||||||
static std::vector<std::wstring> StringToVector(const std::wstring& w, const wchar_t * delimiter, bool addRemainder = false);
|
static std::vector<std::wstring> StringToVector(const std::wstring& w, const wchar_t * delimiter, bool addRemainder = false);
|
||||||
static std::wstring Quote(const std::wstring& s);
|
static std::wstring Quote(const std::wstring& s);
|
||||||
static std::wstring Unquote(const std::wstring& s);
|
static std::wstring Unquote(const std::wstring& s);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
// Licensed under the MIT License.
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
#include "pch.h"
|
#include "pch.h"
|
||||||
|
@ -175,12 +175,16 @@ void UnitConverterViewModel::PopulateData()
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnitConverterViewModel::OnCategoryChanged(Object^ parameter)
|
void UnitConverterViewModel::OnCategoryChanged(Object^ parameter)
|
||||||
|
{
|
||||||
|
m_model->SendCommand(UCM::Command::Clear);
|
||||||
|
ResetCategory();
|
||||||
|
}
|
||||||
|
|
||||||
|
void UnitConverterViewModel::ResetCategory()
|
||||||
{
|
{
|
||||||
UCM::Category currentCategory = CurrentCategory->GetModelCategory();
|
UCM::Category currentCategory = CurrentCategory->GetModelCategory();
|
||||||
IsCurrencyCurrentCategory = currentCategory.id == NavCategory::Serialize(ViewMode::Currency);
|
IsCurrencyCurrentCategory = currentCategory.id == NavCategory::Serialize(ViewMode::Currency);
|
||||||
|
|
||||||
m_model->SendCommand(UCM::Command::Clear);
|
|
||||||
|
|
||||||
m_isInputBlocked = false;
|
m_isInputBlocked = false;
|
||||||
SetSelectedUnits();
|
SetSelectedUnits();
|
||||||
|
|
||||||
|
@ -716,7 +720,8 @@ void UnitConverterViewModel::OnCurrencyDataLoadFinished(bool didLoad)
|
||||||
{
|
{
|
||||||
m_isCurrencyDataLoaded = true;
|
m_isCurrencyDataLoaded = true;
|
||||||
CurrencyDataLoadFailed = !didLoad;
|
CurrencyDataLoadFailed = !didLoad;
|
||||||
ResetView();
|
m_model->ResetCategoriesAndRatio();
|
||||||
|
ResetCategory();
|
||||||
|
|
||||||
StringReference key = didLoad ? UnitConverterResourceKeys::CurrencyRatesUpdated : UnitConverterResourceKeys::CurrencyRatesUpdateFailed;
|
StringReference key = didLoad ? UnitConverterResourceKeys::CurrencyRatesUpdated : UnitConverterResourceKeys::CurrencyRatesUpdateFailed;
|
||||||
String^ announcement = AppResourceProvider::GetInstance().GetResourceString(key);
|
String^ announcement = AppResourceProvider::GetInstance().GetResourceString(key);
|
||||||
|
|
|
@ -242,6 +242,7 @@ namespace CalculatorApp
|
||||||
void UpdateValue2AutomationName();
|
void UpdateValue2AutomationName();
|
||||||
Platform::String^ Serialize();
|
Platform::String^ Serialize();
|
||||||
void Deserialize(Platform::String^ state);
|
void Deserialize(Platform::String^ state);
|
||||||
|
void ResetCategoriesAndRatio();
|
||||||
|
|
||||||
// Saving And Restoring User Preferences of Category and Associated-Units across Sessions.
|
// Saving And Restoring User Preferences of Category and Associated-Units across Sessions.
|
||||||
void SaveUserPreferences();
|
void SaveUserPreferences();
|
||||||
|
@ -282,6 +283,7 @@ namespace CalculatorApp
|
||||||
void RefreshSupplementaryResults();
|
void RefreshSupplementaryResults();
|
||||||
void UpdateInputBlocked(_In_ const std::wstring& currencyInput);
|
void UpdateInputBlocked(_In_ const std::wstring& currencyInput);
|
||||||
bool UnitsAreValid();
|
bool UnitsAreValid();
|
||||||
|
void ResetCategory();
|
||||||
|
|
||||||
void OnButtonPressed(Platform::Object^ parameter);
|
void OnButtonPressed(Platform::Object^ parameter);
|
||||||
Platform::String^ ConvertToLocalizedString(const std::wstring& stringToLocalize, bool allowPartialStrings);
|
Platform::String^ ConvertToLocalizedString(const std::wstring& stringToLocalize, bool allowPartialStrings);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue