From 5bc31a1e16bca1772b8692cf8eaf1b7a21a5be0d Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Tue, 7 Jul 2020 16:46:16 -0500 Subject: [PATCH] Add actions missing in schema, descriptions for `toggleRetroEffect` (#6806) ## Summary of the Pull Request In the wake of #6635, a couple things got missed in merges: * `toggleRetroEffect` didn't get into the schema, nor did `renameTab` or `commandPalette`. * `toggleRetroEffect` also didn't get a name Furthermore, I thought it might be a good idea to start sticking commands into `bindings` even without `keys`. So I tried doing that for `opentabColorPicker` and `toggleRetroEffect`, and found immediately that the labels for the key chord still appear even when the text is empty. So I added some XAML magic to hide those when the text is empty. ## References * #6762 * #6691 * #6557 * #6635 ## PR Checklist * [x] Closes #6762 * [x] I work here * [x] Tests added/passed * [n/a] Requires documentation to be updated ## Detailed Description of the Pull Request / Additional comments * See also: https://docs.microsoft.com/en-us/windows/uwp/data-binding/data-binding-quickstart#formatting-or-converting-data-values-for-display - make sure to switch to C++/WinRT at the top! ## Validation Steps Performed Removed all my manual actions, ran the Terminal: ![image](https://user-images.githubusercontent.com/18356694/86652356-f5a79400-bfa9-11ea-9131-5b7d3e835e19.png) --- .github/actions/spell-check/expect/expect.txt | 1 + doc/cascadia/profiles.schema.json | 3 ++ src/cascadia/TerminalApp/ActionAndArgs.cpp | 1 + .../CommandKeyChordVisibilityConverter.cpp | 38 +++++++++++++++++++ .../CommandKeyChordVisibilityConverter.h | 27 +++++++++++++ .../CommandKeyChordVisibilityConverter.idl | 19 ++++++++++ src/cascadia/TerminalApp/CommandPalette.xaml | 9 +++++ .../Resources/en-US/Resources.resw | 7 +++- src/cascadia/TerminalApp/defaults.json | 4 +- .../TerminalApp/lib/TerminalAppLib.vcxproj | 7 ++++ 10 files changed, 113 insertions(+), 3 deletions(-) create mode 100644 src/cascadia/TerminalApp/CommandKeyChordVisibilityConverter.cpp create mode 100644 src/cascadia/TerminalApp/CommandKeyChordVisibilityConverter.h create mode 100644 src/cascadia/TerminalApp/CommandKeyChordVisibilityConverter.idl diff --git a/.github/actions/spell-check/expect/expect.txt b/.github/actions/spell-check/expect/expect.txt index 6c626fcc186..47a511eefa6 100644 --- a/.github/actions/spell-check/expect/expect.txt +++ b/.github/actions/spell-check/expect/expect.txt @@ -1147,6 +1147,7 @@ IUI IUia IUnknown ivalid +IValue IVector IWait iwch diff --git a/doc/cascadia/profiles.schema.json b/doc/cascadia/profiles.schema.json index 2817e9dfa4f..799a0c5fe25 100644 --- a/doc/cascadia/profiles.schema.json +++ b/doc/cascadia/profiles.schema.json @@ -55,9 +55,12 @@ "splitPane", "switchToTab", "toggleFullscreen", + "toggleRetroEffect", "find", "setTabColor", "openTabColorPicker", + "renameTab", + "commandPalette", "unbound" ], "type": "string" diff --git a/src/cascadia/TerminalApp/ActionAndArgs.cpp b/src/cascadia/TerminalApp/ActionAndArgs.cpp index f0c40bcf5c3..f28bd511c9e 100644 --- a/src/cascadia/TerminalApp/ActionAndArgs.cpp +++ b/src/cascadia/TerminalApp/ActionAndArgs.cpp @@ -251,6 +251,7 @@ namespace winrt::TerminalApp::implementation { ShortcutAction::ResizePane, RS_(L"ResizePaneCommandKey") }, { ShortcutAction::MoveFocus, RS_(L"MoveFocusCommandKey") }, { ShortcutAction::OpenSettings, RS_(L"OpenSettingsCommandKey") }, + { ShortcutAction::ToggleRetroEffect, RS_(L"ToggleRetroEffectCommandKey") }, { ShortcutAction::ToggleFullscreen, RS_(L"ToggleFullscreenCommandKey") }, { ShortcutAction::SplitPane, RS_(L"SplitPaneCommandKey") }, { ShortcutAction::Invalid, L"" }, diff --git a/src/cascadia/TerminalApp/CommandKeyChordVisibilityConverter.cpp b/src/cascadia/TerminalApp/CommandKeyChordVisibilityConverter.cpp new file mode 100644 index 00000000000..24af0da0029 --- /dev/null +++ b/src/cascadia/TerminalApp/CommandKeyChordVisibilityConverter.cpp @@ -0,0 +1,38 @@ +#include "pch.h" +#include "CommandKeyChordVisibilityConverter.h" +#include "CommandKeyChordVisibilityConverter.g.cpp" + +using namespace winrt::Windows; +using namespace winrt::Windows::UI::Xaml; + +namespace winrt::TerminalApp::implementation +{ + // Method Description: + // - Attempt to convert something into another type. For the + // CommandKeyChordVisibilityConverter, we're gonna check if `value` is a + // string, and try and convert it into a Visibility value. If the input + // param wasn't a string, or was the empty string, we'll return + // Visibility::Collapsed. Otherwise, we'll return Visible. + + // Arguments: + // - value: the input object to attempt to convert into a Visibility. + // Return Value: + // - Visible if the object was a string and wasn't the empty string. + Foundation::IInspectable CommandKeyChordVisibilityConverter::Convert(Foundation::IInspectable const& value, + Windows::UI::Xaml::Interop::TypeName const& /* targetType */, + Foundation::IInspectable const& /* parameter */, + hstring const& /* language */) + { + const auto& name = winrt::unbox_value_or(value, L""); + return winrt::box_value(name.empty() ? Visibility::Collapsed : Visibility::Visible); + } + + // unused for one-way bindings + Foundation::IInspectable CommandKeyChordVisibilityConverter::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/TerminalApp/CommandKeyChordVisibilityConverter.h b/src/cascadia/TerminalApp/CommandKeyChordVisibilityConverter.h new file mode 100644 index 00000000000..298f6ac0a0f --- /dev/null +++ b/src/cascadia/TerminalApp/CommandKeyChordVisibilityConverter.h @@ -0,0 +1,27 @@ +#pragma once + +#include "CommandKeyChordVisibilityConverter.g.h" +#include "..\inc\cppwinrt_utils.h" + +namespace winrt::TerminalApp::implementation +{ + struct CommandKeyChordVisibilityConverter : CommandKeyChordVisibilityConverterT + { + CommandKeyChordVisibilityConverter() = default; + + Windows::Foundation::IInspectable Convert(Windows::Foundation::IInspectable const& value, + Windows::UI::Xaml::Interop::TypeName const& targetType, + Windows::Foundation::IInspectable const& parameter, + hstring const& language); + + Windows::Foundation::IInspectable ConvertBack(Windows::Foundation::IInspectable const& value, + Windows::UI::Xaml::Interop::TypeName const& targetType, + Windows::Foundation::IInspectable const& parameter, + hstring const& language); + }; +} + +namespace winrt::TerminalApp::factory_implementation +{ + BASIC_FACTORY(CommandKeyChordVisibilityConverter); +} diff --git a/src/cascadia/TerminalApp/CommandKeyChordVisibilityConverter.idl b/src/cascadia/TerminalApp/CommandKeyChordVisibilityConverter.idl new file mode 100644 index 00000000000..b293224e64d --- /dev/null +++ b/src/cascadia/TerminalApp/CommandKeyChordVisibilityConverter.idl @@ -0,0 +1,19 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +namespace TerminalApp +{ + // See https://docs.microsoft.com/en-us/windows/uwp/data-binding/data-binding-quickstart + + // We use the default attribute to declare IValueConverter as the default + // interface. In the listing, CommandKeyChordVisibilityConverter has only a + // constructor, and no methods, so no default interface is generated for it. + // The default attribute is optimal if you won't be adding instance members + // to CommandKeyChordVisibilityConverter, because no QueryInterface will be + // required to call the IValueConverter methods + runtimeclass CommandKeyChordVisibilityConverter : [default] Windows.UI.Xaml.Data.IValueConverter + { + CommandKeyChordVisibilityConverter(); + }; + +} diff --git a/src/cascadia/TerminalApp/CommandPalette.xaml b/src/cascadia/TerminalApp/CommandPalette.xaml index 86cd6e2edce..db795b7e6d2 100644 --- a/src/cascadia/TerminalApp/CommandPalette.xaml +++ b/src/cascadia/TerminalApp/CommandPalette.xaml @@ -19,6 +19,9 @@ the MIT License. See LICENSE in the project root for license information. --> adds it conditionally --> + + +