From 3bff99b323a3711a91b1fa5b4a8618a08667e390 Mon Sep 17 00:00:00 2001 From: Daniel Belcher Date: Wed, 20 Mar 2019 09:56:59 -0700 Subject: [PATCH] ViewModelProperties namespaces converted to static member properties. (#306) --- src/CalcViewModel/ApplicationViewModel.cpp | 21 ++-- src/CalcViewModel/ApplicationViewModel.h | 23 ++--- src/CalcViewModel/Common/Utils.h | 12 ++- src/CalcViewModel/DateCalculatorViewModel.cpp | 26 ++--- .../StandardCalculatorViewModel.cpp | 68 ++++++------- .../StandardCalculatorViewModel.h | 19 ++-- src/CalcViewModel/UnitConverterViewModel.cpp | 98 +++++++++---------- src/CalcViewModel/UnitConverterViewModel.h | 29 +----- src/Calculator/Views/Calculator.xaml.cpp | 4 +- .../CalculatorProgrammerBitFlipPanel.xaml.cpp | 2 +- ...alculatorProgrammerRadixOperators.xaml.cpp | 2 +- .../CalculatorScientificOperators.xaml.cpp | 2 +- src/Calculator/Views/MainPage.xaml.cpp | 9 +- .../Views/SupplementaryResults.xaml.cpp | 2 +- src/Calculator/Views/UnitConverter.xaml.cpp | 8 +- 15 files changed, 142 insertions(+), 183 deletions(-) diff --git a/src/CalcViewModel/ApplicationViewModel.cpp b/src/CalcViewModel/ApplicationViewModel.cpp index 4df5bac..f99ce03 100644 --- a/src/CalcViewModel/ApplicationViewModel.cpp +++ b/src/CalcViewModel/ApplicationViewModel.cpp @@ -32,14 +32,11 @@ using namespace Windows::UI::Xaml::Data; using namespace Windows::UI::Xaml::Input; using namespace Windows::UI::Xaml::Media; -namespace CalculatorApp::ViewModel::ApplicationViewModelProperties +namespace { - StringReference Mode(L"Mode"); - StringReference PreviousMode(L"PreviousMode"); - StringReference ClearMemoryVisibility(L"ClearMemoryVisibility"); - StringReference AppBarVisibility(L"AppBarVisibility"); - StringReference CategoryName(L"CategoryName"); - StringReference Categories(L"Categories"); + StringReference CategoriesPropertyName(L"Categories"); + StringReference ClearMemoryVisibilityPropertyName(L"ClearMemoryVisibility"); + StringReference AppBarVisibilityPropertyName(L"AppBarVisibility"); } ApplicationViewModel::ApplicationViewModel() : @@ -60,7 +57,7 @@ void ApplicationViewModel::Mode::set(ViewMode value) PreviousMode = m_mode; m_mode = value; OnModeChanged(); - RaisePropertyChanged(ApplicationViewModelProperties::Mode); + RaisePropertyChanged(ModePropertyName); } } @@ -69,7 +66,7 @@ void ApplicationViewModel::Categories::set(IObservableVector^ if (m_categories != value) { m_categories = value; - RaisePropertyChanged(ApplicationViewModelProperties::Categories); + RaisePropertyChanged(CategoriesPropertyName); } } @@ -163,11 +160,11 @@ void ApplicationViewModel::OnModeChanged() // // Save the changed mode, so that the new window launches in this mode. // Don't save until after we have adjusted to the new mode, so we don't save a mode that fails to load. - ApplicationData::Current->LocalSettings->Values->Insert(ApplicationViewModelProperties::Mode, NavCategory::Serialize(m_mode)); + ApplicationData::Current->LocalSettings->Values->Insert(ModePropertyName, NavCategory::Serialize(m_mode)); TraceLogger::GetInstance().LogModeChangeEnd(m_mode, ApplicationView::GetApplicationViewIdForWindow(CoreWindow::GetForCurrentThread())); - RaisePropertyChanged(ApplicationViewModelProperties::ClearMemoryVisibility); - RaisePropertyChanged(ApplicationViewModelProperties::AppBarVisibility); + RaisePropertyChanged(ClearMemoryVisibilityPropertyName); + RaisePropertyChanged(AppBarVisibilityPropertyName); } void ApplicationViewModel::OnCopyCommand(Object^ parameter) diff --git a/src/CalcViewModel/ApplicationViewModel.h b/src/CalcViewModel/ApplicationViewModel.h index a8d459f..f13e00a 100644 --- a/src/CalcViewModel/ApplicationViewModel.h +++ b/src/CalcViewModel/ApplicationViewModel.h @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. #pragma once @@ -11,16 +11,6 @@ namespace CalculatorApp { namespace ViewModel { - namespace ApplicationViewModelProperties - { - extern Platform::StringReference Mode; - extern Platform::StringReference PreviousMode; - extern Platform::StringReference ClearMemoryVisibility; - extern Platform::StringReference AppBarVisibility; - extern Platform::StringReference CategoryName; - extern Platform::StringReference Categories; - } - [Windows::UI::Xaml::Data::Bindable] public ref class ApplicationViewModel sealed : public Windows::UI::Xaml::Data::INotifyPropertyChanged { @@ -32,9 +22,9 @@ namespace CalculatorApp OBSERVABLE_OBJECT(); OBSERVABLE_PROPERTY_RW(StandardCalculatorViewModel^, CalculatorViewModel); OBSERVABLE_PROPERTY_RW(DateCalculatorViewModel^, DateCalcViewModel); - OBSERVABLE_PROPERTY_RW(CalculatorApp::ViewModel::UnitConverterViewModel^, ConverterViewModel); + OBSERVABLE_PROPERTY_RW(UnitConverterViewModel^, ConverterViewModel); OBSERVABLE_PROPERTY_RW(CalculatorApp::Common::ViewMode, PreviousMode); - OBSERVABLE_PROPERTY_RW(Platform::String^, CategoryName); + OBSERVABLE_NAMED_PROPERTY_RW(Platform::String^, CategoryName); COMMAND_FOR_METHOD(CopyCommand, ApplicationViewModel::OnCopyCommand); COMMAND_FOR_METHOD(PasteCommand, ApplicationViewModel::OnPasteCommand); @@ -48,6 +38,13 @@ namespace CalculatorApp void set(CalculatorApp::Common::ViewMode value); } + static property Platform::String^ ModePropertyName + { + Platform::String^ get() + { + return Platform::StringReference(L"Mode"); + } + } property Windows::Foundation::Collections::IObservableVector^ Categories { diff --git a/src/CalcViewModel/Common/Utils.h b/src/CalcViewModel/Common/Utils.h index 03a4c72..a6b773a 100644 --- a/src/CalcViewModel/Common/Utils.h +++ b/src/CalcViewModel/Common/Utils.h @@ -42,10 +42,16 @@ }\ } private: t m_##n; public: -#define NAMED_OBSERVABLE_PROPERTY_RW(t, n)\ +#define OBSERVABLE_NAMED_PROPERTY_R(t, n)\ + OBSERVABLE_PROPERTY_R(t, n)\ + internal: static property Platform::String^ n##PropertyName {\ + Platform::String^ get() { return Platform::StringReference(L#n); }\ + } public: + +#define OBSERVABLE_NAMED_PROPERTY_RW(t, n)\ OBSERVABLE_PROPERTY_RW(t, n)\ - private: property Platform::StringReference n##_PropertyName {\ - Platform::StringReference get() { return Platform::StringReference(L#n); }\ + internal: static property Platform::String^ n##PropertyName {\ + Platform::String^ get() { return Platform::StringReference(L#n); }\ } public: #define OBSERVABLE_PROPERTY_FIELD(n) m_##n diff --git a/src/CalcViewModel/DateCalculatorViewModel.cpp b/src/CalcViewModel/DateCalculatorViewModel.cpp index e581a55..fd4bb71 100644 --- a/src/CalcViewModel/DateCalculatorViewModel.cpp +++ b/src/CalcViewModel/DateCalculatorViewModel.cpp @@ -22,14 +22,14 @@ using namespace Windows::Globalization; using namespace Windows::Globalization::DateTimeFormatting; using namespace Windows::System::UserProfile; -namespace CalculatorApp::ViewModel::DateCalculatorViewModelProperties +namespace { - StringReference StrDateDiffResult(L"StrDateDiffResult"); - StringReference StrDateDiffResultAutomationName(L"StrDateDiffResultAutomationName"); - StringReference StrDateDiffResultInDays(L"StrDateDiffResultInDays"); - StringReference StrDateResult(L"StrDateResult"); - StringReference StrDateResultAutomationName(L"StrDateResultAutomationName"); - StringReference IsDiffInDays(L"IsDiffInDays"); + StringReference StrDateDiffResultPropertyName(L"StrDateDiffResult"); + StringReference StrDateDiffResultAutomationNamePropertyName(L"StrDateDiffResultAutomationName"); + StringReference StrDateDiffResultInDaysPropertyName(L"StrDateDiffResultInDays"); + StringReference StrDateResultPropertyName(L"StrDateResult"); + StringReference StrDateResultAutomationNamePropertyName(L"StrDateResultAutomationName"); + StringReference IsDiffInDaysPropertyName(L"IsDiffInDays"); } DateCalculatorViewModel::DateCalculatorViewModel() : @@ -97,18 +97,18 @@ DateCalculatorViewModel::DateCalculatorViewModel() : void DateCalculatorViewModel::OnPropertyChanged(_In_ String^ prop) { - if (prop == DateCalculatorViewModelProperties::StrDateDiffResult) + if (prop == StrDateDiffResultPropertyName) { UpdateStrDateDiffResultAutomationName(); } - else if (prop == DateCalculatorViewModelProperties::StrDateResult) + else if (prop == StrDateResultPropertyName) { UpdateStrDateResultAutomationName(); } - else if (prop != DateCalculatorViewModelProperties::StrDateDiffResultAutomationName - && prop != DateCalculatorViewModelProperties::StrDateDiffResultInDays - && prop != DateCalculatorViewModelProperties::StrDateResultAutomationName - && prop != DateCalculatorViewModelProperties::IsDiffInDays) + else if (prop != StrDateDiffResultAutomationNamePropertyName + && prop != StrDateDiffResultInDaysPropertyName + && prop != StrDateResultAutomationNamePropertyName + && prop != IsDiffInDaysPropertyName) { OnInputsChanged(); } diff --git a/src/CalcViewModel/StandardCalculatorViewModel.cpp b/src/CalcViewModel/StandardCalculatorViewModel.cpp index 2660455..d6b399b 100644 --- a/src/CalcViewModel/StandardCalculatorViewModel.cpp +++ b/src/CalcViewModel/StandardCalculatorViewModel.cpp @@ -30,40 +30,34 @@ constexpr int StandardModePrecision = 16; constexpr int ScientificModePrecision = 32; constexpr int ProgrammerModePrecision = 64; -namespace CalculatorApp::ViewModel +namespace { - namespace CalculatorViewModelProperties - { - StringReference IsMemoryEmpty(L"IsMemoryEmpty"); - StringReference IsScientific(L"IsScientific"); - StringReference IsStandard(L"IsStandard"); - StringReference IsProgrammer(L"IsProgrammer"); - StringReference DisplayValue(L"DisplayValue"); - StringReference IsInError(L"IsInError"); - StringReference BinaryDisplayValue(L"BinaryDisplayValue"); - StringReference OpenParenthesisCount(L"OpenParenthesisCount"); - } + StringReference IsStandardPropertyName(L"IsStandard"); + StringReference IsScientificPropertyName(L"IsScientific"); + StringReference IsProgrammerPropertyName(L"IsProgrammer"); + StringReference DisplayValuePropertyName(L"DisplayValue"); + StringReference CalculationResultAutomationNamePropertyName(L"CalculationResultAutomationName"); +} - namespace CalculatorResourceKeys - { - StringReference CalculatorExpression(L"Format_CalculatorExpression"); - StringReference CalculatorResults(L"Format_CalculatorResults"); - StringReference CalculatorResults_DecimalSeparator_Announced(L"Format_CalculatorResults_Decimal"); - StringReference HexButton(L"Format_HexButtonValue"); - StringReference DecButton(L"Format_DecButtonValue"); - StringReference OctButton(L"Format_OctButtonValue"); - StringReference BinButton(L"Format_BinButtonValue"); - StringReference LeftParenthesisAutomationFormat(L"Format_OpenParenthesisAutomationNamePrefix"); - StringReference OpenParenthesisCountAutomationFormat(L"Format_OpenParenthesisCountAutomationNamePrefix"); - StringReference NoParenthesisAdded(L"NoRightParenthesisAdded_Announcement"); - StringReference MaxDigitsReachedFormat(L"Format_MaxDigitsReached"); - StringReference ButtonPressFeedbackFormat(L"Format_ButtonPressAuditoryFeedback"); - StringReference MemorySave(L"Format_MemorySave"); - StringReference MemoryItemChanged(L"Format_MemorySlotChanged"); - StringReference MemoryItemCleared(L"Format_MemorySlotCleared"); - StringReference MemoryCleared(L"Memory_Cleared"); - StringReference DisplayCopied(L"Display_Copied"); - } +namespace CalculatorResourceKeys +{ + StringReference CalculatorExpression(L"Format_CalculatorExpression"); + StringReference CalculatorResults(L"Format_CalculatorResults"); + StringReference CalculatorResults_DecimalSeparator_Announced(L"Format_CalculatorResults_Decimal"); + StringReference HexButton(L"Format_HexButtonValue"); + StringReference DecButton(L"Format_DecButtonValue"); + StringReference OctButton(L"Format_OctButtonValue"); + StringReference BinButton(L"Format_BinButtonValue"); + StringReference LeftParenthesisAutomationFormat(L"Format_OpenParenthesisAutomationNamePrefix"); + StringReference OpenParenthesisCountAutomationFormat(L"Format_OpenParenthesisCountAutomationNamePrefix"); + StringReference NoParenthesisAdded(L"NoRightParenthesisAdded_Announcement"); + StringReference MaxDigitsReachedFormat(L"Format_MaxDigitsReached"); + StringReference ButtonPressFeedbackFormat(L"Format_ButtonPressAuditoryFeedback"); + StringReference MemorySave(L"Format_MemorySave"); + StringReference MemoryItemChanged(L"Format_MemorySlotChanged"); + StringReference MemoryItemCleared(L"Format_MemorySlotCleared"); + StringReference MemoryCleared(L"Memory_Cleared"); + StringReference DisplayCopied(L"Display_Copied"); } StandardCalculatorViewModel::StandardCalculatorViewModel() : @@ -1276,30 +1270,30 @@ void StandardCalculatorViewModel::Deserialize(Array^ state) void StandardCalculatorViewModel::OnPropertyChanged(String^ propertyname) { - if (propertyname == CalculatorViewModelProperties::IsScientific) + if (propertyname == IsScientificPropertyName) { if (IsScientific) { OnButtonPressed(NumbersAndOperatorsEnum::IsScientificMode); } } - else if (propertyname == CalculatorViewModelProperties::IsProgrammer) + else if (propertyname == IsProgrammerPropertyName) { if (IsProgrammer) { OnButtonPressed(NumbersAndOperatorsEnum::IsProgrammerMode); } } - else if (propertyname == CalculatorViewModelProperties::IsStandard) + else if (propertyname == IsStandardPropertyName) { if (IsStandard) { OnButtonPressed(NumbersAndOperatorsEnum::IsStandardMode); } } - else if (propertyname == CalculatorViewModelProperties::DisplayValue) + else if (propertyname == DisplayValuePropertyName) { - RaisePropertyChanged(CalculationResultAutomationName_PropertyName); + RaisePropertyChanged(CalculationResultAutomationNamePropertyName); Announcement = GetDisplayUpdatedNarratorAnnouncement(); } } diff --git a/src/CalcViewModel/StandardCalculatorViewModel.h b/src/CalcViewModel/StandardCalculatorViewModel.h index d7d3abd..ba6dc82 100644 --- a/src/CalcViewModel/StandardCalculatorViewModel.h +++ b/src/CalcViewModel/StandardCalculatorViewModel.h @@ -31,13 +31,6 @@ namespace CalculatorApp #define ASCII_0 48 public delegate void HideMemoryClickedHandler(); public delegate void ProgModeRadixChangeHandler(); - namespace CalculatorViewModelProperties - { - extern Platform::StringReference IsMemoryEmpty; - extern Platform::StringReference IsInError; - extern Platform::StringReference BinaryDisplayValue; - extern Platform::StringReference OpenParenthesisCount; - } [Windows::UI::Xaml::Data::Bindable] public ref class StandardCalculatorViewModel sealed : public Windows::UI::Xaml::Data::INotifyPropertyChanged @@ -52,14 +45,14 @@ namespace CalculatorApp OBSERVABLE_OBJECT_CALLBACK(OnPropertyChanged); OBSERVABLE_PROPERTY_RW(Platform::String^, DisplayValue); OBSERVABLE_PROPERTY_RW(HistoryViewModel^, HistoryVM); - OBSERVABLE_PROPERTY_RW(bool, IsInError); + OBSERVABLE_NAMED_PROPERTY_RW(bool, IsInError); OBSERVABLE_PROPERTY_RW(bool, IsOperatorCommand); OBSERVABLE_PROPERTY_RW(Platform::String^, DisplayStringExpression); OBSERVABLE_PROPERTY_RW(Windows::Foundation::Collections::IVector^, ExpressionTokens); OBSERVABLE_PROPERTY_RW(Platform::String^, DecimalDisplayValue); OBSERVABLE_PROPERTY_RW(Platform::String^, HexDisplayValue); OBSERVABLE_PROPERTY_RW(Platform::String^, OctalDisplayValue); - OBSERVABLE_PROPERTY_RW(Platform::String^, BinaryDisplayValue); + OBSERVABLE_NAMED_PROPERTY_RW(Platform::String^, BinaryDisplayValue); OBSERVABLE_PROPERTY_RW(Platform::String^, HexDisplayValue_AutomationName); OBSERVABLE_PROPERTY_RW(Platform::String^, DecDisplayValue_AutomationName); OBSERVABLE_PROPERTY_RW(Platform::String^, OctDisplayValue_AutomationName); @@ -70,19 +63,19 @@ namespace CalculatorApp OBSERVABLE_PROPERTY_RW(bool, IsDecimalEnabled); OBSERVABLE_PROPERTY_RW(bool, IsCurrentViewPinned); OBSERVABLE_PROPERTY_RW(Windows::Foundation::Collections::IVector^, MemorizedNumbers); - OBSERVABLE_PROPERTY_RW(bool, IsMemoryEmpty); + OBSERVABLE_NAMED_PROPERTY_RW(bool, IsMemoryEmpty); OBSERVABLE_PROPERTY_RW(bool, IsFToEChecked); OBSERVABLE_PROPERTY_RW(bool, IsFToEEnabled); OBSERVABLE_PROPERTY_RW(bool, IsHyperbolicChecked); OBSERVABLE_PROPERTY_RW(bool, AreHEXButtonsEnabled); - NAMED_OBSERVABLE_PROPERTY_RW(Platform::String^, CalculationResultAutomationName); - NAMED_OBSERVABLE_PROPERTY_RW(Platform::String^, CalculationExpressionAutomationName); + OBSERVABLE_PROPERTY_RW(Platform::String^, CalculationResultAutomationName); + OBSERVABLE_PROPERTY_RW(Platform::String^, CalculationExpressionAutomationName); OBSERVABLE_PROPERTY_RW(bool, IsShiftProgrammerChecked); OBSERVABLE_PROPERTY_RW(bool, IsQwordEnabled); OBSERVABLE_PROPERTY_RW(bool, IsDwordEnabled); OBSERVABLE_PROPERTY_RW(bool, IsWordEnabled); OBSERVABLE_PROPERTY_RW(bool, IsByteEnabled); - OBSERVABLE_PROPERTY_RW(Platform::String^, OpenParenthesisCount); + OBSERVABLE_NAMED_PROPERTY_RW(Platform::String^, OpenParenthesisCount); OBSERVABLE_PROPERTY_RW(int, CurrentRadixType); OBSERVABLE_PROPERTY_RW(bool, AreTokensUpdated); OBSERVABLE_PROPERTY_RW(bool, AreHistoryShortcutsEnabled); diff --git a/src/CalcViewModel/UnitConverterViewModel.cpp b/src/CalcViewModel/UnitConverterViewModel.cpp index 1cf478f..a04b584 100644 --- a/src/CalcViewModel/UnitConverterViewModel.cpp +++ b/src/CalcViewModel/UnitConverterViewModel.cpp @@ -56,47 +56,37 @@ constexpr unsigned int CONVERSION_FINALIZED_DELAY_IN_MS = 1000; const wregex regexTrimSpacesStart = wregex(L"^\\s+"); const wregex regexTrimSpacesEnd = wregex(L"\\s+$"); -namespace CalculatorApp::ViewModel +namespace { - namespace UnitConverterViewModelProperties - { - StringReference CurrentCategory(L"CurrentCategory"); - StringReference Unit1(L"Unit1"); - StringReference Unit2(L"Unit2"); - StringReference Value1Active(L"Value1Active"); - StringReference Value2Active(L"Value2Active"); - StringReference Value1(L"Value1"); - StringReference Value2(L"Value2"); - StringReference Value1AutomationName(L"Value1AutomationName"); - StringReference Value2AutomationName(L"Value2AutomationName"); - StringReference SupplementaryVisibility(L"SupplementaryVisibility"); - StringReference SupplementaryResults(L"SupplementaryResults"); - StringReference Unit1AutomationName(L"Unit1AutomationName"); - StringReference Unit2AutomationName(L"Unit2AutomationName"); - StringReference CurrencySymbol1(L"CurrencySymbol1"); - StringReference CurrencySymbol2(L"CurrencySymbol2"); - StringReference CurrencySymbolVisibility(L"CurrencySymbolVisibility"); - StringReference CurrencyRatioEquality(L"CurrencyRatioEquality"); - StringReference CurrencyRatioEqualityAutomationName(L"CurrencyRatioEqualityAutomationName"); - StringReference NetworkBehavior(L"NetworkBehavior"); - StringReference CurrencyDataLoadFailed(L"CurrencyDataLoadFailed"); - StringReference CurrencyDataIsWeekOld(L"CurrencyDataIsWeekOld"); - StringReference IsCurrencyLoadingVisible(L"IsCurrencyLoadingVisible"); - } + StringReference CurrentCategoryPropertyName(L"CurrentCategory"); + StringReference Unit1AutomationNamePropertyName(L"Unit1AutomationName"); + StringReference Unit2AutomationNamePropertyName(L"Unit2AutomationName"); + StringReference Unit1PropertyName(L"Unit1"); + StringReference Unit2PropertyName(L"Unit2"); + StringReference Value1PropertyName(L"Value1"); + StringReference Value2PropertyName(L"Value2"); + StringReference Value1ActivePropertyName(L"Value1Active"); + StringReference Value2ActivePropertyName(L"Value2Active"); + StringReference Value1AutomationNamePropertyName(L"Value1AutomationName"); + StringReference Value2AutomationNamePropertyName(L"Value2AutomationName"); + StringReference CurrencySymbol1PropertyName(L"CurrencySymbol1"); + StringReference CurrencySymbol2PropertyName(L"CurrencySymbol2"); + StringReference CurrencySymbolVisibilityPropertyName(L"CurrencySymbolVisibility"); + StringReference SupplementaryVisibilityPropertyName(L"SupplementaryVisibility"); +} - namespace UnitConverterResourceKeys - { - StringReference ValueFromFormat(L"Format_ValueFrom"); - StringReference ValueFromDecimalFormat(L"Format_ValueFrom_Decimal"); - StringReference ValueToFormat(L"Format_ValueTo"); - StringReference ConversionResultFormat(L"Format_ConversionResult"); - StringReference InputUnit_Name(L"InputUnit_Name"); - StringReference OutputUnit_Name(L"OutputUnit_Name"); - StringReference MaxDigitsReachedFormat(L"Format_MaxDigitsReached"); - StringReference UpdatingCurrencyRates(L"UpdatingCurrencyRates"); - StringReference CurrencyRatesUpdated(L"CurrencyRatesUpdated"); - StringReference CurrencyRatesUpdateFailed(L"CurrencyRatesUpdateFailed"); - } +namespace CalculatorApp::ViewModel::UnitConverterResourceKeys +{ + StringReference ValueFromFormat(L"Format_ValueFrom"); + StringReference ValueFromDecimalFormat(L"Format_ValueFrom_Decimal"); + StringReference ValueToFormat(L"Format_ValueTo"); + StringReference ConversionResultFormat(L"Format_ConversionResult"); + StringReference InputUnit_Name(L"InputUnit_Name"); + StringReference OutputUnit_Name(L"OutputUnit_Name"); + StringReference MaxDigitsReachedFormat(L"Format_MaxDigitsReached"); + StringReference UpdatingCurrencyRates(L"UpdatingCurrencyRates"); + StringReference CurrencyRatesUpdated(L"CurrencyRatesUpdated"); + StringReference CurrencyRatesUpdateFailed(L"CurrencyRatesUpdateFailed"); } UnitConverterViewModel::UnitConverterViewModel(const shared_ptr& model) : @@ -281,8 +271,8 @@ void UnitConverterViewModel::OnSwitchActive(Platform::Object^ unused) Utils::Swap(&m_localizedValueFromFormat, &m_localizedValueToFormat); Utils::Swap(&m_Unit1AutomationName, &m_Unit2AutomationName); - RaisePropertyChanged(UnitConverterViewModelProperties::Unit1AutomationName); - RaisePropertyChanged(UnitConverterViewModelProperties::Unit2AutomationName); + RaisePropertyChanged(Unit1AutomationNamePropertyName); + RaisePropertyChanged(Unit2AutomationNamePropertyName); m_isInputBlocked = false; m_model->SwitchActive(m_valueFromUnlocalized); @@ -561,13 +551,13 @@ void UnitConverterViewModel::OnPropertyChanged(Platform::String^ prop) { static bool isCategoryChanging = false; - if (prop->Equals(UnitConverterViewModelProperties::CurrentCategory)) + if (prop == CurrentCategoryPropertyName) { isCategoryChanging = true; CategoryChanged->Execute(nullptr); isCategoryChanging = false; } - else if (prop->Equals(UnitConverterViewModelProperties::Unit1) || prop->Equals(UnitConverterViewModelProperties::Unit2)) + else if (prop == Unit1PropertyName || prop == Unit2PropertyName) { // Category changes will handle updating units after they've both been updated. // This event should only be used to update units from explicit user interaction. @@ -576,7 +566,7 @@ void UnitConverterViewModel::OnPropertyChanged(Platform::String^ prop) UnitChanged->Execute(nullptr); } // Get the localized automation name for each CalculationResults field - if (prop->Equals(UnitConverterViewModelProperties::Unit1)) + if (prop == Unit1PropertyName) { UpdateValue1AutomationName(); } @@ -585,15 +575,15 @@ void UnitConverterViewModel::OnPropertyChanged(Platform::String^ prop) UpdateValue2AutomationName(); } } - else if (prop->Equals(UnitConverterViewModelProperties::Value1)) + else if (prop == Value1PropertyName) { UpdateValue1AutomationName(); } - else if (prop->Equals(UnitConverterViewModelProperties::Value2)) + else if (prop == Value2PropertyName) { UpdateValue2AutomationName(); } - else if (prop->Equals(UnitConverterViewModelProperties::Value1Active) || prop->Equals(UnitConverterViewModelProperties::Value2Active)) + else if (prop == Value1ActivePropertyName || prop == Value2ActivePropertyName) { // if one of the values is activated, and as a result both are true, it means // that we're trying to switch. @@ -605,11 +595,11 @@ void UnitConverterViewModel::OnPropertyChanged(Platform::String^ prop) UpdateValue1AutomationName(); UpdateValue2AutomationName(); } - else if (prop->Equals(UnitConverterViewModelProperties::SupplementaryResults)) + else if (prop == SupplementaryResultsPropertyName) { - RaisePropertyChanged(UnitConverterViewModelProperties::SupplementaryVisibility); + RaisePropertyChanged(SupplementaryVisibilityPropertyName); } - else if (prop->Equals(UnitConverterViewModelProperties::Value1AutomationName)) + else if (prop == Value1AutomationNamePropertyName) { m_isValue1Updating = false; if (!m_isValue2Updating) @@ -617,7 +607,7 @@ void UnitConverterViewModel::OnPropertyChanged(Platform::String^ prop) AnnounceConversionResult(); } } - else if (prop->Equals(UnitConverterViewModelProperties::Value2AutomationName)) + else if (prop == Value2AutomationNamePropertyName) { m_isValue2Updating = false; if (!m_isValue1Updating) @@ -625,9 +615,9 @@ void UnitConverterViewModel::OnPropertyChanged(Platform::String^ prop) AnnounceConversionResult(); } } - else if (prop->Equals(UnitConverterViewModelProperties::CurrencySymbol1) || prop->Equals(UnitConverterViewModelProperties::CurrencySymbol2)) + else if (prop == CurrencySymbol1PropertyName || prop == CurrencySymbol2PropertyName) { - RaisePropertyChanged(UnitConverterViewModelProperties::CurrencySymbolVisibility); + RaisePropertyChanged(CurrencySymbolVisibilityPropertyName); } } @@ -852,7 +842,7 @@ void UnitConverterViewModel::RefreshSupplementaryResults() } m_cacheMutex.unlock(); - RaisePropertyChanged(UnitConverterViewModelProperties::SupplementaryResults); + RaisePropertyChanged(SupplementaryResultsPropertyName); //EventWriteConverterSupplementaryResultsUpdated(); } diff --git a/src/CalcViewModel/UnitConverterViewModel.h b/src/CalcViewModel/UnitConverterViewModel.h index bd7b8bd..5a98238 100644 --- a/src/CalcViewModel/UnitConverterViewModel.h +++ b/src/CalcViewModel/UnitConverterViewModel.h @@ -138,25 +138,6 @@ namespace CalculatorApp return ref new Activatable(activatable); } - namespace UnitConverterViewModelProperties - { - extern Platform::StringReference CurrentCategory; - extern Platform::StringReference Unit1; - extern Platform::StringReference Unit2; - extern Platform::StringReference Value1Active; - extern Platform::StringReference Value2Active; - extern Platform::StringReference SupplementaryVisibility; - extern Platform::StringReference SupplementaryResults; - extern Platform::StringReference CurrencySymbol1; - extern Platform::StringReference CurrencySymbol2; - extern Platform::StringReference CurrencySymbolVisibility; - extern Platform::StringReference CurrencyRatioEquality; - extern Platform::StringReference NetworkBehavior; - extern Platform::StringReference CurrencyDataLoadFailed; - extern Platform::StringReference CurrencyDataIsWeekOld; - extern Platform::StringReference IsCurrencyLoadingVisible; - } - [Windows::UI::Xaml::Data::Bindable] public ref class UnitConverterViewModel sealed : public Windows::UI::Xaml::Data::INotifyPropertyChanged { @@ -176,7 +157,7 @@ namespace CalculatorApp OBSERVABLE_PROPERTY_RW(Platform::String^, CurrencySymbol2); OBSERVABLE_PROPERTY_RW(Unit^, Unit2); OBSERVABLE_PROPERTY_RW(Platform::String^, Value2); - OBSERVABLE_PROPERTY_R(Windows::Foundation::Collections::IObservableVector^, SupplementaryResults); + OBSERVABLE_NAMED_PROPERTY_R(Windows::Foundation::Collections::IObservableVector^, SupplementaryResults); OBSERVABLE_PROPERTY_RW(bool, Value1Active); OBSERVABLE_PROPERTY_RW(bool, Value2Active); OBSERVABLE_PROPERTY_RW(Platform::String^, Value1AutomationName); @@ -187,14 +168,14 @@ namespace CalculatorApp OBSERVABLE_PROPERTY_RW(bool, IsDecimalEnabled); OBSERVABLE_PROPERTY_RW(bool, IsDropDownOpen); OBSERVABLE_PROPERTY_RW(bool, IsDropDownEnabled); - OBSERVABLE_PROPERTY_RW(bool, IsCurrencyLoadingVisible); + OBSERVABLE_NAMED_PROPERTY_RW(bool, IsCurrencyLoadingVisible); OBSERVABLE_PROPERTY_RW(bool, IsCurrencyCurrentCategory); OBSERVABLE_PROPERTY_RW(Platform::String^, CurrencyRatioEquality); OBSERVABLE_PROPERTY_RW(Platform::String^, CurrencyRatioEqualityAutomationName); OBSERVABLE_PROPERTY_RW(Platform::String^, CurrencyTimestamp); - OBSERVABLE_PROPERTY_RW(CalculatorApp::NetworkAccessBehavior, NetworkBehavior); - OBSERVABLE_PROPERTY_RW(bool, CurrencyDataLoadFailed); - OBSERVABLE_PROPERTY_RW(bool, CurrencyDataIsWeekOld); + OBSERVABLE_NAMED_PROPERTY_RW(CalculatorApp::NetworkAccessBehavior, NetworkBehavior); + OBSERVABLE_NAMED_PROPERTY_RW(bool, CurrencyDataLoadFailed); + OBSERVABLE_NAMED_PROPERTY_RW(bool, CurrencyDataIsWeekOld); property Windows::UI::Xaml::Visibility SupplementaryVisibility { diff --git a/src/Calculator/Views/Calculator.xaml.cpp b/src/Calculator/Views/Calculator.xaml.cpp index 65b3f45..fa08ba5 100644 --- a/src/Calculator/Views/Calculator.xaml.cpp +++ b/src/Calculator/Views/Calculator.xaml.cpp @@ -389,11 +389,11 @@ void Calculator::EnsureProgrammer() void Calculator::OnCalcPropertyChanged(_In_ Object^ sender, _In_ PropertyChangedEventArgs^ e) { String^ prop = e->PropertyName; - if (e->PropertyName->Equals(CalculatorViewModelProperties::IsMemoryEmpty)) + if (prop == StandardCalculatorViewModel::IsMemoryEmptyPropertyName) { UpdateMemoryState(); } - else if (e->PropertyName->Equals(CalculatorViewModelProperties::IsInError)) + else if (prop == StandardCalculatorViewModel::IsInErrorPropertyName) { OnIsInErrorPropertyChanged(); } diff --git a/src/Calculator/Views/CalculatorProgrammerBitFlipPanel.xaml.cpp b/src/Calculator/Views/CalculatorProgrammerBitFlipPanel.xaml.cpp index 3225e01..3aed275 100644 --- a/src/Calculator/Views/CalculatorProgrammerBitFlipPanel.xaml.cpp +++ b/src/Calculator/Views/CalculatorProgrammerBitFlipPanel.xaml.cpp @@ -68,7 +68,7 @@ void CalculatorProgrammerBitFlipPanel::UnsubscribePropertyChanged() void CalculatorProgrammerBitFlipPanel::OnPropertyChanged(Object^ sender, PropertyChangedEventArgs^ e) { - if (e->PropertyName == CalculatorViewModelProperties::BinaryDisplayValue) + if (e->PropertyName == StandardCalculatorViewModel::BinaryDisplayValuePropertyName) { UpdateCheckedStates(); } diff --git a/src/Calculator/Views/CalculatorProgrammerRadixOperators.xaml.cpp b/src/Calculator/Views/CalculatorProgrammerRadixOperators.xaml.cpp index 85215dd..5ef6014 100644 --- a/src/Calculator/Views/CalculatorProgrammerRadixOperators.xaml.cpp +++ b/src/Calculator/Views/CalculatorProgrammerRadixOperators.xaml.cpp @@ -102,7 +102,7 @@ void CalculatorProgrammerRadixOperators::IsErrorVisualState::set(bool value) void CalculatorProgrammerRadixOperators::OnViewModelPropertyChanged(Object^ sender, PropertyChangedEventArgs^ e) { - if (e->PropertyName == CalculatorViewModelProperties::OpenParenthesisCount && closeParenthesisButton->FocusState != ::FocusState::Unfocused) + if (e->PropertyName == StandardCalculatorViewModel::OpenParenthesisCountPropertyName && closeParenthesisButton->FocusState != ::FocusState::Unfocused) { Model->SetOpenParenthesisCountNarratorAnnouncement(); } diff --git a/src/Calculator/Views/CalculatorScientificOperators.xaml.cpp b/src/Calculator/Views/CalculatorScientificOperators.xaml.cpp index fa7832f..ee31a1a 100644 --- a/src/Calculator/Views/CalculatorScientificOperators.xaml.cpp +++ b/src/Calculator/Views/CalculatorScientificOperators.xaml.cpp @@ -109,7 +109,7 @@ void CalculatorScientificOperators::SetOperatorRowVisibility() void CalculatorScientificOperators::OnViewModelPropertyChanged(Object^ sender, PropertyChangedEventArgs^ e) { - if (e->PropertyName == CalculatorViewModelProperties::OpenParenthesisCount && closeParenthesisButton->FocusState != ::FocusState::Unfocused) + if (e->PropertyName == StandardCalculatorViewModel::OpenParenthesisCountPropertyName && closeParenthesisButton->FocusState != ::FocusState::Unfocused) { Model->SetOpenParenthesisCountNarratorAnnouncement(); } diff --git a/src/Calculator/Views/MainPage.xaml.cpp b/src/Calculator/Views/MainPage.xaml.cpp index 1b7541c..14c406a 100644 --- a/src/Calculator/Views/MainPage.xaml.cpp +++ b/src/Calculator/Views/MainPage.xaml.cpp @@ -105,9 +105,9 @@ void MainPage::OnNavigatedTo(NavigationEventArgs^ e) else { ApplicationDataContainer^ localSettings = ApplicationData::Current->LocalSettings; - if (localSettings->Values->HasKey(ApplicationViewModelProperties::Mode)) + if (localSettings->Values->HasKey(ApplicationViewModel::ModePropertyName)) { - initialMode = NavCategory::Deserialize(localSettings->Values->Lookup(ApplicationViewModelProperties::Mode)); + initialMode = NavCategory::Deserialize(localSettings->Values->Lookup(ApplicationViewModel::ModePropertyName)); } } @@ -122,7 +122,8 @@ void MainPage::WindowSizeChanged(_In_ Platform::Object^ /*sender*/, _In_ Windows void MainPage::OnAppPropertyChanged(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::Data::PropertyChangedEventArgs^ e) { - if (e->PropertyName->Equals(ApplicationViewModelProperties::Mode)) + String^ propertyName = e->PropertyName; + if (propertyName == ApplicationViewModel::ModePropertyName) { ViewMode newValue = m_model->Mode; ViewMode previousMode = m_model->PreviousMode; @@ -186,7 +187,7 @@ void MainPage::OnAppPropertyChanged(_In_ Platform::Object^ sender, _In_ Windows: SetTitleBarControlColors(); SetDefaultFocus(); } - else if (e->PropertyName->Equals(ApplicationViewModelProperties::CategoryName)) + else if (propertyName == ApplicationViewModel::CategoryNamePropertyName) { SetHeaderAutomationName(); AnnounceCategoryName(); diff --git a/src/Calculator/Views/SupplementaryResults.xaml.cpp b/src/Calculator/Views/SupplementaryResults.xaml.cpp index d598ae9..978df9a 100644 --- a/src/Calculator/Views/SupplementaryResults.xaml.cpp +++ b/src/Calculator/Views/SupplementaryResults.xaml.cpp @@ -95,7 +95,7 @@ void SupplementaryResults::OnLoaded(Object^ sender, RoutedEventArgs^ e) void SupplementaryResults::OnConverterPropertyChanged(Object^ /*sender*/, PropertyChangedEventArgs^ e) { - if (e->PropertyName == UnitConverterViewModelProperties::SupplementaryResults) + if (e->PropertyName == UnitConverterViewModel::SupplementaryResultsPropertyName) { RefreshData(); } diff --git a/src/Calculator/Views/UnitConverter.xaml.cpp b/src/Calculator/Views/UnitConverter.xaml.cpp index 85a52ea..cb10718 100644 --- a/src/Calculator/Views/UnitConverter.xaml.cpp +++ b/src/Calculator/Views/UnitConverter.xaml.cpp @@ -82,16 +82,16 @@ UnitConverter::UnitConverter() : void UnitConverter::OnPropertyChanged(_In_ Object^ sender, _In_ PropertyChangedEventArgs^ e) { String^ propertyName = e->PropertyName; - if (propertyName->Equals(UnitConverterViewModelProperties::NetworkBehavior) || - propertyName->Equals(UnitConverterViewModelProperties::CurrencyDataLoadFailed)) + if (propertyName == UnitConverterViewModel::NetworkBehaviorPropertyName || + propertyName == UnitConverterViewModel::CurrencyDataLoadFailedPropertyName) { OnNetworkBehaviorChanged(); } - else if (propertyName->Equals(UnitConverterViewModelProperties::CurrencyDataIsWeekOld)) + else if (propertyName == UnitConverterViewModel::CurrencyDataIsWeekOldPropertyName) { SetCurrencyTimestampFontWeight(); } - else if (propertyName->Equals(UnitConverterViewModelProperties::IsCurrencyLoadingVisible)) + else if (propertyName == UnitConverterViewModel::IsCurrencyLoadingVisiblePropertyName) { OnIsDisplayVisibleChanged(); }