Replace wstring used in public methods by Platform::String in CalcViewModel (#768)
This commit is contained in:
@@ -35,11 +35,11 @@ AboutFlyout::AboutFlyout()
|
||||
|
||||
this->SetVersionString();
|
||||
|
||||
Header->Text = resourceLoader.GetResourceString("AboutButton/Content");
|
||||
Header->Text = resourceLoader->GetResourceString("AboutButton/Content");
|
||||
|
||||
auto copyrightText =
|
||||
LocalizationStringUtil::GetLocalizedString(resourceLoader.GetResourceString("AboutControlCopyright")->Data(), to_wstring(BUILD_YEAR).c_str());
|
||||
AboutControlCopyrightRun->Text = ref new String(copyrightText.c_str());
|
||||
LocalizationStringUtil::GetLocalizedString(resourceLoader->GetResourceString("AboutControlCopyright"), StringReference(to_wstring(BUILD_YEAR).c_str()));
|
||||
AboutControlCopyrightRun->Text = copyrightText;
|
||||
}
|
||||
|
||||
void AboutFlyout::FeedbackButton_Click(_In_ Object ^ sender, _In_ RoutedEventArgs ^ e)
|
||||
@@ -53,7 +53,7 @@ void AboutFlyout::FeedbackButton_Click(_In_ Object ^ sender, _In_ RoutedEventArg
|
||||
void AboutFlyout::SetVersionString()
|
||||
{
|
||||
PackageVersion version = Package::Current->Id->Version;
|
||||
String ^ appName = AppResourceProvider::GetInstance().GetResourceString(L"AppName");
|
||||
String ^ appName = AppResourceProvider::GetInstance()->GetResourceString(L"AppName");
|
||||
AboutFlyoutVersion->Text = appName + L" " + version.Major + L"." + version.Minor + L"." + version.Build + L"." + version.Revision;
|
||||
}
|
||||
|
||||
|
@@ -63,11 +63,7 @@ CalculationResult::CalculationResult()
|
||||
|
||||
Platform::String ^ CalculationResult::GetRawDisplayValue()
|
||||
{
|
||||
std::wstring rawValue;
|
||||
|
||||
LocalizationSettings::GetInstance().RemoveGroupSeparators(DisplayValue->Data(), DisplayValue->Length(), &rawValue);
|
||||
|
||||
return ref new Platform::String(rawValue.c_str());
|
||||
return LocalizationSettings::GetInstance().RemoveGroupSeparators(DisplayValue);
|
||||
}
|
||||
|
||||
void CalculationResult::OnApplyTemplate()
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#include "pch.h"
|
||||
@@ -18,8 +18,6 @@ using namespace Windows::UI::Xaml::Data;
|
||||
|
||||
String ^ RadixButton::GetRawDisplayValue()
|
||||
{
|
||||
wstring rawValue;
|
||||
String ^ radixContent = Content->ToString();
|
||||
LocalizationSettings::GetInstance().RemoveGroupSeparators(radixContent->Data(), radixContent->Length(), &rawValue);
|
||||
return ref new String(rawValue.c_str());
|
||||
return LocalizationSettings::GetInstance().RemoveGroupSeparators(radixContent);
|
||||
}
|
||||
|
@@ -28,22 +28,22 @@ namespace CalculatorApp
|
||||
{
|
||||
case RADIX_TYPE::BIN_RADIX:
|
||||
{
|
||||
convertedValue = resourceLoader.GetResourceString("Bin");
|
||||
convertedValue = resourceLoader->GetResourceString("Bin");
|
||||
break;
|
||||
}
|
||||
case RADIX_TYPE::OCT_RADIX:
|
||||
{
|
||||
convertedValue = resourceLoader.GetResourceString("Oct");
|
||||
convertedValue = resourceLoader->GetResourceString("Oct");
|
||||
break;
|
||||
}
|
||||
case RADIX_TYPE::DEC_RADIX:
|
||||
{
|
||||
convertedValue = resourceLoader.GetResourceString("Dec");
|
||||
convertedValue = resourceLoader->GetResourceString("Dec");
|
||||
break;
|
||||
}
|
||||
case RADIX_TYPE::HEX_RADIX:
|
||||
{
|
||||
convertedValue = resourceLoader.GetResourceString("Hex");
|
||||
convertedValue = resourceLoader->GetResourceString("Hex");
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@@ -59,8 +59,8 @@ Calculator::Calculator()
|
||||
|
||||
m_displayFlyout = static_cast<MenuFlyout ^>(Resources->Lookup(L"DisplayContextMenu"));
|
||||
auto resLoader = AppResourceProvider::GetInstance();
|
||||
CopyMenuItem->Text = resLoader.GetResourceString(L"copyMenuItem");
|
||||
PasteMenuItem->Text = resLoader.GetResourceString(L"pasteMenuItem");
|
||||
CopyMenuItem->Text = resLoader->GetResourceString(L"copyMenuItem");
|
||||
PasteMenuItem->Text = resLoader->GetResourceString(L"pasteMenuItem");
|
||||
|
||||
this->SizeChanged += ref new SizeChangedEventHandler(this, &Calculator::Calculator_SizeChanged);
|
||||
}
|
||||
@@ -68,10 +68,10 @@ Calculator::Calculator()
|
||||
void Calculator::LoadResourceStrings()
|
||||
{
|
||||
auto resProvider = AppResourceProvider::GetInstance();
|
||||
m_openMemoryFlyoutAutomationName = resProvider.GetResourceString(L"MemoryButton_Open");
|
||||
m_closeMemoryFlyoutAutomationName = resProvider.GetResourceString(L"MemoryButton_Close");
|
||||
m_openHistoryFlyoutAutomationName = resProvider.GetResourceString(L"HistoryButton_Open");
|
||||
m_closeHistoryFlyoutAutomationName = resProvider.GetResourceString(L"HistoryButton_Close");
|
||||
m_openMemoryFlyoutAutomationName = resProvider->GetResourceString(L"MemoryButton_Open");
|
||||
m_closeMemoryFlyoutAutomationName = resProvider->GetResourceString(L"MemoryButton_Close");
|
||||
m_openHistoryFlyoutAutomationName = resProvider->GetResourceString(L"HistoryButton_Open");
|
||||
m_closeHistoryFlyoutAutomationName = resProvider->GetResourceString(L"HistoryButton_Close");
|
||||
AutomationProperties::SetName(MemoryButton, m_openMemoryFlyoutAutomationName);
|
||||
AutomationProperties::SetName(HistoryButton, m_openHistoryFlyoutAutomationName);
|
||||
}
|
||||
@@ -123,9 +123,9 @@ void Calculator::OnLoaded(_In_ Object ^, _In_ RoutedEventArgs ^)
|
||||
Model->HideMemoryClicked += ref new HideMemoryClickedHandler(this, &Calculator::OnHideMemoryClicked);
|
||||
|
||||
InitializeHistoryView(Model->HistoryVM);
|
||||
String ^ historyPaneName = AppResourceProvider::GetInstance().GetResourceString(L"HistoryPane");
|
||||
String ^ historyPaneName = AppResourceProvider::GetInstance()->GetResourceString(L"HistoryPane");
|
||||
HistoryFlyout->FlyoutPresenterStyle->Setters->Append(ref new Setter(AutomationProperties::NameProperty, historyPaneName));
|
||||
String ^ memoryPaneName = AppResourceProvider::GetInstance().GetResourceString(L"MemoryPane");
|
||||
String ^ memoryPaneName = AppResourceProvider::GetInstance()->GetResourceString(L"MemoryPane");
|
||||
MemoryFlyout->FlyoutPresenterStyle->Setters->Append(ref new Setter(AutomationProperties::NameProperty, memoryPaneName));
|
||||
|
||||
if (Windows::Foundation::Metadata::ApiInformation::IsEventPresent(L"Windows.UI.Xaml.Controls.Primitives.FlyoutBase", L"Closing"))
|
||||
@@ -149,24 +149,21 @@ void Calculator::OnLoaded(_In_ Object ^, _In_ RoutedEventArgs ^)
|
||||
}));
|
||||
}
|
||||
|
||||
std::wstring Calculator::GetCurrentLayoutState()
|
||||
Platform::String ^ Calculator::GetCurrentLayoutState()
|
||||
{
|
||||
std::wstring state;
|
||||
|
||||
if (IsProgrammer)
|
||||
{
|
||||
state = L"Programmer";
|
||||
return L"Programmer";
|
||||
}
|
||||
else if (IsScientific)
|
||||
{
|
||||
state = L"Scientific";
|
||||
return L"Scientific";
|
||||
}
|
||||
else
|
||||
{
|
||||
state = L"Standard";
|
||||
return L"Standard";
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
void Calculator::UpdateViewState()
|
||||
@@ -479,7 +476,7 @@ void Calculator::OnHistoryItemClicked(_In_ HistoryItemViewModel ^ e)
|
||||
assert(e->GetTokens() != nullptr);
|
||||
Model->SetHistoryExpressionDisplay(e->GetTokens(), e->GetCommands());
|
||||
Model->SetExpressionDisplay(e->GetTokens(), e->GetCommands());
|
||||
Model->SetPrimaryDisplay(e->Result->Data(), false);
|
||||
Model->SetPrimaryDisplay(e->Result, false);
|
||||
Model->IsFToEEnabled = false;
|
||||
|
||||
CloseHistoryFlyout();
|
||||
@@ -616,7 +613,7 @@ Memory ^ Calculator::GetMemory()
|
||||
if (m_memory == nullptr)
|
||||
{
|
||||
m_memory = ref new Memory();
|
||||
VisualStateManager::GoToState(m_memory, ref new String(GetCurrentLayoutState().c_str()), true /*useTransitions*/);
|
||||
VisualStateManager::GoToState(m_memory, GetCurrentLayoutState(), true /*useTransitions*/);
|
||||
}
|
||||
|
||||
return m_memory;
|
||||
@@ -672,28 +669,6 @@ void Calculator::OnHistoryFlyOutTapped(_In_ Object ^ sender, _In_ TappedRoutedEv
|
||||
}
|
||||
}
|
||||
|
||||
bool Calculator::IsValidRegularExpression(std::wstring str)
|
||||
{
|
||||
bool result = false;
|
||||
std::wregex regexPatterns[3];
|
||||
regexPatterns[0] = L"[-]{0,1}[0-9]{0,}[.]{0,1}[0-9]{0,}";
|
||||
regexPatterns[1] = L"[-]{0,1}[0-9]{0,}[.]{0,1}[0-9]{0,}[e]{1}[+]{1}[0-9]{1,}";
|
||||
regexPatterns[2] = L"[-]{0,1}[0-9]{0,}[.]{0,1}[0-9]{0,}[e]{1}[-]{1}[0-9]{1,}";
|
||||
|
||||
const auto& localizer = LocalizationSettings::GetInstance();
|
||||
String ^ englishString = localizer.GetEnglishValueFromLocalizedDigits(str);
|
||||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
if (regex_match(englishString->Data(), regexPatterns[i]))
|
||||
{
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void Calculator::DockPanelTapped(_In_ TappedRoutedEventArgs ^ e)
|
||||
{
|
||||
int index = DockPivot->SelectedIndex;
|
||||
|
@@ -94,7 +94,7 @@ public
|
||||
void EnsureScientific();
|
||||
void EnsureProgrammer();
|
||||
void SetFontSizeResources();
|
||||
std::wstring GetCurrentLayoutState();
|
||||
Platform::String ^ GetCurrentLayoutState();
|
||||
void Calculator_SizeChanged(Object ^ sender, Windows::UI::Xaml::SizeChangedEventArgs ^ e);
|
||||
|
||||
private:
|
||||
@@ -140,7 +140,6 @@ public
|
||||
void EnableMemoryControls(bool enable);
|
||||
void OnMemoryFlyOutTapped(_In_ Platform::Object ^ sender, _In_ Windows::UI::Xaml::Input::TappedRoutedEventArgs ^ e);
|
||||
void OnHistoryFlyOutTapped(_In_ Platform::Object ^ sender, _In_ Windows::UI::Xaml::Input::TappedRoutedEventArgs ^ e);
|
||||
bool IsValidRegularExpression(std::wstring str);
|
||||
void DockPanelTapped(_In_ Windows::UI::Xaml::Input::TappedRoutedEventArgs ^ e);
|
||||
void OnHistoryAccessKeyInvoked(_In_ Windows::UI::Xaml::UIElement ^ sender, _In_ Windows::UI::Xaml::Input::AccessKeyInvokedEventArgs ^ args);
|
||||
void OnMemoryAccessKeyInvoked(_In_ Windows::UI::Xaml::UIElement ^ sender, _In_ Windows::UI::Xaml::Input::AccessKeyInvokedEventArgs ^ args);
|
||||
|
@@ -247,11 +247,11 @@ int CalculatorProgrammerBitFlipPanel::GetIndexOfLastBit(BitLength length) const
|
||||
String ^ CalculatorProgrammerBitFlipPanel::GenerateAutomationPropertiesName(int position, bool value)
|
||||
{
|
||||
auto resourceLoader = AppResourceProvider::GetInstance();
|
||||
String ^ automationNameTemplate = resourceLoader.GetResourceString(L"BitFlipItemAutomationName");
|
||||
wstring bitPosition;
|
||||
String ^ automationNameTemplate = resourceLoader->GetResourceString(L"BitFlipItemAutomationName");
|
||||
String ^ bitPosition;
|
||||
if (position == 0)
|
||||
{
|
||||
bitPosition = wstring(resourceLoader.GetResourceString(L"LeastSignificantBit")->Data());
|
||||
bitPosition = resourceLoader->GetResourceString(L"LeastSignificantBit");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -263,14 +263,14 @@ String ^ CalculatorProgrammerBitFlipPanel::GenerateAutomationPropertiesName(int
|
||||
|
||||
if (position == lastPosition)
|
||||
{
|
||||
bitPosition = wstring(resourceLoader.GetResourceString(L"MostSignificantBit")->Data());
|
||||
bitPosition = resourceLoader->GetResourceString(L"MostSignificantBit");
|
||||
}
|
||||
else
|
||||
{
|
||||
String ^ indexName = resourceLoader.GetResourceString(ref new Platform::String(to_wstring(position).c_str()));
|
||||
String ^ bitPositionTemplate = resourceLoader.GetResourceString(L"BitPosition");
|
||||
bitPosition = LocalizationStringUtil::GetLocalizedString(bitPositionTemplate->Data(), indexName->Data());
|
||||
String ^ indexName = resourceLoader->GetResourceString(ref new Platform::String(to_wstring(position).c_str()));
|
||||
String ^ bitPositionTemplate = resourceLoader->GetResourceString(L"BitPosition");
|
||||
bitPosition = LocalizationStringUtil::GetLocalizedString(bitPositionTemplate, indexName);
|
||||
}
|
||||
}
|
||||
return ref new String(LocalizationStringUtil::GetLocalizedString(automationNameTemplate->Data(), bitPosition.c_str(), value ? L"1" : L"0").c_str());
|
||||
return LocalizationStringUtil::GetLocalizedString(automationNameTemplate, bitPosition, value ? L"1" : L"0");
|
||||
}
|
||||
|
@@ -33,7 +33,7 @@ CalculatorProgrammerOperators::CalculatorProgrammerOperators()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
CopyMenuItem->Text = AppResourceProvider::GetInstance().GetResourceString(L"copyMenuItem");
|
||||
CopyMenuItem->Text = AppResourceProvider::GetInstance()->GetResourceString(L"copyMenuItem");
|
||||
}
|
||||
|
||||
void CalculatorProgrammerOperators::HexButtonChecked(_In_ Object ^ sender, _In_ RoutedEventArgs ^ e)
|
||||
|
@@ -92,7 +92,7 @@ DateCalculator::DateCalculator()
|
||||
DateDiff_FromDate->PlaceholderText = placeholderText;
|
||||
DateDiff_ToDate->PlaceholderText = placeholderText;
|
||||
|
||||
CopyMenuItem->Text = AppResourceProvider::GetInstance().GetResourceString(L"copyMenuItem");
|
||||
CopyMenuItem->Text = AppResourceProvider::GetInstance()->GetResourceString(L"copyMenuItem");
|
||||
m_dateCalcOptionChangedEventToken = DateCalculationOption->SelectionChanged +=
|
||||
ref new SelectionChangedEventHandler(this, &DateCalculator::DateCalcOption_Changed);
|
||||
}
|
||||
|
@@ -10,6 +10,7 @@
|
||||
#include "CalcViewModel/Common/AppResourceProvider.h"
|
||||
#include "Views/Memory.xaml.h"
|
||||
#include "Converters/BooleanToVisibilityConverter.h"
|
||||
#include "CalcViewModel/Common/LocalizationStringUtil.h"
|
||||
#include "Common/AppLifecycleLogger.h"
|
||||
using namespace CalculatorApp;
|
||||
using namespace CalculatorApp::Common;
|
||||
@@ -510,25 +511,20 @@ void MainPage::SetHeaderAutomationName()
|
||||
String ^ name;
|
||||
if (NavCategory::IsDateCalculatorViewMode(mode))
|
||||
{
|
||||
name = resProvider.GetResourceString(L"HeaderAutomationName_Date");
|
||||
name = resProvider->GetResourceString(L"HeaderAutomationName_Date");
|
||||
}
|
||||
else
|
||||
{
|
||||
wstring full;
|
||||
String ^ full;
|
||||
if (NavCategory::IsCalculatorViewMode(mode))
|
||||
{
|
||||
full = resProvider.GetResourceString(L"HeaderAutomationName_Calculator")->Data();
|
||||
full = resProvider->GetResourceString(L"HeaderAutomationName_Calculator");
|
||||
}
|
||||
else if (NavCategory::IsConverterViewMode(mode))
|
||||
{
|
||||
full = resProvider.GetResourceString(L"HeaderAutomationName_Converter")->Data();
|
||||
full = resProvider->GetResourceString(L"HeaderAutomationName_Converter");
|
||||
}
|
||||
|
||||
string::size_type found = full.find(L"%1");
|
||||
wstring strMode = m_model->CategoryName->Data();
|
||||
full = full.replace(found, 2, strMode);
|
||||
|
||||
name = ref new String(full.c_str());
|
||||
name = LocalizationStringUtil::GetLocalizedString(full, m_model->CategoryName);
|
||||
}
|
||||
|
||||
AutomationProperties::SetName(Header, name);
|
||||
|
@@ -37,9 +37,9 @@ namespace CalculatorApp
|
||||
Loaded += ref new RoutedEventHandler(this, &TitleBar::OnLoaded);
|
||||
Unloaded += ref new RoutedEventHandler(this, &TitleBar::OnUnloaded);
|
||||
#ifdef IS_STORE_BUILD
|
||||
AppName->Text = AppResourceProvider::GetInstance().GetResourceString(L"AppName");
|
||||
AppName->Text = AppResourceProvider::GetInstance()->GetResourceString(L"AppName");
|
||||
#else
|
||||
AppName->Text = AppResourceProvider::GetInstance().GetResourceString(L"DevAppName");
|
||||
AppName->Text = AppResourceProvider::GetInstance()->GetResourceString(L"DevAppName");
|
||||
#endif // IS_STORE_BUILD
|
||||
}
|
||||
|
||||
|
@@ -40,8 +40,6 @@ using namespace Windows::UI::Xaml::Media;
|
||||
using namespace Windows::UI::Xaml::Navigation;
|
||||
using namespace Windows::UI::ViewManagement;
|
||||
|
||||
// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236
|
||||
|
||||
// Calculate number of 100-nanosecond intervals in 500 milliseconds.
|
||||
// There are 10,000 intervals in 1 ms.
|
||||
static const long long DURATION_500_MS = 10000 * 500;
|
||||
@@ -66,14 +64,14 @@ UnitConverter::UnitConverter()
|
||||
m_isAnimationEnabled = userSettings->AnimationsEnabled;
|
||||
|
||||
auto resLoader = AppResourceProvider::GetInstance();
|
||||
m_chargesMayApplyText = resLoader.GetResourceString(L"DataChargesMayApply");
|
||||
m_failedToRefreshText = resLoader.GetResourceString(L"FailedToRefresh");
|
||||
m_chargesMayApplyText = resLoader->GetResourceString(L"DataChargesMayApply");
|
||||
m_failedToRefreshText = resLoader->GetResourceString(L"FailedToRefresh");
|
||||
|
||||
InitializeOfflineStatusTextBlock();
|
||||
|
||||
m_resultsFlyout = static_cast<MenuFlyout ^>(Resources->Lookup(L"CalculationResultContextMenu"));
|
||||
CopyMenuItem->Text = resLoader.GetResourceString(L"copyMenuItem");
|
||||
PasteMenuItem->Text = resLoader.GetResourceString(L"pasteMenuItem");
|
||||
CopyMenuItem->Text = resLoader->GetResourceString(L"copyMenuItem");
|
||||
PasteMenuItem->Text = resLoader->GetResourceString(L"pasteMenuItem");
|
||||
}
|
||||
|
||||
void UnitConverter::OnPropertyChanged(_In_ Object ^ sender, _In_ PropertyChangedEventArgs ^ e)
|
||||
@@ -165,7 +163,7 @@ void UnitConverter::SetFailedToRefreshStatus()
|
||||
void UnitConverter::InitializeOfflineStatusTextBlock()
|
||||
{
|
||||
auto resProvider = AppResourceProvider::GetInstance();
|
||||
std::wstring offlineStatusHyperlinkText = static_cast<String ^>(resProvider.GetResourceString(L"OfflineStatusHyperlinkText"))->Data();
|
||||
std::wstring offlineStatusHyperlinkText = resProvider->GetResourceString(L"OfflineStatusHyperlinkText")->Data();
|
||||
|
||||
// The resource string has the 'NetworkSettings' hyperlink wrapped with '%HL%'.
|
||||
// Break the string and assign pieces appropriately.
|
||||
@@ -245,9 +243,9 @@ void UnitConverter::OnCopyMenuItemClicked(_In_ Object ^ sender, _In_ RoutedEvent
|
||||
|
||||
void UnitConverter::OnPasteMenuItemClicked(_In_ Object ^ sender, _In_ RoutedEventArgs ^ e)
|
||||
{
|
||||
CopyPasteManager::GetStringToPaste(Model->Mode, CategoryGroupType::Converter).then([this](String ^ pastedString) {
|
||||
Model->OnPaste(pastedString);
|
||||
});
|
||||
auto that(this);
|
||||
create_task(CopyPasteManager::GetStringToPaste(Model->Mode, CategoryGroupType::Converter, -1, BitLength::BitLengthUnknown))
|
||||
.then([that](String ^ pastedString) { that->Model->OnPaste(pastedString); });
|
||||
}
|
||||
|
||||
void UnitConverter::AnimateConverter()
|
||||
|
Reference in New Issue
Block a user