From 1f8e660089e65f44eff61514cafd85e84ddfe24c Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Tue, 19 Jan 2021 13:18:07 -0600 Subject: [PATCH] Persist selected color scheme on navigation; Don't gray-out color swatches (#8799) ## Summary of the Pull Request This PR fixes two of the components of #8765. > * [ ] Edit a color scheme -> Hit 'apply' -> the selected color scheme resets to the first color scheme in the list (instead of the one just edited) This was fixed by storing the navigation state as a singleton in MainPage, and having the color schemes page update the selected scheme on that singleton. That way, a subsequent navigation to the schemes page could re-use the existing state. > * [ ] The buttons turn gray on rollover covering up what color I'm looking at (I have dark mode) This one was tricky. We're binding the resource for this button, to the color the button is bound to. We're also running a converter on that color, as to change the alpha slightly. This allows us to still have visual feedback on pointerover, without obscuring the color entirely. ## PR Checklist * [x] I work here * [x] Tested manually --- .../ColorLightenConverter.cpp | 33 +++++++ .../ColorLightenConverter.h | 9 ++ .../TerminalSettingsEditor/ColorSchemes.cpp | 14 +++ .../TerminalSettingsEditor/ColorSchemes.h | 1 + .../TerminalSettingsEditor/ColorSchemes.idl | 2 + .../TerminalSettingsEditor/ColorSchemes.xaml | 87 +++++++++++++++++++ .../TerminalSettingsEditor/Converters.idl | 6 ++ .../TerminalSettingsEditor/MainPage.cpp | 7 +- .../TerminalSettingsEditor/MainPage.h | 2 + ...Microsoft.Terminal.Settings.Editor.vcxproj | 6 ++ 10 files changed, 166 insertions(+), 1 deletion(-) create mode 100644 src/cascadia/TerminalSettingsEditor/ColorLightenConverter.cpp create mode 100644 src/cascadia/TerminalSettingsEditor/ColorLightenConverter.h diff --git a/src/cascadia/TerminalSettingsEditor/ColorLightenConverter.cpp b/src/cascadia/TerminalSettingsEditor/ColorLightenConverter.cpp new file mode 100644 index 000000000000..093c5ac05860 --- /dev/null +++ b/src/cascadia/TerminalSettingsEditor/ColorLightenConverter.cpp @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +#include "pch.h" +#include "ColorLightenConverter.h" +#include "ColorLightenConverter.g.cpp" + +using namespace winrt::Windows; +using namespace winrt::Windows::UI; +using namespace winrt::Windows::UI::Xaml; +using namespace winrt::Windows::UI::Text; + +namespace winrt::Microsoft::Terminal::Settings::Editor::implementation +{ + Foundation::IInspectable ColorLightenConverter::Convert(Foundation::IInspectable const& value, + Windows::UI::Xaml::Interop::TypeName const& /* targetType */, + Foundation::IInspectable const& /* parameter */, + hstring const& /* language */) + { + auto original = winrt::unbox_value_or(value, Color{ 255, 0, 0, 0 }); + auto result = original; + result.A = 128; // halfway transparent + return winrt::box_value(result); + } + + Foundation::IInspectable ColorLightenConverter::ConvertBack(Foundation::IInspectable const& /*value*/, + Windows::UI::Xaml::Interop::TypeName const& /* targetType */, + Foundation::IInspectable const& /*parameter*/, + hstring const& /* language */) + { + throw hresult_not_implemented(); + } +} diff --git a/src/cascadia/TerminalSettingsEditor/ColorLightenConverter.h b/src/cascadia/TerminalSettingsEditor/ColorLightenConverter.h new file mode 100644 index 000000000000..25d16ef711f4 --- /dev/null +++ b/src/cascadia/TerminalSettingsEditor/ColorLightenConverter.h @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +#pragma once + +#include "ColorLightenConverter.g.h" +#include "../inc/cppwinrt_utils.h" + +DECLARE_CONVERTER(winrt::Microsoft::Terminal::Settings::Editor, ColorLightenConverter); diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp b/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp index c70f6702d414..fdbe9300550e 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemes.cpp @@ -73,6 +73,18 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation auto entry = winrt::make(i, Windows::UI::Color{ 0, 0, 0, 0 }); _CurrentColorTable.Append(entry); } + + // Try to look up the scheme that was navigated to. If we find it, immediately select it. + const std::wstring lastNameFromNav{ _State.LastSelectedScheme() }; + const auto it = std::find_if(begin(_ColorSchemeList), + end(_ColorSchemeList), + [&lastNameFromNav](const auto& scheme) { return scheme.Name() == lastNameFromNav; }); + + if (it != end(_ColorSchemeList)) + { + auto scheme = *it; + ColorSchemeComboBox().SelectedItem(scheme); + } } // Function Description: @@ -90,6 +102,8 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation CurrentColorScheme(colorScheme); _UpdateColorTable(colorScheme); + _State.LastSelectedScheme(colorScheme.Name()); + // Set the text disclaimer for the text box hstring disclaimer{}; const std::wstring schemeName{ colorScheme.Name() }; diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemes.h b/src/cascadia/TerminalSettingsEditor/ColorSchemes.h index bcf13d54d380..dbe819208a43 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemes.h +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemes.h @@ -17,6 +17,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation _Globals{ settings } {} GETSET_PROPERTY(Model::GlobalAppSettings, Globals, nullptr); + GETSET_PROPERTY(winrt::hstring, LastSelectedScheme, L""); }; struct ColorSchemes : ColorSchemesT diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemes.idl b/src/cascadia/TerminalSettingsEditor/ColorSchemes.idl index d5f7f5b85cbc..6a402991174b 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemes.idl +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemes.idl @@ -3,9 +3,11 @@ namespace Microsoft.Terminal.Settings.Editor { + runtimeclass ColorSchemesPageNavigationState { Microsoft.Terminal.Settings.Model.GlobalAppSettings Globals; + String LastSelectedScheme; }; [default_interface] runtimeclass ColorSchemes : Windows.UI.Xaml.Controls.Page, Windows.UI.Xaml.Data.INotifyPropertyChanged diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemes.xaml b/src/cascadia/TerminalSettingsEditor/ColorSchemes.xaml index 1c1951af6b7e..78a301ccfa66 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemes.xaml +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemes.xaml @@ -44,6 +44,8 @@ the MIT License. See LICENSE in the project root for license information. --> + + @@ -139,6 +141,23 @@ the MIT License. See LICENSE in the project root for license information. -->