Skip to content

Commit

Permalink
Revert "Maintain current Pivot selection when saving on the Profiles …
Browse files Browse the repository at this point in the history
…page (#8803)"

This reverts commit a7d7362.
  • Loading branch information
carlos-zamora committed Jan 21, 2021
1 parent 9c4950c commit a803f6a
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 66 deletions.
28 changes: 6 additions & 22 deletions src/cascadia/TerminalSettingsEditor/MainPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,6 @@ 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 @@ -123,8 +111,6 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
_InitializeProfilesList();
// 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

// now that the menuItems are repopulated,
// refresh the current page using the SelectedItem data we collected before the refresh
Expand Down Expand Up @@ -269,11 +255,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
{
auto profileVM{ _viewModelForProfile(_settingsClone.ProfileDefaults()) };
profileVM.IsBaseLayer(true);

// Update the profiles navigation state
_profilesNavState.Profile(profileVM);

contentFrame().Navigate(xaml_typename<Editor::Profiles>(), _profilesNavState);
contentFrame().Navigate(xaml_typename<Editor::Profiles>(), winrt::make<ProfilePageNavigationState>(profileVM, _settingsClone.GlobalSettings().ColorSchemes(), *this));
}
else if (clickedItemTag == colorSchemesTag)
{
Expand All @@ -287,10 +269,12 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation

void MainPage::_Navigate(const Editor::ProfileViewModel& profile)
{
// Update the profiles navigation state
_profilesNavState.Profile(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 });

contentFrame().Navigate(xaml_typename<Editor::Profiles>(), _profilesNavState);
contentFrame().Navigate(xaml_typename<Editor::Profiles>(), state);
}

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

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

Expand Down
9 changes: 0 additions & 9 deletions src/cascadia/TerminalSettingsEditor/Profiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,6 @@ 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 @@ -369,10 +366,4 @@ 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: 2 additions & 23 deletions src/cascadia/TerminalSettingsEditor/Profiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ 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 @@ -101,27 +99,9 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation

TYPED_EVENT(DeleteProfile, Editor::ProfilePageNavigationState, Editor::DeleteProfileEventArgs);
GETSET_PROPERTY(IHostedInWindow, WindowRoot, 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;
}
GETSET_PROPERTY(Editor::ProfileViewModel, Profile, nullptr);

private:
Editor::ProfileViewModel _Profile{ nullptr };
Windows::Foundation::Collections::IMapView<hstring, Model::ColorScheme> _Schemes;
};

Expand All @@ -143,7 +123,6 @@ 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: 1 addition & 8 deletions src/cascadia/TerminalSettingsEditor/Profiles.idl
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,12 @@ 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;
ProfilesPivots LastActivePivot;
ProfileViewModel Profile { get; };

event Windows.Foundation.TypedEventHandler<ProfilePageNavigationState, DeleteProfileEventArgs> DeleteProfile;
};
Expand Down
4 changes: 1 addition & 3 deletions src/cascadia/TerminalSettingsEditor/Profiles.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ the MIT License. See LICENSE in the project root for license information. -->
Style="{StaticResource DisclaimerStyle}"
Visibility="{x:Bind State.Profile.IsBaseLayer}"/>

<Pivot x:Name="ProfilesPivot"
HorizontalAlignment="Left"
<Pivot HorizontalAlignment="Left"
Grid.Row="1"
SelectionChanged="Pivot_SelectionChanged"
Margin="1,0,0,0">
<!-- General Tab -->
<PivotItem x:Uid="Profile_General">
Expand Down

0 comments on commit a803f6a

Please sign in to comment.