From 87d9fdb1dae7900b9a8cccfd5ac9d2f428b52743 Mon Sep 17 00:00:00 2001 From: Carlos Zamora Date: Thu, 7 May 2026 18:53:54 -0700 Subject: [PATCH] add polish --- .../TerminalSettingsEditor/MainPage.cpp | 199 ++++++++---------- .../TerminalSettingsEditor/MainPage.h | 5 +- ...Microsoft.Terminal.Settings.Editor.vcxproj | 9 - ...t.Terminal.Settings.Editor.vcxproj.filters | 1 - .../TerminalSettingsEditor/Profiles.cpp | 48 +++-- .../TerminalSettingsEditor/Profiles.h | 33 ++- .../TerminalSettingsEditor/Profiles.idl | 20 +- .../TerminalSettingsEditor/Profiles.xaml | 34 ++- .../ProfilesPageViewModel.cpp | 42 ---- .../ProfilesPageViewModel.h | 41 ---- .../ProfilesPageViewModel.idl | 26 --- src/cascadia/UIHelpers/Converters.cpp | 5 - src/cascadia/UIHelpers/Converters.h | 1 - src/cascadia/UIHelpers/Converters.idl | 1 - tools/GenerateSettingsIndex.ps1 | 5 + 15 files changed, 182 insertions(+), 288 deletions(-) delete mode 100644 src/cascadia/TerminalSettingsEditor/ProfilesPageViewModel.cpp delete mode 100644 src/cascadia/TerminalSettingsEditor/ProfilesPageViewModel.h delete mode 100644 src/cascadia/TerminalSettingsEditor/ProfilesPageViewModel.idl diff --git a/src/cascadia/TerminalSettingsEditor/MainPage.cpp b/src/cascadia/TerminalSettingsEditor/MainPage.cpp index 3ada1f0823..61e37fd093 100644 --- a/src/cascadia/TerminalSettingsEditor/MainPage.cpp +++ b/src/cascadia/TerminalSettingsEditor/MainPage.cpp @@ -18,7 +18,6 @@ #include "EditColorScheme.h" #include "AddProfile.h" #include "Profiles.h" -#include "ProfilesPageViewModel.h" #include "InteractionViewModel.h" #include "LaunchViewModel.h" #include "NewTabMenuViewModel.h" @@ -104,7 +103,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation MainPage::MainPage(const CascadiaSettings& settings) : _settingsSource{ settings }, _settingsClone{ settings.Copy() }, - _profileVMs{ single_threaded_observable_vector() } + _profilesPageVM{ winrt::make() } { InitializeComponent(); _UpdateBackgroundForMica(); @@ -158,14 +157,12 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation } }); - // Make sure to initialize the profiles _after_ we have initialized the color schemes page VM, because we pass - // that VM into the appearance VMs within the profiles - _InitializeProfilesList(); - - // Build the Profiles landing page view model and wire its requests up to MainPage navigation handlers. - _profilesPageVM = winrt::make(_profileVMs); _SetupProfilesPageEventHandling(); + // Make sure to initialize the profiles _after_ we have initialized the color schemes page VM, because we pass + // that VM into the appearance VMs within the profiles. The Profiles VM owns the per-profile list itself. + _InitializeProfilesList(); + // Apply icons and tooltips (GH#19688, long names may be truncated) to static nav items for (const auto& item : SettingsNav().MenuItems()) { @@ -211,16 +208,24 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation _UpdateBackgroundForMica(); - // Deduce information about the currently selected item - IInspectable lastBreadcrumb; - const auto size = _breadcrumbs.Size(); - if (size > 0) + // Capture data about where we are right now, so we can re-navigate to the same + // place after we rebuild all the settings. + IInspectable destination{ nullptr }; + auto subPage = BreadcrumbSubPage::None; + hstring parentNavTag{}; + if (const auto size = _breadcrumbs.Size(); size > 0) { - lastBreadcrumb = _breadcrumbs.GetAt(size - 1); + const auto& crumb = _breadcrumbs.GetAt(size - 1).as(); + destination = crumb->Tag(); + subPage = crumb->SubPage(); + // If we were inside the Profiles section, remember that so we can restore + // the "Profiles ›" prefix on the rebuilt navigation. + if (_RootCrumbIsProfilesBreadcrumb()) + { + parentNavTag = hstring{ profilesTag }; + } } - // Repopulate the profile view models. The Profiles landing page rebinds via - // _profilesPageVM->UpdateProfileVMs below. _InitializeProfilesList(); // Update the Nav State with the new version of the settings @@ -229,61 +234,44 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation _newTabMenuPageVM.UpdateSettings(_settingsClone); _extensionsVM.UpdateSettings(_settingsClone, _colorSchemesPageVM); _profileDefaultsVM = nullptr; // Lazy-loaded upon navigation - if (_profilesPageVM) + + if (const auto& profileTag{ destination.try_as() }) { - _profilesPageVM.UpdateProfileVMs(_profileVMs); + // Find the new profile VM by guid + if (const auto newProfileVM = _FindProfileVMByGuid(profileTag.OriginalProfileGuid())) + { + destination = newProfileVM; + } + else + { + // Fall back to the Profiles landing page + destination = box_value(profilesTag); + subPage = BreadcrumbSubPage::None; + parentNavTag = {}; + } } - - // Now that the menuItems are repopulated, - // refresh the current page using the breadcrumb data we collected before the refresh - if (const auto& crumb{ lastBreadcrumb.try_as() }; crumb && crumb->Tag()) + else if (destination.try_as()) { - auto destination = crumb->Tag(); - auto subPage = crumb->SubPage(); - - // Capture root context before the new navigation. We need this so that pages - // reached via the Profiles landing page keep their "Profiles" breadcrumb prefix after a settings reload. - const hstring inheritedParentNavTag = _RootCrumbIsProfiles() ? hstring{ profilesTag } : hstring{}; - - if (const auto& profileTag{ destination.try_as() }) + destination = box_value(newTabMenuTag); + subPage = BreadcrumbSubPage::NewTabMenu_Folder; + } + else if (destination.try_as()) + { + destination = box_value(extensionsTag); + subPage = BreadcrumbSubPage::Extensions_Extension; + } + else if (!destination.try_as()) + { + // Couldn't find a meaningful previous page. Fall back to the first menu item. + if (_menuItemSource && _menuItemSource.Size() > 0) { - if (const auto newProfileVM = _FindProfileVMByGuid(profileTag.OriginalProfileGuid())) - { - _Navigate(newProfileVM, subPage); - _UpdateSearchIndex(); - return; - } - // Profile was deleted in the new settings. Fall through to the Profiles landing page. - _Navigate(box_value(profilesTag), BreadcrumbSubPage::None); - _UpdateSearchIndex(); - return; - } - else if (const auto& destString{ destination.try_as() }) - { - _Navigate(destination, subPage, {}, inheritedParentNavTag); - _UpdateSearchIndex(); - return; - } - else if (destination.try_as()) - { - _Navigate(box_value(newTabMenuTag), BreadcrumbSubPage::NewTabMenu_Folder); - _UpdateSearchIndex(); - return; - } - else if (destination.try_as()) - { - _Navigate(box_value(extensionsTag), BreadcrumbSubPage::Extensions_Extension); - _UpdateSearchIndex(); - return; + destination = _menuItemSource.GetAt(0).as().Tag(); + subPage = BreadcrumbSubPage::None; + parentNavTag = {}; } } - // Couldn't find a meaningful previous page. Fall back to the first menu item. - if (_menuItemSource && _menuItemSource.Size() > 0) - { - const auto& firstItem{ _menuItemSource.GetAt(0).as() }; - _Navigate(firstItem.Tag(), BreadcrumbSubPage::None); - } + _Navigate(destination, subPage, {}, parentNavTag); _UpdateSearchIndex(); } @@ -435,9 +423,8 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation } else if (_colorSchemesPageVM.CurrentPage() == ColorSchemesSubPage::Base) { - // Preserve the current root context so that "edit → delete → back to base" - // inside Profiles › Color schemes still shows the Profiles prefix. - const hstring inheritedParentNavTag = _RootCrumbIsProfiles() ? hstring{ profilesTag } : hstring{}; + // Preserve the current root context so that "Profiles > Color schemes" still shows the Profiles prefix. + const hstring inheritedParentNavTag = _RootCrumbIsProfilesBreadcrumb() ? hstring{ profilesTag } : hstring{}; _Navigate(boxedTag, BreadcrumbSubPage::None, {}, inheritedParentNavTag); } } @@ -862,22 +849,10 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation if (gsl::narrow_cast(args.Index()) < (_breadcrumbs.Size() - 1)) { const auto crumb = args.Item().as(); - - // Determine the parent nav-context based on the current root crumb so that - // navigating to (e.g.) Color schemes from inside the Profiles section keeps - // the "Profiles ›" prefix instead of falling back to the top-level form. - hstring parentNavTag{}; - if (_breadcrumbs.Size() > 0) - { - if (const auto rootCrumb = _breadcrumbs.GetAt(0).try_as()) - { - if (const auto rootTag = rootCrumb->Tag().try_as()) - { - parentNavTag = *rootTag; - } - } - } - + // If the breadcrumb chain is rooted at the Profiles landing page, preserve + // that context so navigating to sub pages (i.e. Color schemes) via a back-breadcrumb + // keeps the "Profiles ›" prefix. + const hstring parentNavTag = _RootCrumbIsProfilesBreadcrumb() ? hstring{ profilesTag } : hstring{}; _Navigate(crumb->Tag(), crumb->SubPage(), {}, parentNavTag); } } @@ -895,7 +870,10 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation _MoveXamlParsedNavItemsIntoItemSource(); } - _profileVMs.Clear(); + // Populate the per-profile view models on the Profiles VM. The Profiles landing + // page (and the search index) read this same list back through the VM. + const auto& profileVMs = _profilesPageVM.Profiles(); + profileVMs.Clear(); for (const auto& profile : _settingsClone.AllProfiles()) { if (!profile.Deleted()) @@ -903,7 +881,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation auto profileVM = _viewModelForProfile(profile, _settingsClone, Dispatcher()); profileVM.SetupAppearances(_colorSchemesPageVM.AllColorSchemes()); profileVM.DeleteProfileRequested({ this, &MainPage::_DeleteProfile }); - _profileVMs.Append(profileVM); + profileVMs.Append(profileVM); } } } @@ -948,10 +926,10 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation profileViewModel.SetupAppearances(_colorSchemesPageVM.AllColorSchemes()); profileViewModel.DeleteProfileRequested({ this, &MainPage::_DeleteProfile }); - _profileVMs.Append(profileViewModel); + _profilesPageVM.Profiles().Append(profileViewModel); // Select and navigate to the new profile - _Navigate(profileViewModel, BreadcrumbSubPage::None); + _Navigate(profileViewModel); } void MainPage::_DeleteProfile(const IInspectable /*sender*/, const Editor::DeleteProfileEventArgs& args) @@ -968,18 +946,19 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation } } - // remove the profile VM - for (uint32_t i = 0; i < _profileVMs.Size(); ++i) + // Remove the profile VM + const auto& profileVMs = _profilesPageVM.Profiles(); + for (uint32_t i = 0; i < profileVMs.Size(); ++i) { - if (_profileVMs.GetAt(i).OriginalProfileGuid() == guid) + if (profileVMs.GetAt(i).OriginalProfileGuid() == guid) { - _profileVMs.RemoveAt(i); + profileVMs.RemoveAt(i); break; } } // Go back to the Profiles landing page - _Navigate(box_value(profilesTag), BreadcrumbSubPage::None); + _Navigate(box_value(profilesTag)); SettingsMainPage_ScrollViewer().ChangeView(nullptr, 0.0, nullptr); } @@ -992,18 +971,14 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation { if (const auto profileVM = _FindProfileVMByGuid(profileGuid)) { - _Navigate(profileVM, BreadcrumbSubPage::None); + _Navigate(profileVM); } // Silently fail if the profile wasn't found } Editor::ProfileViewModel MainPage::_FindProfileVMByGuid(winrt::guid profileGuid) const { - if (!_profileVMs) - { - return nullptr; - } - for (const auto& profileVM : _profileVMs) + for (const auto& profileVM : _profilesPageVM.Profiles()) { if (profileVM.OriginalProfileGuid() == profileGuid) { @@ -1023,19 +998,14 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation _breadcrumbs.Append(winrt::make(box_value(profilesTag), RS_(L"Nav_Profiles/Content"), BreadcrumbSubPage::None)); } - bool MainPage::_RootCrumbIsProfiles() const + bool MainPage::_RootCrumbIsProfilesBreadcrumb() const { - if (_breadcrumbs && _breadcrumbs.Size() > 0) + if (_breadcrumbs.Size() == 0) { - if (const auto rootCrumb = _breadcrumbs.GetAt(0).try_as()) - { - if (const auto rootTag = rootCrumb->Tag().try_as()) - { - return *rootTag == profilesTag; - } - } + return false; } - return false; + const auto rootTag = _breadcrumbs.GetAt(0).as()->Tag().try_as(); + return rootTag && *rootTag == profilesTag; } void MainPage::_SelectNavItemByTag(std::wstring_view tag) @@ -1065,22 +1035,17 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation void MainPage::_SetupProfilesPageEventHandling() { - if (!_profilesPageVM) - { - return; - } - _profilesPageVM.OpenDefaultsRequested([this](const auto&, const auto&) { - _Navigate(box_value(globalProfileTag), BreadcrumbSubPage::None); + _Navigate(box_value(globalProfileTag)); }); _profilesPageVM.OpenColorSchemesRequested([this](const auto&, const auto&) { - _Navigate(box_value(colorSchemesTag), BreadcrumbSubPage::None, {}, hstring{ profilesTag }); + _Navigate(box_value(colorSchemesTag), {}, {}, hstring{ profilesTag }); }); _profilesPageVM.AddProfileRequested([this](const auto&, const auto&) { - _Navigate(box_value(addProfileTag), BreadcrumbSubPage::None); + _Navigate(box_value(addProfileTag)); }); _profilesPageVM.OpenProfileRequested([this](const auto&, const Editor::ProfileViewModel& profile) { - _Navigate(profile, BreadcrumbSubPage::None); + _Navigate(profile); }); } @@ -1186,7 +1151,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation co_return; } _currentSearch = SearchIndex::Instance().SearchAsync(sanitizedQuery, - _profileVMs.GetView(), + _profilesPageVM.Profiles().GetView(), get_self(_newTabMenuPageVM)->FolderTreeFlatList().GetView(), _colorSchemesPageVM.AllColorSchemes().GetView(), _extensionsVM.ExtensionPackages().GetView(), diff --git a/src/cascadia/TerminalSettingsEditor/MainPage.h b/src/cascadia/TerminalSettingsEditor/MainPage.h index 84cf79324b..f54f4edd96 100644 --- a/src/cascadia/TerminalSettingsEditor/MainPage.h +++ b/src/cascadia/TerminalSettingsEditor/MainPage.h @@ -95,13 +95,13 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation void _NavigateToProfileSubPage(const Editor::ProfileViewModel& profile, ProfileSubPage page, const IInspectable& breadcrumbTag, const hstring& elementToFocus); void _PreNavigateHelper(); - void _Navigate(const IInspectable& vm, BreadcrumbSubPage subPage, hstring elementToFocus = {}, hstring parentNavTag = {}); + void _Navigate(const IInspectable& vm, BreadcrumbSubPage subPage = BreadcrumbSubPage::None, hstring elementToFocus = {}, hstring parentNavTag = {}); void _NavigateToProfileHandler(const IInspectable& sender, winrt::guid profileGuid); void _NavigateToColorSchemeHandler(const IInspectable& sender, const IInspectable& args); Editor::ProfileViewModel _FindProfileVMByGuid(winrt::guid profileGuid) const; void _AppendProfilesRootCrumb(); - bool _RootCrumbIsProfiles() const; + bool _RootCrumbIsProfilesBreadcrumb() const; void _SelectNavItemByTag(std::wstring_view tag); void _UpdateBackgroundForMica(); @@ -110,7 +110,6 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation safe_void_coroutine _UpdateSearchIndex(); winrt::Microsoft::Terminal::Settings::Editor::ProfileViewModel _profileDefaultsVM{ nullptr }; - Windows::Foundation::Collections::IObservableVector _profileVMs{ nullptr }; winrt::Microsoft::Terminal::Settings::Editor::ColorSchemesPageViewModel _colorSchemesPageVM{ nullptr }; winrt::Microsoft::Terminal::Settings::Editor::ActionsViewModel _actionsVM{ nullptr }; winrt::Microsoft::Terminal::Settings::Editor::NewTabMenuViewModel _newTabMenuPageVM{ nullptr }; diff --git a/src/cascadia/TerminalSettingsEditor/Microsoft.Terminal.Settings.Editor.vcxproj b/src/cascadia/TerminalSettingsEditor/Microsoft.Terminal.Settings.Editor.vcxproj index 47c4513b9e..d16f83723b 100644 --- a/src/cascadia/TerminalSettingsEditor/Microsoft.Terminal.Settings.Editor.vcxproj +++ b/src/cascadia/TerminalSettingsEditor/Microsoft.Terminal.Settings.Editor.vcxproj @@ -119,10 +119,6 @@ ColorSchemesPageViewModel.idl Code - - ProfilesPageViewModel.idl - Code - Profiles.xaml Code @@ -342,10 +338,6 @@ ColorSchemesPageViewModel.idl Code - - ProfilesPageViewModel.idl - Code - Profiles.xaml Code @@ -475,7 +467,6 @@ - Profiles.xaml Code diff --git a/src/cascadia/TerminalSettingsEditor/Microsoft.Terminal.Settings.Editor.vcxproj.filters b/src/cascadia/TerminalSettingsEditor/Microsoft.Terminal.Settings.Editor.vcxproj.filters index 8d6b588edc..b9504abcf1 100644 --- a/src/cascadia/TerminalSettingsEditor/Microsoft.Terminal.Settings.Editor.vcxproj.filters +++ b/src/cascadia/TerminalSettingsEditor/Microsoft.Terminal.Settings.Editor.vcxproj.filters @@ -24,7 +24,6 @@ - diff --git a/src/cascadia/TerminalSettingsEditor/Profiles.cpp b/src/cascadia/TerminalSettingsEditor/Profiles.cpp index 3d05b55349..c4ee8f6475 100644 --- a/src/cascadia/TerminalSettingsEditor/Profiles.cpp +++ b/src/cascadia/TerminalSettingsEditor/Profiles.cpp @@ -4,9 +4,11 @@ #include "pch.h" #include "Profiles.h" #include "Profiles.g.cpp" +#include "ProfilesPageViewModel.g.cpp" #include "ProfileViewModel.h" using namespace winrt::Windows::Foundation; +using namespace winrt::Windows::Foundation::Collections; using namespace winrt::Windows::UI::Xaml; using namespace winrt::Windows::UI::Xaml::Controls; using namespace winrt::Windows::UI::Xaml::Navigation; @@ -39,35 +41,21 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation void Profiles::Defaults_Click(const IInspectable& /*sender*/, const RoutedEventArgs& /*args*/) { - if (_ViewModel) - { - _ViewModel.RequestOpenDefaults(); - } + _ViewModel.RequestOpenDefaults(); } void Profiles::ColorSchemes_Click(const IInspectable& /*sender*/, const RoutedEventArgs& /*args*/) { - if (_ViewModel) - { - _ViewModel.RequestOpenColorSchemes(); - } + _ViewModel.RequestOpenColorSchemes(); } void Profiles::AddProfile_Click(const IInspectable& /*sender*/, const RoutedEventArgs& /*args*/) { - if (_ViewModel) - { - _ViewModel.RequestAddProfile(); - } + _ViewModel.RequestAddProfile(); } void Profiles::Profile_Click(const IInspectable& sender, const RoutedEventArgs& /*args*/) { - if (!_ViewModel) - { - return; - } - // Profile navigators are buttons whose DataContext is the bound ProfileViewModel. if (const auto element = sender.try_as()) { @@ -77,4 +65,30 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation } } } + + ProfilesPageViewModel::ProfilesPageViewModel() + { + _setProfiles(single_threaded_observable_vector()); + } + + void ProfilesPageViewModel::RequestOpenDefaults() + { + OpenDefaultsRequested.raise(*this, nullptr); + } + + void ProfilesPageViewModel::RequestOpenColorSchemes() + { + OpenColorSchemesRequested.raise(*this, nullptr); + } + + void ProfilesPageViewModel::RequestAddProfile() + { + AddProfileRequested.raise(*this, nullptr); + } + + void ProfilesPageViewModel::RequestOpenProfile(const Editor::ProfileViewModel& profile) + { + OpenProfileRequested.raise(*this, profile); + } + } diff --git a/src/cascadia/TerminalSettingsEditor/Profiles.h b/src/cascadia/TerminalSettingsEditor/Profiles.h index 9c828cef7b..e1e5809aef 100644 --- a/src/cascadia/TerminalSettingsEditor/Profiles.h +++ b/src/cascadia/TerminalSettingsEditor/Profiles.h @@ -6,21 +6,43 @@ Module Name: - Profiles.h Abstract: -- The Profiles landing page in the Settings UI. Replaces the previous per-profile - navigation tree with a single "Profiles" nav item that opens this page. The page - hosts entry points to the Defaults profile, the Color schemes page, the Add Profile - flow, and the list of individual profiles. +- The Profiles landing page in the Settings UI. The page hosts entry points to + the list of individual profiles among other profile-related settings. --*/ #pragma once #include "Profiles.g.h" -#include "ProfilesPageViewModel.h" +#include "ProfilesPageViewModel.g.h" +#include "ProfileViewModel.h" #include "Utils.h" +#include "ViewModelHelpers.h" namespace winrt::Microsoft::Terminal::Settings::Editor::implementation { + struct ProfilesPageViewModel : ProfilesPageViewModelT, ViewModelHelper + { + public: + ProfilesPageViewModel(); + + void RequestOpenDefaults(); + void RequestOpenColorSchemes(); + void RequestAddProfile(); + void RequestOpenProfile(const Editor::ProfileViewModel& profile); + + // DON'T YOU DARE ADD A `WINRT_CALLBACK(PropertyChanged` TO A CLASS DERIVED FROM ViewModelHelper. Do this instead: + using ViewModelHelper::PropertyChanged; + + WINRT_OBSERVABLE_PROPERTY(Windows::Foundation::Collections::IObservableVector, Profiles, _propertyChangedHandlers, nullptr); + + public: + til::typed_event OpenDefaultsRequested; + til::typed_event OpenColorSchemesRequested; + til::typed_event AddProfileRequested; + til::typed_event OpenProfileRequested; + }; + struct Profiles : public HasScrollViewer, ProfilesT { public: @@ -41,4 +63,5 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation namespace winrt::Microsoft::Terminal::Settings::Editor::factory_implementation { BASIC_FACTORY(Profiles); + BASIC_FACTORY(ProfilesPageViewModel); } diff --git a/src/cascadia/TerminalSettingsEditor/Profiles.idl b/src/cascadia/TerminalSettingsEditor/Profiles.idl index 8c8d3d1c42..d10dd10dfb 100644 --- a/src/cascadia/TerminalSettingsEditor/Profiles.idl +++ b/src/cascadia/TerminalSettingsEditor/Profiles.idl @@ -1,10 +1,28 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import "ProfilesPageViewModel.idl"; +import "ProfileViewModel.idl"; +import "ColorSchemeViewModel.idl"; namespace Microsoft.Terminal.Settings.Editor { + runtimeclass ProfilesPageViewModel : Windows.UI.Xaml.Data.INotifyPropertyChanged + { + ProfilesPageViewModel(); + + Windows.Foundation.Collections.IObservableVector Profiles { get; }; + + void RequestOpenDefaults(); + void RequestOpenColorSchemes(); + void RequestAddProfile(); + void RequestOpenProfile(ProfileViewModel profile); + + event Windows.Foundation.TypedEventHandler OpenDefaultsRequested; + event Windows.Foundation.TypedEventHandler OpenColorSchemesRequested; + event Windows.Foundation.TypedEventHandler AddProfileRequested; + event Windows.Foundation.TypedEventHandler OpenProfileRequested; + } + [default_interface] runtimeclass Profiles : Windows.UI.Xaml.Controls.Page { Profiles(); diff --git a/src/cascadia/TerminalSettingsEditor/Profiles.xaml b/src/cascadia/TerminalSettingsEditor/Profiles.xaml index 60b5478529..54b3fd5f28 100644 --- a/src/cascadia/TerminalSettingsEditor/Profiles.xaml +++ b/src/cascadia/TerminalSettingsEditor/Profiles.xaml @@ -45,7 +45,7 @@ + Visibility="{x:Bind Hidden, Mode=OneWay}"> + Visibility="{x:Bind Orphaned, Mode=OneWay}"> - @@ -107,24 +106,21 @@ - - - - + & profileVMs) - { - _setProfiles(profileVMs); - } - - void ProfilesPageViewModel::UpdateProfileVMs(const IObservableVector& profileVMs) - { - Profiles(profileVMs); - } - - void ProfilesPageViewModel::RequestOpenDefaults() - { - OpenDefaultsRequested.raise(*this, nullptr); - } - - void ProfilesPageViewModel::RequestOpenColorSchemes() - { - OpenColorSchemesRequested.raise(*this, nullptr); - } - - void ProfilesPageViewModel::RequestAddProfile() - { - AddProfileRequested.raise(*this, nullptr); - } - - void ProfilesPageViewModel::RequestOpenProfile(const Editor::ProfileViewModel& profile) - { - OpenProfileRequested.raise(*this, profile); - } -} diff --git a/src/cascadia/TerminalSettingsEditor/ProfilesPageViewModel.h b/src/cascadia/TerminalSettingsEditor/ProfilesPageViewModel.h deleted file mode 100644 index b6e144c45f..0000000000 --- a/src/cascadia/TerminalSettingsEditor/ProfilesPageViewModel.h +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -#pragma once - -#include "ProfilesPageViewModel.g.h" -#include "ProfileViewModel.h" -#include "Utils.h" -#include "ViewModelHelpers.h" - -namespace winrt::Microsoft::Terminal::Settings::Editor::implementation -{ - struct ProfilesPageViewModel : ProfilesPageViewModelT, ViewModelHelper - { - public: - explicit ProfilesPageViewModel(const Windows::Foundation::Collections::IObservableVector& profileVMs); - - void UpdateProfileVMs(const Windows::Foundation::Collections::IObservableVector& profileVMs); - - void RequestOpenDefaults(); - void RequestOpenColorSchemes(); - void RequestAddProfile(); - void RequestOpenProfile(const Editor::ProfileViewModel& profile); - - // DON'T YOU DARE ADD A `WINRT_CALLBACK(PropertyChanged` TO A CLASS DERIVED FROM ViewModelHelper. Do this instead: - using ViewModelHelper::PropertyChanged; - - WINRT_OBSERVABLE_PROPERTY(Windows::Foundation::Collections::IObservableVector, Profiles, _propertyChangedHandlers, nullptr); - - public: - til::typed_event OpenDefaultsRequested; - til::typed_event OpenColorSchemesRequested; - til::typed_event AddProfileRequested; - til::typed_event OpenProfileRequested; - }; -}; - -namespace winrt::Microsoft::Terminal::Settings::Editor::factory_implementation -{ - BASIC_FACTORY(ProfilesPageViewModel); -} diff --git a/src/cascadia/TerminalSettingsEditor/ProfilesPageViewModel.idl b/src/cascadia/TerminalSettingsEditor/ProfilesPageViewModel.idl deleted file mode 100644 index 74e4b8c8ca..0000000000 --- a/src/cascadia/TerminalSettingsEditor/ProfilesPageViewModel.idl +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -import "ProfileViewModel.idl"; -import "ColorSchemeViewModel.idl"; - -namespace Microsoft.Terminal.Settings.Editor -{ - runtimeclass ProfilesPageViewModel : Windows.UI.Xaml.Data.INotifyPropertyChanged - { - ProfilesPageViewModel(Windows.Foundation.Collections.IObservableVector profileVMs); - void UpdateProfileVMs(Windows.Foundation.Collections.IObservableVector profileVMs); - - Windows.Foundation.Collections.IObservableVector Profiles { get; }; - - void RequestOpenDefaults(); - void RequestOpenColorSchemes(); - void RequestAddProfile(); - void RequestOpenProfile(ProfileViewModel profile); - - event Windows.Foundation.TypedEventHandler OpenDefaultsRequested; - event Windows.Foundation.TypedEventHandler OpenColorSchemesRequested; - event Windows.Foundation.TypedEventHandler AddProfileRequested; - event Windows.Foundation.TypedEventHandler OpenProfileRequested; - } -} diff --git a/src/cascadia/UIHelpers/Converters.cpp b/src/cascadia/UIHelpers/Converters.cpp index 78ce4003bd..e626c2b9e1 100644 --- a/src/cascadia/UIHelpers/Converters.cpp +++ b/src/cascadia/UIHelpers/Converters.cpp @@ -21,11 +21,6 @@ namespace winrt::Microsoft::Terminal::UI::implementation return value ? winrt::Windows::UI::Xaml::Visibility::Collapsed : winrt::Windows::UI::Xaml::Visibility::Visible; } - winrt::Windows::UI::Xaml::Visibility Converters::BooleanToVisibility(bool value) - { - return value ? winrt::Windows::UI::Xaml::Visibility::Visible : winrt::Windows::UI::Xaml::Visibility::Collapsed; - } - // Numbers double Converters::PercentageToPercentageValue(double value) { diff --git a/src/cascadia/UIHelpers/Converters.h b/src/cascadia/UIHelpers/Converters.h index a6ceca2e69..998daad41f 100644 --- a/src/cascadia/UIHelpers/Converters.h +++ b/src/cascadia/UIHelpers/Converters.h @@ -12,7 +12,6 @@ namespace winrt::Microsoft::Terminal::UI::implementation // Booleans static bool InvertBoolean(bool value); static winrt::Windows::UI::Xaml::Visibility InvertedBooleanToVisibility(bool value); - static winrt::Windows::UI::Xaml::Visibility BooleanToVisibility(bool value); // Numbers static double PercentageToPercentageValue(double value); diff --git a/src/cascadia/UIHelpers/Converters.idl b/src/cascadia/UIHelpers/Converters.idl index 4e2e3e4e10..5cd5b55325 100644 --- a/src/cascadia/UIHelpers/Converters.idl +++ b/src/cascadia/UIHelpers/Converters.idl @@ -10,7 +10,6 @@ namespace Microsoft.Terminal.UI // Booleans static Boolean InvertBoolean(Boolean value); static Windows.UI.Xaml.Visibility InvertedBooleanToVisibility(Boolean value); - static Windows.UI.Xaml.Visibility BooleanToVisibility(Boolean value); // Numbers static Double PercentageToPercentageValue(Double value); diff --git a/tools/GenerateSettingsIndex.ps1 b/tools/GenerateSettingsIndex.ps1 index 1a5d774702..5b1db56a69 100644 --- a/tools/GenerateSettingsIndex.ps1 +++ b/tools/GenerateSettingsIndex.ps1 @@ -106,6 +106,11 @@ $ClassMap = @{ NavigationParam = "AddProfile" SubPage = "BreadcrumbSubPage::None" } + "Microsoft::Terminal::Settings::Editor::Profiles" = @{ + ResourceName = "Nav_Profiles/Content" + NavigationParam = "Profiles_Nav" + SubPage = "BreadcrumbSubPage::None" + } } function IsProfileSubPage($pageClass)