diff --git a/src/cascadia/TerminalSettingsEditor/MainPage.cpp b/src/cascadia/TerminalSettingsEditor/MainPage.cpp index ae1088459150..ae765856a572 100644 --- a/src/cascadia/TerminalSettingsEditor/MainPage.cpp +++ b/src/cascadia/TerminalSettingsEditor/MainPage.cpp @@ -51,6 +51,18 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation _InitializeProfilesList(); _colorSchemesNavState = winrt::make(_settingsClone.GlobalSettings()); + + // We have to provide _some_ profile in the profile nav state, so just + // hook it up with the base for now. It'll get updated when we actually + // navigate to a profile. + auto profileVM{ _viewModelForProfile(_settingsClone.ProfileDefaults()) }; + profileVM.IsBaseLayer(true); + _profilesNavState = winrt::make(profileVM, + _settingsClone.GlobalSettings().ColorSchemes(), + *this); + + // Add an event handler for when the user wants to delete a profile. + _profilesNavState.DeleteProfile({ this, &MainPage::_DeleteProfile }); } // Method Description: @@ -98,6 +110,8 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation // Update the Nav State with the new version of the settings _colorSchemesNavState.Globals(_settingsClone.GlobalSettings()); + _profilesNavState.Schemes(_settingsClone.GlobalSettings().ColorSchemes()); + // We'll update the profile in the _profilesNavState whenever we actually navigate to one _RefreshCurrentPage(); } @@ -226,7 +240,11 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation { auto profileVM{ _viewModelForProfile(_settingsClone.ProfileDefaults()) }; profileVM.IsBaseLayer(true); - contentFrame().Navigate(xaml_typename(), winrt::make(profileVM, _settingsClone.GlobalSettings().ColorSchemes(), *this)); + + // Update the profiles navigation state + _profilesNavState.Profile(profileVM); + + contentFrame().Navigate(xaml_typename(), _profilesNavState); } else if (clickedItemTag == colorSchemesTag) { @@ -240,12 +258,10 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation void MainPage::_Navigate(const Editor::ProfileViewModel& profile) { - auto state{ winrt::make(profile, _settingsClone.GlobalSettings().ColorSchemes(), *this) }; - - // Add an event handler for when the user wants to delete a profile. - state.DeleteProfile({ this, &MainPage::_DeleteProfile }); + // Update the profiles navigation state + _profilesNavState.Profile(profile); - contentFrame().Navigate(xaml_typename(), state); + contentFrame().Navigate(xaml_typename(), _profilesNavState); } void MainPage::OpenJsonTapped(IInspectable const& /*sender*/, Windows::UI::Xaml::Input::TappedRoutedEventArgs const& /*args*/) diff --git a/src/cascadia/TerminalSettingsEditor/MainPage.h b/src/cascadia/TerminalSettingsEditor/MainPage.h index 017f1f89fc6e..a89ea9a333a2 100644 --- a/src/cascadia/TerminalSettingsEditor/MainPage.h +++ b/src/cascadia/TerminalSettingsEditor/MainPage.h @@ -43,6 +43,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation void _RefreshCurrentPage(); ColorSchemesPageNavigationState _colorSchemesNavState{ nullptr }; + ProfilePageNavigationState _profilesNavState{ nullptr }; }; } diff --git a/src/cascadia/TerminalSettingsEditor/Profiles.cpp b/src/cascadia/TerminalSettingsEditor/Profiles.cpp index 3072068b148a..a3e0ed2f4208 100644 --- a/src/cascadia/TerminalSettingsEditor/Profiles.cpp +++ b/src/cascadia/TerminalSettingsEditor/Profiles.cpp @@ -185,6 +185,9 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation { StartingDirectoryUseParentCheckbox().IsChecked(true); } + + // Navigate to the pivot in the provided navigation state + ProfilesPivot().SelectedIndex(static_cast(_State.LastActivePivot())); } ColorScheme Profiles::CurrentColorScheme() @@ -366,4 +369,10 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation return _State.Profile().CursorShape() == TerminalControl::CursorStyle::Vintage; } + void Profiles::Pivot_SelectionChanged(Windows::Foundation::IInspectable const& /*sender*/, + Windows::UI::Xaml::RoutedEventArgs const& /*e*/) + { + _State.LastActivePivot(static_cast(ProfilesPivot().SelectedIndex())); + } + } diff --git a/src/cascadia/TerminalSettingsEditor/Profiles.h b/src/cascadia/TerminalSettingsEditor/Profiles.h index 367a2714093e..989991716d41 100644 --- a/src/cascadia/TerminalSettingsEditor/Profiles.h +++ b/src/cascadia/TerminalSettingsEditor/Profiles.h @@ -85,7 +85,9 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation struct ProfilePageNavigationState : ProfilePageNavigationStateT { public: - ProfilePageNavigationState(const Editor::ProfileViewModel& viewModel, const Windows::Foundation::Collections::IMapView& schemes, const IHostedInWindow& windowRoot) : + ProfilePageNavigationState(const Editor::ProfileViewModel& viewModel, + const Windows::Foundation::Collections::IMapView& schemes, + const IHostedInWindow& windowRoot) : _Profile{ viewModel }, _Schemes{ schemes }, _WindowRoot{ windowRoot } @@ -99,9 +101,27 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation TYPED_EVENT(DeleteProfile, Editor::ProfilePageNavigationState, Editor::DeleteProfileEventArgs); GETSET_PROPERTY(IHostedInWindow, WindowRoot, nullptr); - GETSET_PROPERTY(Editor::ProfileViewModel, Profile, nullptr); + GETSET_PROPERTY(Editor::ProfilesPivots, LastActivePivot, Editor::ProfilesPivots::General); + + public: + // Manually define Profile(), so we can overload the setter + Editor::ProfileViewModel Profile() const noexcept { return _Profile; } + + void Profile(const Editor::ProfileViewModel& value) noexcept + { + // If the profile has a different guid than the new one, then reset + // the selected pivot to the "General" tab. + const auto& oldGuid = _Profile.Guid(); + const auto& newGuid = value.Guid(); + if (oldGuid != newGuid) + { + _LastActivePivot = Editor::ProfilesPivots::General; + } + _Profile = value; + } private: + Editor::ProfileViewModel _Profile{ nullptr }; Windows::Foundation::Collections::IMapView _Schemes; }; @@ -123,6 +143,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation void DeleteConfirmation_Click(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& e); void UseParentProcessDirectory_Check(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& e); void UseParentProcessDirectory_Uncheck(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& e); + void Pivot_SelectionChanged(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& e); // CursorShape visibility logic void CursorShape_Changed(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& e); diff --git a/src/cascadia/TerminalSettingsEditor/Profiles.idl b/src/cascadia/TerminalSettingsEditor/Profiles.idl index 9081a44ce0d9..6b7b476f24cf 100644 --- a/src/cascadia/TerminalSettingsEditor/Profiles.idl +++ b/src/cascadia/TerminalSettingsEditor/Profiles.idl @@ -60,12 +60,19 @@ namespace Microsoft.Terminal.Settings.Editor Guid ProfileGuid { get; }; } + enum ProfilesPivots { + General = 0, + Appearance = 1, + Advanced = 2 + }; + runtimeclass ProfilePageNavigationState { Windows.Foundation.Collections.IMapView Schemes; IHostedInWindow WindowRoot; // necessary to send the right HWND into the file picker dialogs. - ProfileViewModel Profile { get; }; + ProfileViewModel Profile; + ProfilesPivots LastActivePivot; event Windows.Foundation.TypedEventHandler DeleteProfile; }; diff --git a/src/cascadia/TerminalSettingsEditor/Profiles.xaml b/src/cascadia/TerminalSettingsEditor/Profiles.xaml index c916df3c6ac9..765c404c1a1e 100644 --- a/src/cascadia/TerminalSettingsEditor/Profiles.xaml +++ b/src/cascadia/TerminalSettingsEditor/Profiles.xaml @@ -50,8 +50,10 @@ the MIT License. See LICENSE in the project root for license information. --> Style="{StaticResource DisclaimerStyle}" Visibility="{x:Bind State.Profile.IsBaseLayer}"/> -