mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-20 13:23:13 -07:00
Remove PLM code from MainPage
This commit is contained in:
parent
ba7edad6e9
commit
f298662fb3
2 changed files with 18 additions and 93 deletions
|
@ -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"
|
||||||
|
@ -85,105 +85,32 @@ MainPage::MainPage() :
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
void MainPage::OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e)
|
||||||
/// Populates the page with content passed during navigation. Any saved state is also
|
|
||||||
/// provided when recreating a page from a prior session.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="navigationParameter">The parameter value passed to
|
|
||||||
/// <see cref="Frame::Navigate(Type, Object)"/> when this page was initially requested.
|
|
||||||
/// </param>
|
|
||||||
/// <param name="pageState">A map of state preserved by this page during an earlier
|
|
||||||
/// session. This will be null the first time a page is visited.</param>
|
|
||||||
void MainPage::LoadState(_In_ Object^ navigationParameter, _In_ IMap<String^, Object^>^ pageState)
|
|
||||||
{
|
{
|
||||||
if (pageState != nullptr)
|
if (m_model->CalculatorViewModel)
|
||||||
{
|
{
|
||||||
if (pageState->HasKey("ConverterViewModelState"))
|
m_model->CalculatorViewModel->HistoryVM->ClearHistory();
|
||||||
|
}
|
||||||
|
|
||||||
|
ViewMode initialMode = ViewMode::Standard;
|
||||||
|
if (e->Parameter != nullptr)
|
||||||
|
{
|
||||||
|
String^ stringParameter = dynamic_cast<String^>(e->Parameter);
|
||||||
|
if (stringParameter != nullptr)
|
||||||
{
|
{
|
||||||
auto converterViewModelState = safe_cast<String^>(pageState->Lookup("ConverterViewModelState"));
|
initialMode = (ViewMode)stoi(stringParameter->Data());
|
||||||
|
|
||||||
m_model->ConverterViewModel->Deserialize(converterViewModelState);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Moving these below the converter view model deserialize, since the converter modes are also displayed in the MainPage NavBar and thus need to be deserialized before setting the current mode
|
|
||||||
if (pageState->HasKey(ApplicationViewModelProperties::Mode))
|
|
||||||
{
|
|
||||||
m_model->Mode = NavCategory::Deserialize(pageState->Lookup(ApplicationViewModelProperties::Mode));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pageState->HasKey(ApplicationViewModelProperties::PreviousMode))
|
|
||||||
{
|
|
||||||
m_model->PreviousMode = NavCategory::Deserialize(pageState->Lookup(ApplicationViewModelProperties::PreviousMode));
|
|
||||||
}
|
|
||||||
|
|
||||||
// rehydrate
|
|
||||||
if (pageState->HasKey("CalculatorViewModelState"))
|
|
||||||
{
|
|
||||||
auto calculatorViewModelState = safe_cast<Array<unsigned char>^>(pageState->Lookup("CalculatorViewModelState"));
|
|
||||||
|
|
||||||
m_model->CalculatorViewModel->Deserialize(calculatorViewModelState);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_model->CalculatorViewModel->HistoryVM->RestoreCompleteHistory();
|
|
||||||
m_model->CalculatorViewModel->HistoryVM->ReloadHistory(m_model->Mode);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// initialize
|
ApplicationDataContainer^ localSettings = ApplicationData::Current->LocalSettings;
|
||||||
if (m_model->CalculatorViewModel)
|
if (localSettings->Values->HasKey(ApplicationViewModelProperties::Mode))
|
||||||
{
|
{
|
||||||
m_model->CalculatorViewModel->HistoryVM->ClearHistory();
|
initialMode = NavCategory::Deserialize(localSettings->Values->Lookup(ApplicationViewModelProperties::Mode));
|
||||||
}
|
}
|
||||||
|
|
||||||
ViewMode initialMode = ViewMode::Standard;
|
|
||||||
if (navigationParameter != nullptr)
|
|
||||||
{
|
|
||||||
String^ stringParameter = dynamic_cast<String^>(navigationParameter);
|
|
||||||
if (stringParameter != nullptr)
|
|
||||||
{
|
|
||||||
initialMode = (ViewMode)stoi(stringParameter->Data());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ApplicationDataContainer^ localSettings = ApplicationData::Current->LocalSettings;
|
|
||||||
if (localSettings->Values->HasKey(ApplicationViewModelProperties::Mode))
|
|
||||||
{
|
|
||||||
initialMode = NavCategory::Deserialize(localSettings->Values->Lookup(ApplicationViewModelProperties::Mode));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
m_model->Initialize(initialMode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Preserves state associated with this page in case the application is suspended or the
|
|
||||||
/// page is discarded from the navigation cache. Values must conform to the serialization
|
|
||||||
/// requirements of <see cref="SuspensionManager::SessionState"/>.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="pageState">An empty map to be populated with serializable state.</param>
|
|
||||||
void MainPage::SaveState(_In_ IMap<String^, Object^>^ pageState)
|
|
||||||
{
|
|
||||||
int serializedCurrentMode = NavCategory::Serialize(m_model->Mode);
|
|
||||||
|
|
||||||
pageState->Insert(ApplicationViewModelProperties::Mode, serializedCurrentMode);
|
|
||||||
pageState->Insert(ApplicationViewModelProperties::PreviousMode, NavCategory::Serialize(m_model->PreviousMode));
|
|
||||||
|
|
||||||
ApplicationDataContainer^ localSettings = ApplicationData::Current->LocalSettings;
|
|
||||||
localSettings->Values->Insert(ApplicationViewModelProperties::Mode, serializedCurrentMode);
|
|
||||||
|
|
||||||
auto serializedCalculatorData = m_model->CalculatorViewModel->Serialize();
|
|
||||||
auto serializedConverterData = m_model->ConverterViewModel->Serialize();
|
|
||||||
if (serializedCalculatorData->Length > 0)
|
|
||||||
{
|
|
||||||
pageState->Insert("CalculatorViewModelState", serializedCalculatorData);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (serializedConverterData != nullptr)
|
m_model->Initialize(initialMode);
|
||||||
{
|
|
||||||
pageState->Insert("ConverterViewModelState", serializedConverterData);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainPage::WindowSizeChanged(_In_ Platform::Object^ /*sender*/, _In_ Windows::UI::Core::WindowSizeChangedEventArgs^ e)
|
void MainPage::WindowSizeChanged(_In_ Platform::Object^ /*sender*/, _In_ Windows::UI::Core::WindowSizeChangedEventArgs^ e)
|
||||||
|
|
|
@ -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
|
||||||
|
@ -40,9 +40,7 @@ namespace CalculatorApp
|
||||||
Windows::Foundation::Collections::IObservableVector<Platform::Object^>^ CreateUIElementsForCategories(_In_ Windows::Foundation::Collections::IObservableVector<CalculatorApp::Common::NavCategoryGroup^>^ categories);
|
Windows::Foundation::Collections::IObservableVector<Platform::Object^>^ CreateUIElementsForCategories(_In_ Windows::Foundation::Collections::IObservableVector<CalculatorApp::Common::NavCategoryGroup^>^ categories);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void LoadState(_In_ Platform::Object^ navigationParameter,
|
virtual void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;
|
||||||
_In_ Windows::Foundation::Collections::IMap<Platform::String^, Platform::Object^>^ pageState) override;
|
|
||||||
virtual void SaveState(_In_ Windows::Foundation::Collections::IMap<Platform::String^, Platform::Object^>^ pageState) override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void WindowSizeChanged(_In_ Platform::Object^ sender, _In_ Windows::UI::Core::WindowSizeChangedEventArgs^ e);
|
void WindowSizeChanged(_In_ Platform::Object^ sender, _In_ Windows::UI::Core::WindowSizeChangedEventArgs^ e);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue