From bbc570d107b6b67b68454355e04724ecea9c9796 Mon Sep 17 00:00:00 2001 From: PankajBhojwani Date: Fri, 8 Jul 2022 15:50:38 -0700 Subject: [PATCH] Implement MVVM for the Rendering page (#13391) ## Summary of the Pull Request Implements a `RenderingViewModel` for the Rendering page in the SUI ## PR Checklist * [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA * [x] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx ## Validation Steps Performed Rendering page still works --- .../TerminalSettingsEditor/MainPage.cpp | 3 +- ...Microsoft.Terminal.Settings.Editor.vcxproj | 9 ++++++ ...t.Terminal.Settings.Editor.vcxproj.filters | 1 + .../TerminalSettingsEditor/Rendering.cpp | 3 +- .../TerminalSettingsEditor/Rendering.h | 13 ++------- .../TerminalSettingsEditor/Rendering.idl | 9 ++---- .../TerminalSettingsEditor/Rendering.xaml | 4 +-- .../RenderingViewModel.cpp | 17 +++++++++++ .../RenderingViewModel.h | 28 +++++++++++++++++++ .../RenderingViewModel.idl | 17 +++++++++++ 10 files changed, 82 insertions(+), 22 deletions(-) create mode 100644 src/cascadia/TerminalSettingsEditor/RenderingViewModel.cpp create mode 100644 src/cascadia/TerminalSettingsEditor/RenderingViewModel.h create mode 100644 src/cascadia/TerminalSettingsEditor/RenderingViewModel.idl diff --git a/src/cascadia/TerminalSettingsEditor/MainPage.cpp b/src/cascadia/TerminalSettingsEditor/MainPage.cpp index 1529968df05..fcca6ca30f7 100644 --- a/src/cascadia/TerminalSettingsEditor/MainPage.cpp +++ b/src/cascadia/TerminalSettingsEditor/MainPage.cpp @@ -7,6 +7,7 @@ #include "Launch.h" #include "Interaction.h" #include "Rendering.h" +#include "RenderingViewModel.h" #include "Actions.h" #include "Profiles.h" #include "GlobalAppearance.h" @@ -352,7 +353,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation } else if (clickedItemTag == renderingTag) { - contentFrame().Navigate(xaml_typename(), winrt::make(_settingsClone.GlobalSettings())); + contentFrame().Navigate(xaml_typename(), winrt::make(_settingsClone.GlobalSettings())); const auto crumb = winrt::make(box_value(clickedItemTag), RS_(L"Nav_Rendering/Content"), BreadcrumbSubPage::None); _breadcrumbs.Append(crumb); } diff --git a/src/cascadia/TerminalSettingsEditor/Microsoft.Terminal.Settings.Editor.vcxproj b/src/cascadia/TerminalSettingsEditor/Microsoft.Terminal.Settings.Editor.vcxproj index 9c667000d51..16926b30c46 100644 --- a/src/cascadia/TerminalSettingsEditor/Microsoft.Terminal.Settings.Editor.vcxproj +++ b/src/cascadia/TerminalSettingsEditor/Microsoft.Terminal.Settings.Editor.vcxproj @@ -81,6 +81,10 @@ ProfileViewModel.idl Code + + RenderingViewModel.idl + Code + InteractionViewModel.idl Code @@ -205,6 +209,10 @@ ProfileViewModel.idl Code + + RenderingViewModel.idl + Code + InteractionViewModel.idl Code @@ -287,6 +295,7 @@ Code + diff --git a/src/cascadia/TerminalSettingsEditor/Microsoft.Terminal.Settings.Editor.vcxproj.filters b/src/cascadia/TerminalSettingsEditor/Microsoft.Terminal.Settings.Editor.vcxproj.filters index fbab4f94671..705877a68f3 100644 --- a/src/cascadia/TerminalSettingsEditor/Microsoft.Terminal.Settings.Editor.vcxproj.filters +++ b/src/cascadia/TerminalSettingsEditor/Microsoft.Terminal.Settings.Editor.vcxproj.filters @@ -18,6 +18,7 @@ + diff --git a/src/cascadia/TerminalSettingsEditor/Rendering.cpp b/src/cascadia/TerminalSettingsEditor/Rendering.cpp index d3f6a81a85d..5ce0d1285e9 100644 --- a/src/cascadia/TerminalSettingsEditor/Rendering.cpp +++ b/src/cascadia/TerminalSettingsEditor/Rendering.cpp @@ -4,7 +4,6 @@ #include "pch.h" #include "Rendering.h" #include "Rendering.g.cpp" -#include "RenderingPageNavigationState.g.cpp" using namespace winrt::Windows::UI::Xaml::Navigation; @@ -17,6 +16,6 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation void Rendering::OnNavigatedTo(const NavigationEventArgs& e) { - _State = e.Parameter().as(); + _ViewModel = e.Parameter().as(); } } diff --git a/src/cascadia/TerminalSettingsEditor/Rendering.h b/src/cascadia/TerminalSettingsEditor/Rendering.h index e26ad44fa06..32c101aae0e 100644 --- a/src/cascadia/TerminalSettingsEditor/Rendering.h +++ b/src/cascadia/TerminalSettingsEditor/Rendering.h @@ -4,27 +4,18 @@ #pragma once #include "Rendering.g.h" -#include "RenderingPageNavigationState.g.h" #include "Utils.h" namespace winrt::Microsoft::Terminal::Settings::Editor::implementation { - struct RenderingPageNavigationState : RenderingPageNavigationStateT - { - public: - RenderingPageNavigationState(const Model::GlobalAppSettings& settings) : - _Globals{ settings } {} - - WINRT_PROPERTY(Model::GlobalAppSettings, Globals, nullptr) - }; - struct Rendering : public HasScrollViewer, RenderingT { Rendering(); void OnNavigatedTo(const winrt::Windows::UI::Xaml::Navigation::NavigationEventArgs& e); - WINRT_PROPERTY(Editor::RenderingPageNavigationState, State, nullptr); + WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler); + WINRT_OBSERVABLE_PROPERTY(Editor::RenderingViewModel, ViewModel, _PropertyChangedHandlers, nullptr); }; } diff --git a/src/cascadia/TerminalSettingsEditor/Rendering.idl b/src/cascadia/TerminalSettingsEditor/Rendering.idl index 725f72ba0b5..21dc7d8023f 100644 --- a/src/cascadia/TerminalSettingsEditor/Rendering.idl +++ b/src/cascadia/TerminalSettingsEditor/Rendering.idl @@ -1,16 +1,13 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. +import "RenderingViewModel.idl"; + namespace Microsoft.Terminal.Settings.Editor { - runtimeclass RenderingPageNavigationState - { - Microsoft.Terminal.Settings.Model.GlobalAppSettings Globals; - }; - [default_interface] runtimeclass Rendering : Windows.UI.Xaml.Controls.Page { Rendering(); - RenderingPageNavigationState State { get; }; + RenderingViewModel ViewModel { get; }; } } diff --git a/src/cascadia/TerminalSettingsEditor/Rendering.xaml b/src/cascadia/TerminalSettingsEditor/Rendering.xaml index 72f39027bca..0f19ac0f88e 100644 --- a/src/cascadia/TerminalSettingsEditor/Rendering.xaml +++ b/src/cascadia/TerminalSettingsEditor/Rendering.xaml @@ -25,13 +25,13 @@ - - diff --git a/src/cascadia/TerminalSettingsEditor/RenderingViewModel.cpp b/src/cascadia/TerminalSettingsEditor/RenderingViewModel.cpp new file mode 100644 index 00000000000..e00d3462da4 --- /dev/null +++ b/src/cascadia/TerminalSettingsEditor/RenderingViewModel.cpp @@ -0,0 +1,17 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +#include "pch.h" +#include "RenderingViewModel.h" +#include "RenderingViewModel.g.cpp" + +using namespace winrt::Windows::Foundation; +using namespace winrt::Microsoft::Terminal::Settings::Model; + +namespace winrt::Microsoft::Terminal::Settings::Editor::implementation +{ + RenderingViewModel::RenderingViewModel(Model::GlobalAppSettings globalSettings) : + _GlobalSettings{ globalSettings } + { + } +} diff --git a/src/cascadia/TerminalSettingsEditor/RenderingViewModel.h b/src/cascadia/TerminalSettingsEditor/RenderingViewModel.h new file mode 100644 index 00000000000..fdf784fff23 --- /dev/null +++ b/src/cascadia/TerminalSettingsEditor/RenderingViewModel.h @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +#pragma once + +#include "RenderingViewModel.g.h" +#include "ViewModelHelpers.h" +#include "Utils.h" + +namespace winrt::Microsoft::Terminal::Settings::Editor::implementation +{ + struct RenderingViewModel : RenderingViewModelT, ViewModelHelper + { + public: + RenderingViewModel(Model::GlobalAppSettings globalSettings); + + PERMANENT_OBSERVABLE_PROJECTED_SETTING(_GlobalSettings, ForceFullRepaintRendering); + PERMANENT_OBSERVABLE_PROJECTED_SETTING(_GlobalSettings, SoftwareRendering); + + private: + Model::GlobalAppSettings _GlobalSettings; + }; +}; + +namespace winrt::Microsoft::Terminal::Settings::Editor::factory_implementation +{ + BASIC_FACTORY(RenderingViewModel); +} diff --git a/src/cascadia/TerminalSettingsEditor/RenderingViewModel.idl b/src/cascadia/TerminalSettingsEditor/RenderingViewModel.idl new file mode 100644 index 00000000000..b4ad306387b --- /dev/null +++ b/src/cascadia/TerminalSettingsEditor/RenderingViewModel.idl @@ -0,0 +1,17 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import "EnumEntry.idl"; + +#include "ViewModelHelpers.idl.h" + +namespace Microsoft.Terminal.Settings.Editor +{ + runtimeclass RenderingViewModel : Windows.UI.Xaml.Data.INotifyPropertyChanged + { + RenderingViewModel(Microsoft.Terminal.Settings.Model.GlobalAppSettings globalSettings); + + PERMANENT_OBSERVABLE_PROJECTED_SETTING(Boolean, ForceFullRepaintRendering); + PERMANENT_OBSERVABLE_PROJECTED_SETTING(Boolean, SoftwareRendering); + } +}