Maintain current Pivot selection when saving on the Profiles page (#8803)

This PR Makes sure that after you save the settings, we stay on the same part of the profiles pivot. We do this by having a singleton `ProfilesNavigationState`, a bit like the color scheme one in #8799. Hence why this PR is targeting the other.

## PR Checklist
* [x] I work here
* [x] Tested manually
* [x] Fixes the first point in #8769
This commit is contained in:
Mike Griese 2021-01-19 15:55:06 -06:00 committed by GitHub
parent 9293867a06
commit a7d7362b95
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 66 additions and 10 deletions

View file

@ -51,6 +51,18 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
_InitializeProfilesList();
_colorSchemesNavState = winrt::make<ColorSchemesPageNavigationState>(_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<ProfilePageNavigationState>(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<Editor::Profiles>(), winrt::make<ProfilePageNavigationState>(profileVM, _settingsClone.GlobalSettings().ColorSchemes(), *this));
// Update the profiles navigation state
_profilesNavState.Profile(profileVM);
contentFrame().Navigate(xaml_typename<Editor::Profiles>(), _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<ProfilePageNavigationState>(profile, _settingsClone.GlobalSettings().ColorSchemes(), *this) };
// Update the profiles navigation state
_profilesNavState.Profile(profile);
// Add an event handler for when the user wants to delete a profile.
state.DeleteProfile({ this, &MainPage::_DeleteProfile });
contentFrame().Navigate(xaml_typename<Editor::Profiles>(), state);
contentFrame().Navigate(xaml_typename<Editor::Profiles>(), _profilesNavState);
}
void MainPage::OpenJsonTapped(IInspectable const& /*sender*/, Windows::UI::Xaml::Input::TappedRoutedEventArgs const& /*args*/)

View file

@ -43,6 +43,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
void _RefreshCurrentPage();
ColorSchemesPageNavigationState _colorSchemesNavState{ nullptr };
ProfilePageNavigationState _profilesNavState{ nullptr };
};
}

View file

@ -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<int>(_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<Editor::ProfilesPivots>(ProfilesPivot().SelectedIndex()));
}
}

View file

@ -85,7 +85,9 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
struct ProfilePageNavigationState : ProfilePageNavigationStateT<ProfilePageNavigationState>
{
public:
ProfilePageNavigationState(const Editor::ProfileViewModel& viewModel, const Windows::Foundation::Collections::IMapView<hstring, Model::ColorScheme>& schemes, const IHostedInWindow& windowRoot) :
ProfilePageNavigationState(const Editor::ProfileViewModel& viewModel,
const Windows::Foundation::Collections::IMapView<hstring, Model::ColorScheme>& 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<hstring, Model::ColorScheme> _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);

View file

@ -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<String, Microsoft.Terminal.Settings.Model.ColorScheme> 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<ProfilePageNavigationState, DeleteProfileEventArgs> DeleteProfile;
};

View file

@ -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}"/>
<Pivot HorizontalAlignment="Left"
<Pivot x:Name="ProfilesPivot"
HorizontalAlignment="Left"
Grid.Row="1"
SelectionChanged="Pivot_SelectionChanged"
Margin="{StaticResource PivotIndentMargin}">
<!-- General Tab -->
<PivotItem x:Uid="Profile_General">