From 31e69720549e1508715815bc99fc64d101d71ba8 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Mon, 18 Jan 2021 16:34:07 -0600 Subject: [PATCH] Polish the Background Image settings (#8778) ## 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 #8763 * [x] I work here ## Validation Steps Performed Tested manually --- .../ColorToBrushConverter.idl | 10 --- .../ColorToHexConverter.idl | 10 --- .../TerminalSettingsEditor/Converters.idl | 45 +++++++++++++ .../FontWeightConverter.idl | 10 --- .../InvertedBooleanToVisibilityConverter.idl | 10 --- ...Microsoft.Terminal.Settings.Editor.vcxproj | 38 ++++++----- ...t.Terminal.Settings.Editor.vcxproj.filters | 16 +---- .../PercentageConverter.idl | 10 --- .../TerminalSettingsEditor/Profiles.cpp | 65 +++++++++++++++++++ .../TerminalSettingsEditor/Profiles.h | 9 ++- .../TerminalSettingsEditor/Profiles.idl | 2 + .../TerminalSettingsEditor/Profiles.xaml | 40 ++++++++---- .../Resources/en-US/Resources.resw | 64 +++++++++--------- .../StringIsEmptyConverter.cpp | 30 +++++++++ .../StringIsEmptyConverter.h | 9 +++ .../StringIsNotDesktopConverter.cpp | 50 ++++++++++++++ .../StringIsNotDesktopConverter.h | 11 ++++ src/cascadia/inc/cppwinrt_utils.h | 24 +++++++ 18 files changed, 332 insertions(+), 121 deletions(-) delete mode 100644 src/cascadia/TerminalSettingsEditor/ColorToBrushConverter.idl delete mode 100644 src/cascadia/TerminalSettingsEditor/ColorToHexConverter.idl create mode 100644 src/cascadia/TerminalSettingsEditor/Converters.idl delete mode 100644 src/cascadia/TerminalSettingsEditor/FontWeightConverter.idl delete mode 100644 src/cascadia/TerminalSettingsEditor/InvertedBooleanToVisibilityConverter.idl delete mode 100644 src/cascadia/TerminalSettingsEditor/PercentageConverter.idl create mode 100644 src/cascadia/TerminalSettingsEditor/StringIsEmptyConverter.cpp create mode 100644 src/cascadia/TerminalSettingsEditor/StringIsEmptyConverter.h create mode 100644 src/cascadia/TerminalSettingsEditor/StringIsNotDesktopConverter.cpp create mode 100644 src/cascadia/TerminalSettingsEditor/StringIsNotDesktopConverter.h diff --git a/src/cascadia/TerminalSettingsEditor/ColorToBrushConverter.idl b/src/cascadia/TerminalSettingsEditor/ColorToBrushConverter.idl deleted file mode 100644 index fb4346e42ef6..000000000000 --- a/src/cascadia/TerminalSettingsEditor/ColorToBrushConverter.idl +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -namespace Microsoft.Terminal.Settings.Editor -{ - runtimeclass ColorToBrushConverter : [default] Windows.UI.Xaml.Data.IValueConverter - { - ColorToBrushConverter(); - }; -} diff --git a/src/cascadia/TerminalSettingsEditor/ColorToHexConverter.idl b/src/cascadia/TerminalSettingsEditor/ColorToHexConverter.idl deleted file mode 100644 index e16d4656ff09..000000000000 --- a/src/cascadia/TerminalSettingsEditor/ColorToHexConverter.idl +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -namespace Microsoft.Terminal.Settings.Editor -{ - runtimeclass ColorToHexConverter : [default] Windows.UI.Xaml.Data.IValueConverter - { - ColorToHexConverter(); - }; -} diff --git a/src/cascadia/TerminalSettingsEditor/Converters.idl b/src/cascadia/TerminalSettingsEditor/Converters.idl new file mode 100644 index 000000000000..ec6e543607b4 --- /dev/null +++ b/src/cascadia/TerminalSettingsEditor/Converters.idl @@ -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(); + }; + +} diff --git a/src/cascadia/TerminalSettingsEditor/FontWeightConverter.idl b/src/cascadia/TerminalSettingsEditor/FontWeightConverter.idl deleted file mode 100644 index 881c9104fd9e..000000000000 --- a/src/cascadia/TerminalSettingsEditor/FontWeightConverter.idl +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -namespace Microsoft.Terminal.Settings.Editor -{ - runtimeclass FontWeightConverter : [default] Windows.UI.Xaml.Data.IValueConverter - { - FontWeightConverter(); - }; -} diff --git a/src/cascadia/TerminalSettingsEditor/InvertedBooleanToVisibilityConverter.idl b/src/cascadia/TerminalSettingsEditor/InvertedBooleanToVisibilityConverter.idl deleted file mode 100644 index 2b218d15b647..000000000000 --- a/src/cascadia/TerminalSettingsEditor/InvertedBooleanToVisibilityConverter.idl +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -namespace Microsoft.Terminal.Settings.Editor -{ - runtimeclass InvertedBooleanToVisibilityConverter : [default] Windows.UI.Xaml.Data.IValueConverter - { - InvertedBooleanToVisibilityConverter(); - }; -} diff --git a/src/cascadia/TerminalSettingsEditor/Microsoft.Terminal.Settings.Editor.vcxproj b/src/cascadia/TerminalSettingsEditor/Microsoft.Terminal.Settings.Editor.vcxproj index af4ef42d7a0c..b83e9de3c444 100644 --- a/src/cascadia/TerminalSettingsEditor/Microsoft.Terminal.Settings.Editor.vcxproj +++ b/src/cascadia/TerminalSettingsEditor/Microsoft.Terminal.Settings.Editor.vcxproj @@ -36,19 +36,25 @@ - ColorToBrushConverter.idl + Converters.idl - ColorToHexConverter.idl + Converters.idl - FontWeightConverter.idl + Converters.idl - InvertedBooleanToVisibilityConverter.idl + Converters.idl + + + Converters.idl + + + Converters.idl - PercentageConverter.idl + Converters.idl EnumEntry.idl @@ -109,19 +115,25 @@ - ColorToBrushConverter.idl + Converters.idl - ColorToHexConverter.idl + Converters.idl - FontWeightConverter.idl + Converters.idl - InvertedBooleanToVisibilityConverter.idl + Converters.idl + + + Converters.idl + + + Converters.idl - PercentageConverter.idl + Converters.idl GlobalAppearance.xaml @@ -154,11 +166,7 @@ - - - - - + GlobalAppearance.xaml diff --git a/src/cascadia/TerminalSettingsEditor/Microsoft.Terminal.Settings.Editor.vcxproj.filters b/src/cascadia/TerminalSettingsEditor/Microsoft.Terminal.Settings.Editor.vcxproj.filters index 95e1ceabc87e..7cd275a7ec1a 100644 --- a/src/cascadia/TerminalSettingsEditor/Microsoft.Terminal.Settings.Editor.vcxproj.filters +++ b/src/cascadia/TerminalSettingsEditor/Microsoft.Terminal.Settings.Editor.vcxproj.filters @@ -16,22 +16,10 @@ - - Converters - - - Converters - - - Converters - - - Converters - - + + Converters - diff --git a/src/cascadia/TerminalSettingsEditor/PercentageConverter.idl b/src/cascadia/TerminalSettingsEditor/PercentageConverter.idl deleted file mode 100644 index 48644f88c5ad..000000000000 --- a/src/cascadia/TerminalSettingsEditor/PercentageConverter.idl +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -namespace Microsoft.Terminal.Settings.Editor -{ - runtimeclass PercentageConverter : [default] Windows.UI.Xaml.Data.IValueConverter - { - PercentageConverter(); - }; -} diff --git a/src/cascadia/TerminalSettingsEditor/Profiles.cpp b/src/cascadia/TerminalSettingsEditor/Profiles.cpp index 3456f1ece439..3072068b148a 100644 --- a/src/cascadia/TerminalSettingsEditor/Profiles.cpp +++ b/src/cascadia/TerminalSettingsEditor/Profiles.cpp @@ -26,6 +26,37 @@ static const std::array 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() }; @@ -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(_Profile.Guid()) }; diff --git a/src/cascadia/TerminalSettingsEditor/Profiles.h b/src/cascadia/TerminalSettingsEditor/Profiles.h index 085840a3e6b9..367a2714093e 100644 --- a/src/cascadia/TerminalSettingsEditor/Profiles.h +++ b/src/cascadia/TerminalSettingsEditor/Profiles.h @@ -15,10 +15,14 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation struct ProfileViewModel : ProfileViewModelT, ViewModelHelper { 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); @@ -62,6 +66,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation private: Model::Profile _profile; + winrt::hstring _lastBgImagePath; }; struct DeleteProfileEventArgs : diff --git a/src/cascadia/TerminalSettingsEditor/Profiles.idl b/src/cascadia/TerminalSettingsEditor/Profiles.idl index d4f626f2903d..9081a44ce0d9 100644 --- a/src/cascadia/TerminalSettingsEditor/Profiles.idl +++ b/src/cascadia/TerminalSettingsEditor/Profiles.idl @@ -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); diff --git a/src/cascadia/TerminalSettingsEditor/Profiles.xaml b/src/cascadia/TerminalSettingsEditor/Profiles.xaml index 696de34f9457..c916df3c6ac9 100644 --- a/src/cascadia/TerminalSettingsEditor/Profiles.xaml +++ b/src/cascadia/TerminalSettingsEditor/Profiles.xaml @@ -30,6 +30,10 @@ the MIT License. See LICENSE in the project root for license information. --> + + + + @@ -291,19 +295,31 @@ the MIT License. See LICENSE in the project root for license information. --> - - -