mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-23 06:25:19 -07:00
Remove trailing decimal
Disable decimal input if maxFractionDigits is 0 Fix input may be blocked after switched active
This commit is contained in:
parent
98762d2575
commit
d30849705c
6 changed files with 46 additions and 11 deletions
|
@ -191,6 +191,18 @@ void UnitConverter::SwitchActive(const wstring& newValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool UnitConversionManager::UnitConverter::IsSwitchedActive() const
|
||||||
|
{
|
||||||
|
return m_switchedActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UnitConversionManager::UnitConverter::SetValue(const std::wstring& newValue)
|
||||||
|
{
|
||||||
|
m_returnDisplay = m_currentDisplay;
|
||||||
|
m_currentDisplay = newValue;
|
||||||
|
m_currentHasDecimal = (m_currentDisplay.find(L'.') != wstring::npos);
|
||||||
|
}
|
||||||
|
|
||||||
wstring UnitConverter::CategoryToString(const Category& c, wstring_view delimiter)
|
wstring UnitConverter::CategoryToString(const Category& c, wstring_view delimiter)
|
||||||
{
|
{
|
||||||
return Quote(std::to_wstring(c.id))
|
return Quote(std::to_wstring(c.id))
|
||||||
|
|
|
@ -223,6 +223,8 @@ namespace UnitConversionManager
|
||||||
virtual Category GetCurrentCategory() = 0;
|
virtual Category GetCurrentCategory() = 0;
|
||||||
virtual void SetCurrentUnitTypes(const Unit& fromType, const Unit& toType) = 0;
|
virtual void SetCurrentUnitTypes(const Unit& fromType, const Unit& toType) = 0;
|
||||||
virtual void SwitchActive(const std::wstring& newValue) = 0;
|
virtual void SwitchActive(const std::wstring& newValue) = 0;
|
||||||
|
virtual bool IsSwitchedActive() const = 0;
|
||||||
|
virtual void SetValue(const std::wstring& newValue) = 0;
|
||||||
virtual std::wstring SaveUserPreferences() = 0;
|
virtual std::wstring SaveUserPreferences() = 0;
|
||||||
virtual void RestoreUserPreferences(_In_ std::wstring_view userPreferences) = 0;
|
virtual void RestoreUserPreferences(_In_ std::wstring_view userPreferences) = 0;
|
||||||
virtual void SendCommand(Command command) = 0;
|
virtual void SendCommand(Command command) = 0;
|
||||||
|
@ -246,6 +248,8 @@ namespace UnitConversionManager
|
||||||
Category GetCurrentCategory() override;
|
Category GetCurrentCategory() override;
|
||||||
void SetCurrentUnitTypes(const Unit& fromType, const Unit& toType) override;
|
void SetCurrentUnitTypes(const Unit& fromType, const Unit& toType) override;
|
||||||
void SwitchActive(const std::wstring& newValue) override;
|
void SwitchActive(const std::wstring& newValue) override;
|
||||||
|
bool IsSwitchedActive() const override;
|
||||||
|
void SetValue(const std::wstring& newValue) override;
|
||||||
std::wstring SaveUserPreferences() override;
|
std::wstring SaveUserPreferences() override;
|
||||||
void RestoreUserPreferences(std::wstring_view userPreference) override;
|
void RestoreUserPreferences(std::wstring_view userPreference) override;
|
||||||
void SendCommand(Command command) override;
|
void SendCommand(Command command) override;
|
||||||
|
|
|
@ -227,9 +227,8 @@ void UnitConverterViewModel::OnUnitChanged(Object ^ parameter)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_model->SetCurrentUnitTypes(UnitFrom->GetModelUnit(), UnitTo->GetModelUnit());
|
|
||||||
|
|
||||||
UpdateCurrencyFormatter();
|
UpdateCurrencyFormatter();
|
||||||
|
m_model->SetCurrentUnitTypes(UnitFrom->GetModelUnit(), UnitTo->GetModelUnit());
|
||||||
|
|
||||||
if (m_supplementaryResultsTimer != nullptr)
|
if (m_supplementaryResultsTimer != nullptr)
|
||||||
{
|
{
|
||||||
|
@ -271,6 +270,8 @@ void UnitConverterViewModel::OnSwitchActive(Platform::Object ^ unused)
|
||||||
|
|
||||||
m_isInputBlocked = false;
|
m_isInputBlocked = false;
|
||||||
m_model->SwitchActive(m_valueFromUnlocalized);
|
m_model->SwitchActive(m_valueFromUnlocalized);
|
||||||
|
|
||||||
|
UpdateIsDecimalEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
String ^ UnitConverterViewModel::ConvertToLocalizedString(const std::wstring& stringToLocalize, bool allowPartialStrings, CurrencyFormatterParameter cfp)
|
String ^ UnitConverterViewModel::ConvertToLocalizedString(const std::wstring& stringToLocalize, bool allowPartialStrings, CurrencyFormatterParameter cfp)
|
||||||
|
@ -330,7 +331,7 @@ String ^ UnitConverterViewModel::ConvertToLocalizedString(const std::wstring& st
|
||||||
|
|
||||||
if (hasDecimal)
|
if (hasDecimal)
|
||||||
{
|
{
|
||||||
if (allowPartialStrings)
|
if (allowPartialStrings && lastCurrencyFractionDigits > 0)
|
||||||
{
|
{
|
||||||
// allow "in progress" strings, like "3." that occur during the composition of
|
// allow "in progress" strings, like "3." that occur during the composition of
|
||||||
// a final number. Without this, when typing the three characters in "3.2"
|
// a final number. Without this, when typing the three characters in "3.2"
|
||||||
|
@ -504,9 +505,7 @@ void UnitConverterViewModel::OnButtonPressed(Platform::Object ^ parameter)
|
||||||
|
|
||||||
static constexpr UCM::Command OPERANDS[] = { UCM::Command::Zero, UCM::Command::One, UCM::Command::Two, UCM::Command::Three, UCM::Command::Four,
|
static constexpr UCM::Command OPERANDS[] = { UCM::Command::Zero, UCM::Command::One, UCM::Command::Two, UCM::Command::Three, UCM::Command::Four,
|
||||||
UCM::Command::Five, UCM::Command::Six, UCM::Command::Seven, UCM::Command::Eight, UCM::Command::Nine };
|
UCM::Command::Five, UCM::Command::Six, UCM::Command::Seven, UCM::Command::Eight, UCM::Command::Nine };
|
||||||
if (m_isInputBlocked &&
|
if (m_isInputBlocked && !m_model->IsSwitchedActive() && command != UCM::Command::Clear && command != UCM::Command::Backspace)
|
||||||
command != UCM::Command::Clear &&
|
|
||||||
command != UCM::Command::Backspace)
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -851,6 +850,13 @@ void UnitConverterViewModel::UpdateCurrencyFormatter()
|
||||||
m_currencyFormatter2->IsGrouped = true;
|
m_currencyFormatter2->IsGrouped = true;
|
||||||
m_currencyFormatter2->Mode = CurrencyFormatterMode::UseCurrencyCode;
|
m_currencyFormatter2->Mode = CurrencyFormatterMode::UseCurrencyCode;
|
||||||
m_currencyFormatter2->ApplyRoundingForCurrency(RoundingAlgorithm::RoundHalfDown);
|
m_currencyFormatter2->ApplyRoundingForCurrency(RoundingAlgorithm::RoundHalfDown);
|
||||||
|
|
||||||
|
UpdateIsDecimalEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
void UnitConverterViewModel::UpdateIsDecimalEnabled()
|
||||||
|
{
|
||||||
|
IsDecimalEnabled = CurrencyFormatterFrom->FractionDigits > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
NumbersAndOperatorsEnum UnitConverterViewModel::MapCharacterToButtonId(const wchar_t ch, bool& canSendNegate)
|
NumbersAndOperatorsEnum UnitConverterViewModel::MapCharacterToButtonId(const wchar_t ch, bool& canSendNegate)
|
||||||
|
|
|
@ -288,6 +288,7 @@ namespace CalculatorApp
|
||||||
void RefreshSupplementaryResults();
|
void RefreshSupplementaryResults();
|
||||||
void UpdateInputBlocked(_In_ const std::wstring& currencyInput);
|
void UpdateInputBlocked(_In_ const std::wstring& currencyInput);
|
||||||
void UpdateCurrencyFormatter();
|
void UpdateCurrencyFormatter();
|
||||||
|
void UpdateIsDecimalEnabled();
|
||||||
bool UnitsAreValid();
|
bool UnitsAreValid();
|
||||||
void ResetCategory();
|
void ResetCategory();
|
||||||
|
|
||||||
|
|
|
@ -220,6 +220,16 @@ void UnitConverterMock::SwitchActive(const std::wstring& newValue)
|
||||||
m_curValue = newValue;
|
m_curValue = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool UnitConverterMock::IsSwitchedActive() const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UnitConverterMock::SetValue(const std::wstring& newValue)
|
||||||
|
{
|
||||||
|
m_curValue = newValue;
|
||||||
|
}
|
||||||
|
|
||||||
std::wstring UnitConverterMock::SaveUserPreferences()
|
std::wstring UnitConverterMock::SaveUserPreferences()
|
||||||
{
|
{
|
||||||
return L"TEST";
|
return L"TEST";
|
||||||
|
@ -950,8 +960,8 @@ TEST_METHOD(TestCurrencyFormattingLogic)
|
||||||
|
|
||||||
// Establish base condition
|
// Establish base condition
|
||||||
vm.CurrentCategory = vm.Categories->GetAt(3); // Currency
|
vm.CurrentCategory = vm.Categories->GetAt(3); // Currency
|
||||||
vm.Unit1 = vm.Units->GetAt(0); // JPY
|
vm.Unit1 = vm.Units->GetAt(0); // JPY
|
||||||
vm.Unit2 = vm.Units->GetAt(1); // JOD
|
vm.Unit2 = vm.Units->GetAt(1); // JOD
|
||||||
vm.UnitChanged->Execute(nullptr);
|
vm.UnitChanged->Execute(nullptr);
|
||||||
|
|
||||||
const WCHAR *vFrom = L"1.2340", *vTo = L"0.0070";
|
const WCHAR *vFrom = L"1.2340", *vTo = L"0.0070";
|
||||||
|
|
|
@ -38,7 +38,9 @@ namespace CalculatorUnitTests
|
||||||
UCM::CategorySelectionInitializer SetCurrentCategory(const UCM::Category& input) override;
|
UCM::CategorySelectionInitializer SetCurrentCategory(const UCM::Category& input) override;
|
||||||
UCM::Category GetCurrentCategory();
|
UCM::Category GetCurrentCategory();
|
||||||
void SetCurrentUnitTypes(const UCM::Unit& fromType, const UCM::Unit& toType) override;
|
void SetCurrentUnitTypes(const UCM::Unit& fromType, const UCM::Unit& toType) override;
|
||||||
void SwitchActive(const std::wstring& newValue);
|
void SwitchActive(const std::wstring& newValue) override;
|
||||||
|
bool IsSwitchedActive() const override;
|
||||||
|
void SetValue(const std::wstring& newValue) override;
|
||||||
std::wstring SaveUserPreferences() override;
|
std::wstring SaveUserPreferences() override;
|
||||||
void RestoreUserPreferences(_In_ std::wstring_view userPreferences) override;
|
void RestoreUserPreferences(_In_ std::wstring_view userPreferences) override;
|
||||||
void SendCommand(UCM::Command command) override;
|
void SendCommand(UCM::Command command) override;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue