Skip to content

Commit

Permalink
Polish the Background Image settings (microsoft#8778)
Browse files Browse the repository at this point in the history
## Summary of the Pull Request

Two parts:
* Hide the BG image settings when no image is specified
* Add a checkbox for "Use desktop wallpaper". When that's checked, the BG image path input is hidden. Unchecking that box restores the path to what it was before.

## PR Checklist
* [x] Closes microsoft#8763
* [x] I work here

## Validation Steps Performed
Tested manually
  • Loading branch information
zadjii-msft authored and mpela81 committed Jan 28, 2021
1 parent 0b86e8c commit 31e6972
Show file tree
Hide file tree
Showing 18 changed files with 332 additions and 121 deletions.
10 changes: 0 additions & 10 deletions src/cascadia/TerminalSettingsEditor/ColorToBrushConverter.idl

This file was deleted.

10 changes: 0 additions & 10 deletions src/cascadia/TerminalSettingsEditor/ColorToHexConverter.idl

This file was deleted.

45 changes: 45 additions & 0 deletions src/cascadia/TerminalSettingsEditor/Converters.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

namespace Microsoft.Terminal.Settings.Editor
{
runtimeclass FontWeightConverter : [default] Windows.UI.Xaml.Data.IValueConverter
{
FontWeightConverter();
};

runtimeclass InvertedBooleanToVisibilityConverter : [default] Windows.UI.Xaml.Data.IValueConverter
{
InvertedBooleanToVisibilityConverter();
};

runtimeclass ColorToBrushConverter : [default] Windows.UI.Xaml.Data.IValueConverter
{
ColorToBrushConverter();
};

runtimeclass ColorToHexConverter : [default] Windows.UI.Xaml.Data.IValueConverter
{
ColorToHexConverter();
};

runtimeclass PercentageConverter : [default] Windows.UI.Xaml.Data.IValueConverter
{
PercentageConverter();
};

runtimeclass StringIsEmptyConverter : [default] Windows.UI.Xaml.Data.IValueConverter
{
StringIsEmptyConverter();
};

runtimeclass StringIsNotDesktopConverter : [default] Windows.UI.Xaml.Data.IValueConverter
{
StringIsNotDesktopConverter();
};
runtimeclass DesktopWallpaperToEmptyStringConverter : [default] Windows.UI.Xaml.Data.IValueConverter
{
DesktopWallpaperToEmptyStringConverter();
};

}
10 changes: 0 additions & 10 deletions src/cascadia/TerminalSettingsEditor/FontWeightConverter.idl

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,25 @@
<!-- ========================= Headers ======================== -->
<ItemGroup>
<ClInclude Include="ColorToBrushConverter.h">
<DependentUpon>ColorToBrushConverter.idl</DependentUpon>
<DependentUpon>Converters.idl</DependentUpon>
</ClInclude>
<ClInclude Include="ColorToHexConverter.h">
<DependentUpon>ColorToHexConverter.idl</DependentUpon>
<DependentUpon>Converters.idl</DependentUpon>
</ClInclude>
<ClInclude Include="FontWeightConverter.h">
<DependentUpon>FontWeightConverter.idl</DependentUpon>
<DependentUpon>Converters.idl</DependentUpon>
</ClInclude>
<ClInclude Include="InvertedBooleanToVisibilityConverter.h">
<DependentUpon>InvertedBooleanToVisibilityConverter.idl</DependentUpon>
<DependentUpon>Converters.idl</DependentUpon>
</ClInclude>
<ClInclude Include="StringIsEmptyConverter.h">
<DependentUpon>Converters.idl</DependentUpon>
</ClInclude>
<ClInclude Include="StringIsNotDesktopConverter.h">
<DependentUpon>Converters.idl</DependentUpon>
</ClInclude>
<ClInclude Include="PercentageConverter.h">
<DependentUpon>PercentageConverter.idl</DependentUpon>
<DependentUpon>Converters.idl</DependentUpon>
</ClInclude>
<ClInclude Include="EnumEntry.h">
<DependentUpon>EnumEntry.idl</DependentUpon>
Expand Down Expand Up @@ -109,19 +115,25 @@
<!-- ========================= Cpp Files ======================== -->
<ItemGroup>
<ClCompile Include="ColorToBrushConverter.cpp">
<DependentUpon>ColorToBrushConverter.idl</DependentUpon>
<DependentUpon>Converters.idl</DependentUpon>
</ClCompile>
<ClCompile Include="ColorToHexConverter.cpp">
<DependentUpon>ColorToHexConverter.idl</DependentUpon>
<DependentUpon>Converters.idl</DependentUpon>
</ClCompile>
<ClCompile Include="FontWeightConverter.cpp">
<DependentUpon>FontWeightConverter.idl</DependentUpon>
<DependentUpon>Converters.idl</DependentUpon>
</ClCompile>
<ClCompile Include="InvertedBooleanToVisibilityConverter.cpp">
<DependentUpon>InvertedBooleanToVisibilityConverter.idl</DependentUpon>
<DependentUpon>Converters.idl</DependentUpon>
</ClCompile>
<ClCompile Include="StringIsEmptyConverter.cpp">
<DependentUpon>Converters.idl</DependentUpon>
</ClCompile>
<ClCompile Include="StringIsNotDesktopConverter.cpp">
<DependentUpon>Converters.idl</DependentUpon>
</ClCompile>
<ClCompile Include="PercentageConverter.cpp">
<DependentUpon>PercentageConverter.idl</DependentUpon>
<DependentUpon>Converters.idl</DependentUpon>
</ClCompile>
<ClCompile Include="GlobalAppearance.cpp">
<DependentUpon>GlobalAppearance.xaml</DependentUpon>
Expand Down Expand Up @@ -154,11 +166,7 @@
</ItemGroup>
<!-- ========================= idl Files ======================== -->
<ItemGroup>
<Midl Include="ColorToBrushConverter.idl" />
<Midl Include="ColorToHexConverter.idl" />
<Midl Include="FontWeightConverter.idl" />
<Midl Include="InvertedBooleanToVisibilityConverter.idl" />
<Midl Include="PercentageConverter.idl" />
<Midl Include="Converters.idl" />
<Midl Include="EnumEntry.idl" />
<Midl Include="GlobalAppearance.idl">
<DependentUpon>GlobalAppearance.xaml</DependentUpon>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,10 @@
<ClInclude Include="Utils.h" />
</ItemGroup>
<ItemGroup>
<Midl Include="ColorToBrushConverter.idl">
<Filter>Converters</Filter>
</Midl>
<Midl Include="ColorToHexConverter.idl">
<Filter>Converters</Filter>
</Midl>
<Midl Include="FontWeightConverter.idl">
<Filter>Converters</Filter>
</Midl>
<Midl Include="InvertedBooleanToVisibilityConverter.idl">
<Filter>Converters</Filter>
</Midl>
<Midl Include="PercentageConverter.idl">
<Midl Include="EnumEntry.idl" />
<Midl Include="Converters.idl">
<Filter>Converters</Filter>
</Midl>
<Midl Include="EnumEntry.idl" />
</ItemGroup>
<ItemGroup>
<None Include="TerminalSettingsEditor.def" />
Expand Down
10 changes: 0 additions & 10 deletions src/cascadia/TerminalSettingsEditor/PercentageConverter.idl

This file was deleted.

65 changes: 65 additions & 0 deletions src/cascadia/TerminalSettingsEditor/Profiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,37 @@ static const std::array<winrt::guid, 2> InBoxProfileGuids{

namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
{
ProfileViewModel::ProfileViewModel(const Model::Profile& profile) :
_profile{ profile }
{
// Add a property changed handler to our own property changed event.
// When the BackgroundImagePath changes, we _also_ need to change the
// value of UseDesktopBGImage.
//
// We need to do this so if someone manually types "desktopWallpaper"
// into the path TextBox, we properly update the checkbox and stored
// _lastBgImagePath. Without this, then we'll permanently hide the text
// box, prevent it from ever being changed again.
PropertyChanged([this](auto&&, const Data::PropertyChangedEventArgs& args) {
if (args.PropertyName() == L"BackgroundImagePath")
{
_NotifyChanges(L"UseDesktopBGImage", L"BackgroundImageSettingsVisible");
}
else if (args.PropertyName() == L"IsBaseLayer")
{
_NotifyChanges(L"BackgroundImageSettingsVisible");
}
});

// Cache the original BG image path. If the user clicks "Use desktop
// wallpaper", then un-checks it, this is the string we'll restore to
// them.
if (BackgroundImagePath() != L"desktopWallpaper")
{
_lastBgImagePath = BackgroundImagePath();
}
}

bool ProfileViewModel::CanDeleteProfile() const
{
const auto guid{ Guid() };
Expand All @@ -49,6 +80,40 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
}
}

bool ProfileViewModel::UseDesktopBGImage()
{
return BackgroundImagePath() == L"desktopWallpaper";
}

void ProfileViewModel::UseDesktopBGImage(const bool useDesktop)
{
if (useDesktop)
{
// Stash the current value of BackgroundImagePath. If the user
// checks and un-checks the "Use desktop wallpaper" button, we want
// the path that we display in the text box to remain unchanged.
//
// Only stash this value if it's not the special "desktopWallpaper"
// value.
if (BackgroundImagePath() != L"desktopWallpaper")
{
_lastBgImagePath = BackgroundImagePath();
}
BackgroundImagePath(L"desktopWallpaper");
}
else
{
// Restore the path we had previously cached. This might be the
// empty string.
BackgroundImagePath(_lastBgImagePath);
}
}

bool ProfileViewModel::BackgroundImageSettingsVisible()
{
return IsBaseLayer() || BackgroundImagePath() != L"";
}

void ProfilePageNavigationState::DeleteProfile()
{
auto deleteProfileArgs{ winrt::make_self<DeleteProfileEventArgs>(_Profile.Guid()) };
Expand Down
9 changes: 7 additions & 2 deletions src/cascadia/TerminalSettingsEditor/Profiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
struct ProfileViewModel : ProfileViewModelT<ProfileViewModel>, ViewModelHelper<ProfileViewModel>
{
public:
ProfileViewModel(const Model::Profile& profile) :
_profile{ profile } {}
ProfileViewModel(const Model::Profile& profile);

bool CanDeleteProfile() const;

bool UseDesktopBGImage();
void UseDesktopBGImage(const bool useDesktop);
bool BackgroundImageSettingsVisible();

GETSET_PROPERTY(bool, IsBaseLayer, false);

PERMANENT_OBSERVABLE_PROJECTED_SETTING(_profile, Guid);
Expand Down Expand Up @@ -62,6 +66,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation

private:
Model::Profile _profile;
winrt::hstring _lastBgImagePath;
};

struct DeleteProfileEventArgs :
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalSettingsEditor/Profiles.idl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ namespace Microsoft.Terminal.Settings.Editor
{
Boolean CanDeleteProfile { get; };
Boolean IsBaseLayer;
Boolean UseDesktopBGImage;
Boolean BackgroundImageSettingsVisible { get; };

OBSERVABLE_PROJECTED_SETTING(String, Name);
OBSERVABLE_PROJECTED_SETTING(Guid, Guid);
Expand Down
40 changes: 29 additions & 11 deletions src/cascadia/TerminalSettingsEditor/Profiles.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ the MIT License. See LICENSE in the project root for license information. -->
<local:PercentageConverter x:Key="PercentageConverter"/>
<local:FontWeightConverter x:Key="FontWeightConverter"/>
<local:InvertedBooleanToVisibilityConverter x:Key="InvertedBooleanToVisibilityConverter"/>
<local:StringIsEmptyConverter x:Key="StringIsEmptyConverter"/>
<local:StringIsNotDesktopConverter x:Key="StringIsNotDesktopConverter"/>
<local:DesktopWallpaperToEmptyStringConverter x:Key="DesktopWallpaperToEmptyStringConverter"/>

</ResourceDictionary>
</Page.Resources>

Expand Down Expand Up @@ -291,19 +295,31 @@ the MIT License. See LICENSE in the project root for license information. -->

<!--Background Image-->
<ContentPresenter Style="{StaticResource SettingContainerStyle}">
<StackPanel Orientation="Horizontal">
<TextBox x:Uid="Profile_BackgroundImage"
x:Name="BackgroundImage"
Text="{x:Bind State.Profile.BackgroundImagePath, Mode=TwoWay}"
Style="{StaticResource TextBoxSettingStyle}"/>
<Button x:Uid="Profile_BackgroundImageBrowse"
Click="BackgroundImage_Click"
Style="{StaticResource BrowseButtonStyle}"/>
</ContentPresenter>

<ContentPresenter Style="{StaticResource SettingContainerStyle}">
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<TextBox x:Uid="Profile_BackgroundImage"
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}}"
Style="{StaticResource TextBoxSettingStyle}"/>
<Button x:Uid="Profile_BackgroundImageBrowse"
Click="BackgroundImage_Click"
IsEnabled="{x:Bind State.Profile.BackgroundImagePath, Mode=OneWay, Converter={StaticResource StringIsNotDesktopConverter}}"
Style="{StaticResource BrowseButtonStyle}"/>
</StackPanel>
<CheckBox x:Uid="Profile_UseDesktopImage"
x:Name="UseDesktopImageCheckBox"
IsChecked="{x:Bind State.Profile.UseDesktopBGImage, Mode=TwoWay}"
Style="{StaticResource CheckBoxSettingStyle}"/>
</StackPanel>
</ContentPresenter>

<!--Background Image Stretch Mode-->
<ContentPresenter Style="{StaticResource SettingContainerStyle}">
<ContentPresenter Style="{StaticResource SettingContainerStyle}"
Visibility="{x:Bind State.Profile.BackgroundImageSettingsVisible, Mode=OneWay}">
<muxc:RadioButtons x:Uid="Profile_BackgroundImageStretchMode"
ItemsSource="{x:Bind BackgroundImageStretchModeList, Mode=OneWay}"
SelectedItem="{x:Bind CurrentBackgroundImageStretchMode, Mode=TwoWay}"
Expand All @@ -312,7 +328,8 @@ the MIT License. See LICENSE in the project root for license information. -->
</ContentPresenter>

<!--Background Image Alignment-->
<ContentPresenter Style="{StaticResource SettingContainerStyle}">
<ContentPresenter Style="{StaticResource SettingContainerStyle}"
Visibility="{x:Bind State.Profile.BackgroundImageSettingsVisible, Mode=OneWay}">
<StackPanel HorizontalAlignment="Left">
<TextBlock x:Uid="Profile_BackgroundImageAlignment"
Style="{StaticResource CustomSettingHeaderStyle}"
Expand Down Expand Up @@ -468,7 +485,8 @@ the MIT License. See LICENSE in the project root for license information. -->
</ContentPresenter>

<!--Background Image Opacity-->
<ContentPresenter Style="{StaticResource SettingContainerStyle}">
<ContentPresenter Style="{StaticResource SettingContainerStyle}"
Visibility="{x:Bind State.Profile.BackgroundImageSettingsVisible, Mode=OneWay}">
<StackPanel>
<TextBlock x:Uid="Profile_BackgroundImageOpacity"
Style="{StaticResource SliderHeaderStyle}"/>
Expand Down
Loading

0 comments on commit 31e6972

Please sign in to comment.