From d9df27ffa4d8e8d56df5f75ec5d89a0a6c1f1c19 Mon Sep 17 00:00:00 2001 From: PankajBhojwani Date: Tue, 26 Jul 2022 15:05:27 -0700 Subject: [PATCH] Improve Launch MVVM (#13467) ## Summary of the Pull Request The xaml file no longer directly accesses the settings model object, and the settings model object is no longer exposed on the view model ## References #13377 ## PR Checklist * [ ] Closes #xxx * [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA * [ ] Tests added/passed * [ ] Documentation updated. If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/terminal) and link it here: #xxx * [ ] Schema updated. * [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 Still works --- .../TerminalSettingsEditor/Launch.xaml | 10 ++++---- .../LaunchViewModel.cpp | 25 +++++++++++++------ .../TerminalSettingsEditor/LaunchViewModel.h | 11 ++++++-- .../LaunchViewModel.idl | 14 ++++++++--- 4 files changed, 42 insertions(+), 18 deletions(-) diff --git a/src/cascadia/TerminalSettingsEditor/Launch.xaml b/src/cascadia/TerminalSettingsEditor/Launch.xaml index 63b63880e62..5fcd45d7035 100644 --- a/src/cascadia/TerminalSettingsEditor/Launch.xaml +++ b/src/cascadia/TerminalSettingsEditor/Launch.xaml @@ -73,8 +73,8 @@ x:Uid="Globals_DefaultTerminal" x:Load="false"> @@ -137,7 +137,7 @@ - @@ -192,7 +192,7 @@ Grid.Column="1" VerticalAlignment="Center" Style="{StaticResource LaunchSizeNumberBoxStyle}" - Value="{x:Bind ViewModel.Settings.GlobalSettings.InitialCols, Mode=TwoWay}" /> + Value="{x:Bind ViewModel.InitialCols, Mode=TwoWay}" /> + Value="{x:Bind ViewModel.InitialRows, Mode=TwoWay}" /> diff --git a/src/cascadia/TerminalSettingsEditor/LaunchViewModel.cpp b/src/cascadia/TerminalSettingsEditor/LaunchViewModel.cpp index ddd8602beaa..cc4a3a3dd9f 100644 --- a/src/cascadia/TerminalSettingsEditor/LaunchViewModel.cpp +++ b/src/cascadia/TerminalSettingsEditor/LaunchViewModel.cpp @@ -25,11 +25,6 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation INITIALIZE_BINDABLE_ENUM_SETTING(WindowingBehavior, WindowingMode, WindowingMode, L"Globals_WindowingBehavior", L"Content"); } - Model::CascadiaSettings LaunchViewModel::Settings() const - { - return _Settings; - } - winrt::Windows::Foundation::IInspectable LaunchViewModel::CurrentDefaultProfile() { const auto defaultProfileGuid{ _Settings.GlobalSettings().DefaultProfile() }; @@ -42,11 +37,11 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation _Settings.GlobalSettings().DefaultProfile(profile.Guid()); } - winrt::Windows::Foundation::Collections::IObservableVector LaunchViewModel::DefaultProfiles() const + winrt::Windows::Foundation::Collections::IObservableVector LaunchViewModel::DefaultProfiles() const { const auto allProfiles = _Settings.AllProfiles(); - std::vector profiles; + std::vector profiles; profiles.reserve(allProfiles.Size()); // Remove profiles from the selection which have been explicitly deleted. @@ -62,4 +57,20 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation return winrt::single_threaded_observable_vector(std::move(profiles)); } + + winrt::Windows::Foundation::IInspectable LaunchViewModel::CurrentDefaultTerminal() + { + return winrt::box_value(_Settings.CurrentDefaultTerminal()); + } + + void LaunchViewModel::CurrentDefaultTerminal(const IInspectable& value) + { + const auto defaultTerminal{ winrt::unbox_value(value) }; + _Settings.CurrentDefaultTerminal(defaultTerminal); + } + + winrt::Windows::Foundation::Collections::IObservableVector LaunchViewModel::DefaultTerminals() const + { + return _Settings.DefaultTerminals(); + } } diff --git a/src/cascadia/TerminalSettingsEditor/LaunchViewModel.h b/src/cascadia/TerminalSettingsEditor/LaunchViewModel.h index 94b888bb1d0..92c42cf630c 100644 --- a/src/cascadia/TerminalSettingsEditor/LaunchViewModel.h +++ b/src/cascadia/TerminalSettingsEditor/LaunchViewModel.h @@ -13,16 +13,23 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation { public: LaunchViewModel(Model::CascadiaSettings settings); - Model::CascadiaSettings Settings() const; IInspectable CurrentDefaultProfile(); void CurrentDefaultProfile(const IInspectable& value); - winrt::Windows::Foundation::Collections::IObservableVector DefaultProfiles() const; + winrt::Windows::Foundation::Collections::IObservableVector DefaultProfiles() const; + + IInspectable CurrentDefaultTerminal(); + void CurrentDefaultTerminal(const IInspectable& value); + winrt::Windows::Foundation::Collections::IObservableVector DefaultTerminals() const; GETSET_BINDABLE_ENUM_SETTING(FirstWindowPreference, Model::FirstWindowPreference, _Settings.GlobalSettings().FirstWindowPreference); GETSET_BINDABLE_ENUM_SETTING(LaunchMode, Model::LaunchMode, _Settings.GlobalSettings().LaunchMode); GETSET_BINDABLE_ENUM_SETTING(WindowingBehavior, Model::WindowingMode, _Settings.GlobalSettings().WindowingBehavior); + PERMANENT_OBSERVABLE_PROJECTED_SETTING(_Settings.GlobalSettings(), StartOnUserLogin); + PERMANENT_OBSERVABLE_PROJECTED_SETTING(_Settings.GlobalSettings(), InitialRows); + PERMANENT_OBSERVABLE_PROJECTED_SETTING(_Settings.GlobalSettings(), InitialCols); + private: Model::CascadiaSettings _Settings; }; diff --git a/src/cascadia/TerminalSettingsEditor/LaunchViewModel.idl b/src/cascadia/TerminalSettingsEditor/LaunchViewModel.idl index 313ad46e0a0..1531ac9380c 100644 --- a/src/cascadia/TerminalSettingsEditor/LaunchViewModel.idl +++ b/src/cascadia/TerminalSettingsEditor/LaunchViewModel.idl @@ -3,17 +3,19 @@ import "EnumEntry.idl"; +#include "ViewModelHelpers.idl.h" + namespace Microsoft.Terminal.Settings.Editor { runtimeclass LaunchViewModel : Windows.UI.Xaml.Data.INotifyPropertyChanged { LaunchViewModel(Microsoft.Terminal.Settings.Model.CascadiaSettings settings); - Microsoft.Terminal.Settings.Model.CascadiaSettings Settings { get; }; IInspectable CurrentDefaultProfile; - // I wish this was a IObservableVector, but: - // https://github.com/microsoft/microsoft-ui-xaml/issues/5395 - IObservableVector DefaultProfiles { get; }; + IObservableVector DefaultProfiles { get; }; + + IInspectable CurrentDefaultTerminal; + IObservableVector DefaultTerminals { get; }; IInspectable CurrentFirstWindowPreference; IObservableVector FirstWindowPreferenceList { get; }; @@ -23,5 +25,9 @@ namespace Microsoft.Terminal.Settings.Editor IInspectable CurrentWindowingBehavior; IObservableVector WindowingBehaviorList { get; }; + + PERMANENT_OBSERVABLE_PROJECTED_SETTING(Boolean, StartOnUserLogin); + PERMANENT_OBSERVABLE_PROJECTED_SETTING(Int32, InitialRows); + PERMANENT_OBSERVABLE_PROJECTED_SETTING(Int32, InitialCols); } }