Skip to content

Commit

Permalink
Maintain current Pivot selection when saving on the Profiles page (mi…
Browse files Browse the repository at this point in the history
…crosoft#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 microsoft#8799. Hence why this PR is targeting the other.

## PR Checklist
* [x] I work here
* [x] Tested manually
* [x] Fixes the first point in microsoft#8769
  • Loading branch information
zadjii-msft authored and mpela81 committed Jan 28, 2021
1 parent 1f8e660 commit 0af16dc
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 10 deletions.
28 changes: 22 additions & 6 deletions src/cascadia/TerminalSettingsEditor/MainPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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)
{
Expand All @@ -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) };

// 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<Editor::Profiles>(), state);
contentFrame().Navigate(xaml_typename<Editor::Profiles>(), _profilesNavState);
}

void MainPage::OpenJsonTapped(IInspectable const& /*sender*/, Windows::UI::Xaml::Input::TappedRoutedEventArgs const& /*args*/)
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsEditor/MainPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
void _RefreshCurrentPage();

ColorSchemesPageNavigationState _colorSchemesNavState{ nullptr };
ProfilePageNavigationState _profilesNavState{ nullptr };
};
}

Expand Down
9 changes: 9 additions & 0 deletions src/cascadia/TerminalSettingsEditor/Profiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()));
}

}
25 changes: 23 additions & 2 deletions src/cascadia/TerminalSettingsEditor/Profiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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;
};

Expand All @@ -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);
Expand Down
9 changes: 8 additions & 1 deletion src/cascadia/TerminalSettingsEditor/Profiles.idl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
4 changes: 3 additions & 1 deletion src/cascadia/TerminalSettingsEditor/Profiles.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down

0 comments on commit 0af16dc

Please sign in to comment.