Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Represent inheritance in Settings UI #8919

Merged
18 commits merged into from
Feb 8, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 50 additions & 42 deletions src/cascadia/TerminalSettingsEditor/Profiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,51 +248,54 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
// Subscribe to some changes in the view model
// These changes should force us to update our own set of "Current<Setting>" members,
// and propagate those changes to the UI
_State.Profile().PropertyChanged([&](auto&&, const PropertyChangedEventArgs& args) {
if (args.PropertyName() == L"CursorShape")
_ViewModelChangedRevoker = _State.Profile().PropertyChanged(winrt::auto_revoke, [weakThis{ get_weak() }](auto&&, const PropertyChangedEventArgs& args) {
carlos-zamora marked this conversation as resolved.
Show resolved Hide resolved
if (auto page{ weakThis.get() })
{
carlos-zamora marked this conversation as resolved.
Show resolved Hide resolved
_PropertyChangedHandlers(*this, PropertyChangedEventArgs{ L"CurrentCursorShape" });
_PropertyChangedHandlers(*this, PropertyChangedEventArgs{ L"IsVintageCursor" });
}
else if (args.PropertyName() == L"BackgroundImageStretchMode")
{
_PropertyChangedHandlers(*this, PropertyChangedEventArgs{ L"CurrentBackgroundImageStretchMode" });
}
else if (args.PropertyName() == L"AntialiasingMode")
{
_PropertyChangedHandlers(*this, PropertyChangedEventArgs{ L"CurrentAntiAliasingMode" });
}
else if (args.PropertyName() == L"CloseOnExit")
{
_PropertyChangedHandlers(*this, PropertyChangedEventArgs{ L"CurrentCloseOnExitMode" });
}
else if (args.PropertyName() == L"BellStyle")
{
_PropertyChangedHandlers(*this, PropertyChangedEventArgs{ L"CurrentBellStyle" });
}
else if (args.PropertyName() == L"ScrollState")
{
_PropertyChangedHandlers(*this, PropertyChangedEventArgs{ L"CurrentScrollState" });
}
else if (args.PropertyName() == L"FontWeight")
{
_PropertyChangedHandlers(*this, PropertyChangedEventArgs{ L"CurrentFontWeight" });
_PropertyChangedHandlers(*this, PropertyChangedEventArgs{ L"IsCustomFontWeight" });
}
else if (args.PropertyName() == L"ColorSchemeName")
{
_PropertyChangedHandlers(*this, PropertyChangedEventArgs{ L"CurrentColorScheme" });
}
else if (args.PropertyName() == L"BackgroundImageAlignment")
{
// reset all of the buttons to unchecked.
// set the one for the value we actually have.
const auto alignment{ static_cast<int32_t>(_State.Profile().BackgroundImageAlignment()) };
for (const auto& biButton : _BIAlignmentButtons)
if (args.PropertyName() == L"CursorShape")
{
page->_PropertyChangedHandlers(*page, PropertyChangedEventArgs{ L"CurrentCursorShape" });
page->_PropertyChangedHandlers(*page, PropertyChangedEventArgs{ L"IsVintageCursor" });
}
else if (args.PropertyName() == L"BackgroundImageStretchMode")
{
page->_PropertyChangedHandlers(*page, PropertyChangedEventArgs{ L"CurrentBackgroundImageStretchMode" });
}
else if (args.PropertyName() == L"AntialiasingMode")
{
page->_PropertyChangedHandlers(*page, PropertyChangedEventArgs{ L"CurrentAntiAliasingMode" });
}
else if (args.PropertyName() == L"CloseOnExit")
{
page->_PropertyChangedHandlers(*page, PropertyChangedEventArgs{ L"CurrentCloseOnExitMode" });
}
else if (args.PropertyName() == L"BellStyle")
{
page->_PropertyChangedHandlers(*page, PropertyChangedEventArgs{ L"CurrentBellStyle" });
}
else if (args.PropertyName() == L"ScrollState")
{
if (const auto& biButtonAlignment{ biButton.Tag().try_as<int32_t>() })
page->_PropertyChangedHandlers(*page, PropertyChangedEventArgs{ L"CurrentScrollState" });
}
else if (args.PropertyName() == L"FontWeight")
{
page->_PropertyChangedHandlers(*page, PropertyChangedEventArgs{ L"CurrentFontWeight" });
page->_PropertyChangedHandlers(*page, PropertyChangedEventArgs{ L"IsCustomFontWeight" });
}
else if (args.PropertyName() == L"ColorSchemeName")
{
page->_PropertyChangedHandlers(*page, PropertyChangedEventArgs{ L"CurrentColorScheme" });
carlos-zamora marked this conversation as resolved.
Show resolved Hide resolved
}
else if (args.PropertyName() == L"BackgroundImageAlignment")
{
// reset all of the buttons to unchecked.
// set the one for the value we actually have.
const auto alignment{ static_cast<int32_t>(page->_State.Profile().BackgroundImageAlignment()) };
for (const auto& biButton : page->_BIAlignmentButtons)
{
biButton.IsChecked(biButtonAlignment == alignment);
if (const auto& biButtonAlignment{ biButton.Tag().try_as<int32_t>() })
{
biButton.IsChecked(biButtonAlignment == alignment);
}
}
}
}
Expand All @@ -302,6 +305,11 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
ProfilesPivot().SelectedIndex(static_cast<int>(_State.LastActivePivot()));
}

void Profiles::OnNavigatedFrom(const NavigationEventArgs& /*e*/)
{
_ViewModelChangedRevoker.revoke();
}

ColorScheme Profiles::CurrentColorScheme()
{
const auto schemeName{ _State.Profile().ColorSchemeName() };
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalSettingsEditor/Profiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
Profiles();

void OnNavigatedTo(const Windows::UI::Xaml::Navigation::NavigationEventArgs& e);
void OnNavigatedFrom(const Windows::UI::Xaml::Navigation::NavigationEventArgs& e);

Model::ColorScheme CurrentColorScheme();
void CurrentColorScheme(const Model::ColorScheme& val);
Expand Down Expand Up @@ -167,6 +168,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
Windows::Foundation::Collections::IMap<uint16_t, Microsoft::Terminal::Settings::Editor::EnumEntry> _FontWeightMap;
Editor::EnumEntry _CustomFontWeight{ nullptr };
std::array<Windows::UI::Xaml::Controls::Primitives::ToggleButton, 9> _BIAlignmentButtons;
Windows::UI::Xaml::Data::INotifyPropertyChanged::PropertyChanged_revoker _ViewModelChangedRevoker;
};
};

Expand Down
18 changes: 9 additions & 9 deletions src/cascadia/TerminalSettingsEditor/Profiles.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ the MIT License. See LICENSE in the project root for license information. -->
<StackPanel Orientation="Horizontal">
<TextBox x:Name="Commandline"
Text="{x:Bind State.Profile.Commandline, Mode=TwoWay}"
AutomationProperties.Name="{Binding CommandlineContainer.HeaderText}"
AutomationProperties.Name="{Binding CommandlineContainer.Header}"
AutomationProperties.HelpText="{Binding CommandlineContainer.HelpText}"
Style="{StaticResource TextBoxSettingStyle}"/>
<Button x:Uid="Profile_CommandlineBrowse"
Expand All @@ -101,7 +101,7 @@ the MIT License. See LICENSE in the project root for license information. -->
<TextBox x:Name="StartingDirectory"
Text="{x:Bind State.Profile.StartingDirectory, Mode=TwoWay}"
IsEnabled="{x:Bind State.Profile.UseCustomStartingDirectory, Mode=OneWay}"
AutomationProperties.Name="{Binding StartingDirectoryContainer.HeaderText}"
AutomationProperties.Name="{Binding StartingDirectoryContainer.Header}"
AutomationProperties.HelpText="{Binding StartingDirectoryContainer.HelpText}"
Style="{StaticResource TextBoxSettingStyle}"/>
<Button x:Uid="Profile_StartingDirectoryBrowse"
Expand All @@ -125,7 +125,7 @@ the MIT License. See LICENSE in the project root for license information. -->
<TextBox x:Name="Icon"
carlos-zamora marked this conversation as resolved.
Show resolved Hide resolved
Text="{x:Bind State.Profile.Icon, Mode=TwoWay}"
FontFamily="Segoe UI, Segoe MDL2 Assets"
AutomationProperties.Name="{Binding IconContainer.HeaderText}"
AutomationProperties.Name="{Binding IconContainer.Header}"
AutomationProperties.HelpText="{Binding IconContainer.HelpText}"
Style="{StaticResource TextBoxSettingStyle}"/>
<Button x:Uid="Profile_IconBrowse"
Expand Down Expand Up @@ -267,7 +267,7 @@ the MIT License. See LICENSE in the project root for license information. -->
ItemsSource="{x:Bind FontWeightList, Mode=OneWay}"
SelectedItem="{x:Bind CurrentFontWeight, Mode=TwoWay}"
ItemTemplate="{StaticResource EnumComboBoxItemTemplate}"
AutomationProperties.Name="{Binding FontWeightContainer.HeaderText}"
AutomationProperties.Name="{Binding FontWeightContainer.Header}"
AutomationProperties.HelpText="{Binding FontWeightContainer.HelpText}"
Style="{StaticResource ComboBoxSettingStyle}"/>

Expand Down Expand Up @@ -319,8 +319,8 @@ the MIT License. See LICENSE in the project root for license information. -->

<!--Cursor Height-->
<local:SettingContainer x:Uid="Profile_CursorHeight"
HasSettingValue="{x:Bind State.Profile.HasCursorShape, Mode=OneWay}"
ClearSettingValue="{x:Bind State.Profile.ClearCursorShape}"
HasSettingValue="{x:Bind State.Profile.HasCursorHeight, Mode=OneWay}"
ClearSettingValue="{x:Bind State.Profile.ClearCursorHeight}"
Visibility="{x:Bind IsVintageCursor, Mode=OneWay}">
<muxc:NumberBox Value="{x:Bind State.Profile.CursorHeight, Mode=TwoWay}"
Style="{StaticResource NumberBoxSettingStyle}"
Expand All @@ -344,7 +344,7 @@ the MIT License. See LICENSE in the project root for license information. -->
<TextBox x:Name="BackgroundImage"
Text="{x:Bind State.Profile.BackgroundImagePath, Mode=TwoWay, Converter={StaticResource DesktopWallpaperToEmptyStringConverter}}"
IsEnabled="{x:Bind State.Profile.BackgroundImagePath, Mode=OneWay, Converter={StaticResource StringIsNotDesktopConverter}}"
AutomationProperties.Name="{Binding BackgroundImageContainer.HeaderText}"
AutomationProperties.Name="{Binding BackgroundImageContainer.Header}"
AutomationProperties.HelpText="{Binding BackgroundImageContainer.HelpText}"
Style="{StaticResource TextBoxSettingStyle}"/>
<Button x:Uid="Profile_BackgroundImageBrowse"
Expand Down Expand Up @@ -536,7 +536,7 @@ the MIT License. See LICENSE in the project root for license information. -->
<Slider x:Name="BIOpacitySlider"
Grid.Column="0"
Value="{x:Bind State.Profile.BackgroundImageOpacity, Converter={StaticResource PercentageConverter}, Mode=TwoWay}"
AutomationProperties.Name="{Binding BackgroundImageOpacityContainer.HeaderText}"
AutomationProperties.Name="{Binding BackgroundImageOpacityContainer.Header}"
AutomationProperties.HelpText="{Binding BackgroundImageOpacityContainer.HelpText}"/>
<TextBlock Grid.Column="1"
Text="{Binding ElementName=BIOpacitySlider, Path=Value, Mode=OneWay}"
Expand Down Expand Up @@ -573,7 +573,7 @@ the MIT License. See LICENSE in the project root for license information. -->
<Slider x:Name="AcrylicOpacitySlider"
Grid.Column="0"
Value="{x:Bind State.Profile.AcrylicOpacity, Converter={StaticResource PercentageConverter}, Mode=TwoWay}"
AutomationProperties.Name="{Binding AcrylicOpacityContainer.HeaderText}"
AutomationProperties.Name="{Binding AcrylicOpacityContainer.Header}"
AutomationProperties.HelpText="{Binding AcrylicOpacityContainer.HelpText}"/>
<TextBlock Grid.Column="1"
Text="{Binding ElementName=AcrylicOpacitySlider, Path=Value, Mode=OneWay}"
Expand Down
Loading