Compare commits

...

4 Commits

Author SHA1 Message Date
Carlos Zamora
03dfed4d54 const 2026-05-12 15:10:39 -07:00
Carlos Zamora
5a45c8d7e4 improve "view all" UI; consistently use "shortcut" 2026-05-12 14:37:26 -07:00
Carlos Zamora
76f89bff04 polish 2026-05-11 21:08:30 -07:00
Carlos Zamora
a7aefad0ba Add containers to Actions page 2026-05-11 19:06:07 -07:00
15 changed files with 915 additions and 709 deletions

View File

@@ -7,7 +7,9 @@
#include "LibraryResources.h"
#include "../TerminalSettingsModel/AllShortcutActions.h"
using namespace winrt::Windows::Foundation;
using namespace winrt::Windows::UI::Xaml;
using namespace winrt::Windows::UI::Xaml::Controls;
using namespace winrt::Windows::UI::Xaml::Navigation;
namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
@@ -42,4 +44,65 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES),
TelemetryPrivacyDataTag(PDT_ProductAndServiceUsage));
}
// Builds the "view all" flyout lazily on the first click of a
// row's "..." button, then caches it on the button so subsequent clicks
// just re-show it.
void Actions::ViewAllKeyChordsButton_Click(const IInspectable& sender, const RoutedEventArgs& /*e*/)
{
const auto button = sender.try_as<Button>();
if (!button)
{
return;
}
// Retrieve cached flyout, if possible
if (const auto existing = button.Flyout())
{
existing.ShowAt(button);
return;
}
const auto cmdVM = button.DataContext().try_as<Editor::CommandViewModel>();
if (!cmdVM)
{
return;
}
Flyout flyout;
flyout.Placement(Primitives::FlyoutPlacementMode::Bottom);
flyout.FlyoutPresenterStyle(Resources().Lookup(box_value(L"EdgeToEdgeFlyoutPresenterStyle")).as<winrt::Windows::UI::Xaml::Style>());
StackPanel content;
content.Orientation(Orientation::Vertical);
content.MinWidth(120.0);
if (cmdVM.HasNoKeyChords())
{
const auto emptyTemplate = Resources().Lookup(box_value(L"ViewAllKeyChordsFlyoutEmptyStateTemplate")).as<DataTemplate>();
content.Children().Append(emptyTemplate.LoadContent().as<UIElement>());
}
else
{
const auto separatorTemplate = Resources().Lookup(box_value(L"ViewAllKeyChordsFlyoutSeparatorTemplate")).as<DataTemplate>();
const auto itemTemplate = Resources().Lookup(box_value(L"ViewAllKeyChordsFlyoutItemTemplate")).as<DataTemplate>();
const auto chords = cmdVM.KeyChordList();
const auto count = chords.Size();
for (uint32_t i = 0; i < count; ++i)
{
if (i > 0)
{
content.Children().Append(separatorTemplate.LoadContent().as<UIElement>());
}
auto chordVisual = itemTemplate.LoadContent().as<Editor::KeyChordVisual>();
chordVisual.KeyChord(chords.GetAt(i).CurrentKeys());
content.Children().Append(chordVisual);
}
}
flyout.Content(content);
button.Flyout(flyout);
flyout.ShowAt(button);
}
}

View File

@@ -17,6 +17,8 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
void OnNavigatedTo(const winrt::Windows::UI::Xaml::Navigation::NavigationEventArgs& e);
void ViewAllKeyChordsButton_Click(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::UI::Xaml::RoutedEventArgs& e);
til::property_changed_event PropertyChanged;
WINRT_OBSERVABLE_PROPERTY(Editor::ActionsViewModel, ViewModel, PropertyChanged.raise, nullptr);

View File

@@ -8,7 +8,6 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:Microsoft.Terminal.Settings.Editor"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mtu="using:Microsoft.Terminal.UI"
mc:Ignorable="d">
<Page.Resources>
@@ -17,182 +16,116 @@
<ResourceDictionary Source="CommonResources.xaml" />
</ResourceDictionary.MergedDictionaries>
<!-- Theme Dictionary -->
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Dark">
<!-- TextBox colors ! -->
<SolidColorBrush x:Key="TextControlBackground"
Color="#333333" />
<SolidColorBrush x:Key="TextBoxPlaceholderTextThemeBrush"
Color="#B5B5B5" />
<SolidColorBrush x:Key="TextControlForeground"
Color="#B5B5B5" />
<SolidColorBrush x:Key="TextControlBorderBrush"
Color="#404040" />
<SolidColorBrush x:Key="TextControlButtonForeground"
Color="#B5B5B5" />
<SolidColorBrush x:Key="TextControlBackgroundPointerOver"
Color="#404040" />
<SolidColorBrush x:Key="TextControlForegroundPointerOver"
Color="#FFFFFF" />
<SolidColorBrush x:Key="TextControlBorderBrushPointerOver"
Color="#404040" />
<SolidColorBrush x:Key="TextControlButtonForegroundPointerOver"
Color="#FF4343" />
<SolidColorBrush x:Key="TextControlBackgroundFocused"
Color="#333333" />
<SolidColorBrush x:Key="TextControlForegroundFocused"
Color="#FFFFFF" />
<SolidColorBrush x:Key="TextControlBorderBrushFocused"
Color="#404040" />
<SolidColorBrush x:Key="TextControlButtonForegroundPressed"
Color="#FFFFFF" />
<SolidColorBrush x:Key="TextControlButtonBackgroundPressed"
Color="#FF4343" />
<!-- KeyChordText styles -->
<Style x:Key="KeyChordBorderStyle"
TargetType="Border">
<Setter Property="BorderThickness" Value="1" />
<Setter Property="CornerRadius" Value="{StaticResource ControlCornerRadius}" />
<Setter Property="Background" Value="{ThemeResource SystemAltMediumLowColor}" />
<Setter Property="BorderBrush" Value="{ThemeResource SystemControlForegroundBaseMediumBrush}" />
</Style>
<Style x:Key="KeyChordTextBlockStyle"
TargetType="TextBlock">
<Setter Property="Foreground" Value="{ThemeResource SystemControlForegroundBaseMediumBrush}" />
</Style>
</ResourceDictionary>
<ResourceDictionary x:Key="Light">
<!-- TextBox colors ! -->
<SolidColorBrush x:Key="TextControlBackground"
Color="#CCCCCC" />
<SolidColorBrush x:Key="TextBoxPlaceholderTextThemeBrush"
Color="#636363" />
<SolidColorBrush x:Key="TextControlBorderBrush"
Color="#636363" />
<SolidColorBrush x:Key="TextControlButtonForeground"
Color="#636363" />
<SolidColorBrush x:Key="TextControlBackgroundPointerOver"
Color="#DADADA" />
<SolidColorBrush x:Key="TextControlBorderBrushPointerOver"
Color="#636363" />
<SolidColorBrush x:Key="TextControlButtonForegroundPointerOver"
Color="#FF4343" />
<SolidColorBrush x:Key="TextControlBackgroundFocused"
Color="#CCCCCC" />
<SolidColorBrush x:Key="TextControlBorderBrushFocused"
Color="#636363" />
<SolidColorBrush x:Key="TextControlButtonForegroundPressed"
Color="#FFFFFF" />
<SolidColorBrush x:Key="TextControlButtonBackgroundPressed"
Color="#FF4343" />
<!-- KeyChordText styles -->
<Style x:Key="KeyChordBorderStyle"
TargetType="Border">
<Setter Property="BorderThickness" Value="1" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="CornerRadius" Value="{StaticResource ControlCornerRadius}" />
<Setter Property="Background" Value="{ThemeResource SystemAltMediumLowColor}" />
<Setter Property="BorderBrush" Value="{ThemeResource SystemControlForegroundBaseMediumBrush}" />
</Style>
<Style x:Key="KeyChordTextBlockStyle"
TargetType="TextBlock">
<Setter Property="Foreground" Value="{ThemeResource SystemControlForegroundBaseMediumBrush}" />
</Style>
</ResourceDictionary>
<ResourceDictionary x:Key="HighContrast">
<!-- KeyChordText styles (use XAML defaults for High Contrast theme) -->
<Style x:Key="KeyChordBorderStyle"
TargetType="Border" />
<Style x:Key="KeyChordTextBlockStyle"
TargetType="TextBlock" />
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
<!-- Styles -->
<Style x:Key="KeyBindingContainerStyle"
<Style x:Key="ActionRowItemContainerStyle"
BasedOn="{StaticResource DefaultListViewItemStyle}"
TargetType="ListViewItem">
<Setter Property="Padding" Value="12,4,4,4" />
<Setter Property="Padding" Value="{StaticResource SettingsCardPadding}" />
<Setter Property="MinHeight" Value="{StaticResource SettingsCardMinHeight}" />
<Setter Property="Margin" Value="{StaticResource SettingsCardItemMargin}" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="XYFocusKeyboardNavigation" Value="Enabled" />
<Setter Property="BorderBrush" Value="{ThemeResource ExpanderHeaderBorderBrush}" />
<Setter Property="BorderThickness" Value="{ThemeResource ExpanderHeaderBorderThickness}" />
<Setter Property="CornerRadius" Value="{ThemeResource ControlCornerRadius}" />
</Style>
<Style x:Key="KeyBindingNameTextBlockStyle"
<Style x:Key="ActionRowNameTextStyle"
BasedOn="{StaticResource BaseTextBlockStyle}"
TargetType="TextBlock">
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="FontWeight" Value="Normal" />
<Setter Property="TextWrapping" Value="WrapWholeWords" />
</Style>
<Style x:Key="KeyChordEditorStyle"
TargetType="local:KeyChordListener">
<Setter Property="HorizontalAlignment" Value="Right" />
<Style x:Key="ActionRowSubtleButtonStyle"
BasedOn="{StaticResource DefaultButtonStyle}"
TargetType="Button">
<Setter Property="MinWidth" Value="32" />
<Setter Property="Width" Value="32" />
<Setter Property="Height" Value="32" />
<Setter Property="Padding" Value="0" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="Transparent" />
</Style>
<!-- Converters & Misc. -->
<SolidColorBrush x:Key="ActionContainerBackgroundEditing"
Color="{ThemeResource SystemListMediumColor}" />
<SolidColorBrush x:Key="ActionContainerBackground"
Color="Transparent" />
<!--
FlyoutPresenter style with no internal padding so a full-width Border
separator inside the flyout can reach the flyout's left/right edges.
-->
<Style x:Key="EdgeToEdgeFlyoutPresenterStyle"
BasedOn="{StaticResource DefaultFlyoutPresenterStyle}"
TargetType="FlyoutPresenter">
<Setter Property="Padding" Value="0" />
<Setter Property="ScrollViewer.HorizontalScrollMode" Value="Disabled" />
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" />
</Style>
<!-- Templates -->
<DataTemplate x:Key="ViewAllKeyChordsFlyoutSeparatorTemplate">
<Border Height="1"
Margin="0,4,0,4"
Background="{ThemeResource DividerStrokeColorDefaultBrush}" />
</DataTemplate>
<DataTemplate x:Key="ViewAllKeyChordsFlyoutEmptyStateTemplate">
<TextBlock x:Uid="Actions_NoKeyBindings"
Margin="12,8,12,8"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Style="{StaticResource SecondaryTextBlockStyle}" />
</DataTemplate>
<DataTemplate x:Key="ViewAllKeyChordsFlyoutItemTemplate">
<local:KeyChordVisual Margin="{ThemeResource MenuFlyoutItemThemePaddingNarrow}"
HorizontalAlignment="Right" />
</DataTemplate>
<DataTemplate x:Key="CommandTemplate"
x:DataType="local:CommandViewModel">
<ListViewItem AutomationProperties.Name="{x:Bind DisplayNameAndKeyChordAutomationPropName, Mode=OneWay}"
Style="{StaticResource KeyBindingContainerStyle}">
<Grid ColumnSpacing="8">
<Grid.ColumnDefinitions>
<!-- command name -->
<ColumnDefinition Width="*" />
<!-- key chord -->
<ColumnDefinition Width="auto" />
</Grid.ColumnDefinitions>
<Grid AutomationProperties.Name="{x:Bind DisplayNameAndKeyChordAutomationPropName, Mode=OneWay}"
ColumnSpacing="8">
<Grid.ColumnDefinitions>
<!-- command name -->
<ColumnDefinition Width="*" />
<!-- key chord -->
<ColumnDefinition Width="Auto" />
<!-- edit button -->
<ColumnDefinition Width="Auto" />
<!-- "..." button -->
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<!-- Command Name -->
<TextBlock Grid.Column="0"
FontWeight="Normal"
Style="{StaticResource KeyBindingNameTextBlockStyle}"
Text="{x:Bind DisplayName, Mode=OneWay}" />
<!-- Key Chord Text -->
<Grid Grid.Column="1"
HorizontalAlignment="Right"
VerticalAlignment="Center"
ColumnSpacing="4">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Border Grid.Column="0"
Padding="8,4,8,4"
Style="{ThemeResource KeyChordBorderStyle}"
Visibility="{x:Bind mtu:Converters.StringNotEmptyToVisibility(FirstKeyChordText)}">
<TextBlock FontSize="14"
Style="{ThemeResource KeyChordTextBlockStyle}"
Text="{x:Bind FirstKeyChordText, Mode=OneWay}"
TextWrapping="WrapWholeWords" />
</Border>
<Border Grid.Column="1"
Padding="8,4,8,4"
Style="{ThemeResource KeyChordBorderStyle}"
ToolTipService.ToolTip="{x:Bind AdditionalKeyChordTooltipText, Mode=OneWay}"
Visibility="{x:Bind mtu:Converters.StringNotEmptyToVisibility(AdditionalKeyChordCountText)}">
<TextBlock FontSize="14"
Style="{ThemeResource KeyChordTextBlockStyle}"
Text="{x:Bind AdditionalKeyChordCountText, Mode=OneWay}" />
</Border>
</Grid>
</Grid>
</ListViewItem>
<!-- Command Name -->
<TextBlock Grid.Column="0"
Style="{StaticResource ActionRowNameTextStyle}"
Text="{x:Bind DisplayName, Mode=OneWay}" />
<!-- Key Chord -->
<local:KeyChordVisual Grid.Column="1"
HorizontalAlignment="Right"
KeyChord="{x:Bind FirstKeyChord, Mode=OneWay}" />
<!-- Edit button -->
<Button x:Uid="Actions_EditButton"
Grid.Column="2"
AutomationProperties.Name="{x:Bind DisplayName, Mode=OneWay}"
Click="{x:Bind Edit_Click}"
Style="{StaticResource ActionRowSubtleButtonStyle}">
<FontIcon FontSize="14"
Glyph="&#xE70F;" />
</Button>
<!-- "..." button + flyout -->
<Button x:Uid="Actions_ViewAllKeyChordsButton"
Grid.Column="3"
Click="ViewAllKeyChordsButton_Click"
Style="{StaticResource ActionRowSubtleButtonStyle}">
<FontIcon FontSize="14"
Glyph="&#xE712;" />
</Button>
</Grid>
</DataTemplate>
</ResourceDictionary>
</Page.Resources>
@@ -208,7 +141,8 @@
<!-- Add New Button -->
<Button x:Name="AddNewButton"
Margin="0,12,0,0"
Click="{x:Bind ViewModel.AddNewCommand}">
Click="{x:Bind ViewModel.AddNewCommand}"
Style="{StaticResource AccentButtonStyle}">
<Button.Content>
<StackPanel Orientation="Horizontal">
<FontIcon FontSize="{StaticResource StandardIconSize}"
@@ -221,11 +155,42 @@
<!-- Commands -->
<ListView x:Name="CommandsListView"
Margin="-8,0,0,0"
IsItemClickEnabled="True"
ItemClick="{x:Bind ViewModel.CmdListItemClicked}"
ItemContainerStyle="{StaticResource ActionRowItemContainerStyle}"
ItemTemplate="{StaticResource CommandTemplate}"
ItemsSource="{x:Bind ViewModel.CommandList, Mode=OneWay}" />
ItemsSource="{x:Bind ViewModel.CommandList, Mode=OneWay}"
SelectionMode="None">
<!--
The framework ListViewItemPresenter reads its per-state backgrounds
from these theme resources (not from ListViewItem.Background), so we
override them here to match the card chrome on ActionRowItemContainerStyle.
-->
<ListView.Resources>
<ResourceDictionary>
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Default">
<StaticResource x:Key="ListViewItemBackground"
ResourceKey="ExpanderHeaderBackground" />
<StaticResource x:Key="ListViewItemBackgroundPointerOver"
ResourceKey="ControlFillColorSecondaryBrush" />
<StaticResource x:Key="ListViewItemBackgroundPressed"
ResourceKey="ControlFillColorTertiaryBrush" />
<StaticResource x:Key="ListViewItemBackgroundSelected"
ResourceKey="ExpanderHeaderBackground" />
<StaticResource x:Key="ListViewItemBackgroundSelectedPointerOver"
ResourceKey="ControlFillColorSecondaryBrush" />
<StaticResource x:Key="ListViewItemBackgroundSelectedPressed"
ResourceKey="ControlFillColorTertiaryBrush" />
</ResourceDictionary>
<ResourceDictionary x:Key="HighContrast">
<StaticResource x:Key="ListViewItemBackground"
ResourceKey="SystemColorButtonFaceColorBrush" />
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
</ResourceDictionary>
</ListView.Resources>
</ListView>
</StackPanel>
</Border>
</Page>

View File

@@ -57,13 +57,22 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
return;
}
std::vector<Editor::KeyChordViewModel> keyChordVMs;
int32_t idx = 1;
for (const auto keys : _keyChordList)
{
auto kcVM{ make<KeyChordViewModel>(keys) };
_RegisterKeyChordVMEvents(kcVM);
keyChordVMs.push_back(kcVM);
auto kcVM{ make_self<KeyChordViewModel>(keys) };
kcVM->Index(idx++);
_RegisterKeyChordVMEvents(*kcVM);
keyChordVMs.push_back(*kcVM);
}
_KeyChordList = single_threaded_observable_vector(std::move(keyChordVMs));
_KeyChordList.VectorChanged([weakThis{ get_weak() }](const auto& /*sender*/, const auto& /*args*/) {
if (auto self{ weakThis.get() })
{
self->_ReindexKeyChordList();
self->_NotifyChanges(L"FirstKeyChord", L"FirstKeyChordText", L"AdditionalKeyChordCountText", L"AdditionalKeyChordTooltipText", L"DisplayNameAndKeyChordAutomationPropName");
}
});
std::vector<hstring> shortcutActions;
for (const auto [action, name] : _availableActionsAndNamesMap)
@@ -119,7 +128,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
return _cachedDisplayName;
}
winrt::hstring CommandViewModel::Name()
winrt::hstring CommandViewModel::Name() const noexcept
{
return _command.HasName() ? _command.Name() : L"";
}
@@ -145,7 +154,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
return result;
}
winrt::hstring CommandViewModel::FirstKeyChordText()
winrt::hstring CommandViewModel::FirstKeyChordText() const
{
if (_KeyChordList.Size() != 0)
{
@@ -154,7 +163,21 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
return L"";
}
winrt::hstring CommandViewModel::AdditionalKeyChordCountText()
Control::KeyChord CommandViewModel::FirstKeyChord() const noexcept
{
if (_KeyChordList.Size() != 0)
{
return _KeyChordList.GetAt(0).CurrentKeys();
}
return nullptr;
}
bool CommandViewModel::HasNoKeyChords() const noexcept
{
return _KeyChordList.Size() == 0;
}
winrt::hstring CommandViewModel::AdditionalKeyChordCountText() const
{
const auto size = _KeyChordList.Size();
if (size > 1)
@@ -164,7 +187,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
return L"";
}
winrt::hstring CommandViewModel::AdditionalKeyChordTooltipText()
winrt::hstring CommandViewModel::AdditionalKeyChordTooltipText() const
{
const auto size = _KeyChordList.Size();
if (size <= 1)
@@ -183,12 +206,12 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
return winrt::hstring{ result };
}
winrt::hstring CommandViewModel::ID()
winrt::hstring CommandViewModel::ID() const noexcept
{
return _command.ID();
}
bool CommandViewModel::IsUserAction()
bool CommandViewModel::IsUserAction() const noexcept
{
return _command.Origin() == OriginTag::User;
}
@@ -206,23 +229,40 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
void CommandViewModel::AddKeybinding_Click()
{
auto kbdVM{ make_self<KeyChordViewModel>(nullptr) };
kbdVM->Index(gsl::narrow_cast<int32_t>(_KeyChordList.Size()) + 1);
kbdVM->IsInEditMode(true);
_RegisterKeyChordVMEvents(*kbdVM);
KeyChordList().Append(*kbdVM);
FocusContainer.raise(*this, *kbdVM);
}
winrt::hstring CommandViewModel::ActionNameTextBoxAutomationPropName()
// Reassigns 1-based Index values for every KeyChordViewModel in the list. Called
// whenever the list changes shape so the per-row "Key Binding #N" label stays in sync.
void CommandViewModel::_ReindexKeyChordList()
{
const auto size = _KeyChordList.Size();
for (uint32_t i = 0; i < size; ++i)
{
auto kcVM{ _KeyChordList.GetAt(i) };
const auto newIdx = gsl::narrow_cast<int32_t>(i) + 1;
if (kcVM.Index() != newIdx)
{
kcVM.Index(newIdx);
}
}
}
winrt::hstring CommandViewModel::ActionNameTextBoxAutomationPropName() const
{
return RS_(L"Actions_Name/Text");
}
winrt::hstring CommandViewModel::ShortcutActionComboBoxAutomationPropName()
winrt::hstring CommandViewModel::ShortcutActionComboBoxAutomationPropName() const
{
return RS_(L"Actions_ShortcutAction/Text");
}
winrt::hstring CommandViewModel::AdditionalArgumentsControlAutomationPropName()
winrt::hstring CommandViewModel::AdditionalArgumentsControlAutomationPropName() const
{
return RS_(L"Actions_Arguments/Text");
}
@@ -273,6 +313,19 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
self->FocusContainer.raise(*self, senderVM);
}
}
else if (propertyName == L"KeyChordText")
{
// The first chord of the list is what the row visual on the Actions page binds to,
// so propagate the change up so the row updates.
if (self->_KeyChordList.Size() > 0 && self->_KeyChordList.GetAt(0) == senderVM)
{
self->_NotifyChanges(L"FirstKeyChord", L"FirstKeyChordText", L"DisplayNameAndKeyChordAutomationPropName");
}
else
{
self->_NotifyChanges(L"AdditionalKeyChordTooltipText");
}
}
}
});
}
@@ -1065,12 +1118,21 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
KeyChordViewModel::KeyChordViewModel(Control::KeyChord currentKeys)
{
CurrentKeys(currentKeys);
// DisplayLabel is derived from Index, so re-fire the change for it whenever Index changes.
PropertyChanged([this](const auto& /*sender*/, const Windows::UI::Xaml::Data::PropertyChangedEventArgs& args) {
if (args.PropertyName() == L"Index")
{
_NotifyChanges(L"DisplayLabel");
}
});
}
void KeyChordViewModel::CurrentKeys(const Control::KeyChord& newKeys)
{
_currentKeys = newKeys;
KeyChordText(Model::KeyChordSerialization::ToString(_currentKeys));
_NotifyChanges(L"CurrentKeys");
}
Control::KeyChord KeyChordViewModel::CurrentKeys() const noexcept
@@ -1126,6 +1188,12 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
hstring KeyChordViewModel::CancelButtonName() const noexcept { return RS_(L"Actions_CancelButton/[using:Windows.UI.Xaml.Controls]ToolTipService/ToolTip"); }
hstring KeyChordViewModel::AcceptButtonName() const noexcept { return RS_(L"Actions_AcceptButton/[using:Windows.UI.Xaml.Controls]ToolTipService/ToolTip"); }
hstring KeyChordViewModel::DeleteButtonName() const noexcept { return RS_(L"Actions_DeleteButton/[using:Windows.UI.Xaml.Controls]ToolTipService/ToolTip"); }
hstring KeyChordViewModel::EditButtonName() const noexcept { return RS_(L"Actions_EditButton/[using:Windows.UI.Xaml.Controls]ToolTipService/ToolTip"); }
winrt::hstring KeyChordViewModel::DisplayLabel() const
{
return hstring{ RS_fmt(L"EditAction_KeyBindingNumberFormat", _Index) };
}
ActionsViewModel::ActionsViewModel(Model::CascadiaSettings settings) :
_Settings{ settings }

View File

@@ -69,16 +69,18 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
void Initialize();
winrt::hstring DisplayName();
winrt::hstring Name();
winrt::hstring Name() const noexcept;
void Name(const winrt::hstring& newName);
winrt::hstring DisplayNameAndKeyChordAutomationPropName();
winrt::hstring FirstKeyChordText();
winrt::hstring AdditionalKeyChordCountText();
winrt::hstring AdditionalKeyChordTooltipText();
winrt::hstring FirstKeyChordText() const;
Control::KeyChord FirstKeyChord() const noexcept;
bool HasNoKeyChords() const noexcept;
winrt::hstring AdditionalKeyChordCountText() const;
winrt::hstring AdditionalKeyChordTooltipText() const;
winrt::hstring ID();
bool IsUserAction();
winrt::hstring ID() const noexcept;
bool IsUserAction() const noexcept;
void Edit_Click();
til::typed_event<Editor::CommandViewModel, IInspectable> EditRequested;
@@ -89,9 +91,9 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
void AddKeybinding_Click();
// UIA text
winrt::hstring ActionNameTextBoxAutomationPropName();
winrt::hstring ShortcutActionComboBoxAutomationPropName();
winrt::hstring AdditionalArgumentsControlAutomationPropName();
winrt::hstring ActionNameTextBoxAutomationPropName() const;
winrt::hstring ShortcutActionComboBoxAutomationPropName() const;
winrt::hstring AdditionalArgumentsControlAutomationPropName() const;
til::typed_event<IInspectable, Editor::ArgWrapper> PropagateColorSchemeRequested;
til::typed_event<IInspectable, Editor::ArgWrapper> PropagateColorSchemeNamesRequested;
@@ -115,6 +117,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
void _RegisterActionArgsVMEvents(Editor::ActionArgsViewModel actionArgsVM);
void _ReplaceCommandWithUserCopy(bool reinitialize);
void _CreateAndInitializeActionArgsVMHelper();
void _ReindexKeyChordList();
};
struct ArgWrapper : ArgWrapperT<ArgWrapper>, ViewModelHelper<ArgWrapper>
@@ -230,15 +233,19 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
void CancelChanges();
void DeleteKeyChord();
winrt::hstring DisplayLabel() const;
// UIA Text
hstring CancelButtonName() const noexcept;
hstring AcceptButtonName() const noexcept;
hstring DeleteButtonName() const noexcept;
hstring EditButtonName() const noexcept;
VIEW_MODEL_OBSERVABLE_PROPERTY(bool, IsInEditMode, false);
VIEW_MODEL_OBSERVABLE_PROPERTY(Control::KeyChord, ProposedKeys);
VIEW_MODEL_OBSERVABLE_PROPERTY(winrt::hstring, KeyChordText);
VIEW_MODEL_OBSERVABLE_PROPERTY(Windows::UI::Xaml::Controls::Flyout, AcceptChangesFlyout, nullptr);
VIEW_MODEL_OBSERVABLE_PROPERTY(int32_t, Index, 0);
public:
til::typed_event<Editor::KeyChordViewModel, Terminal::Control::KeyChord> AddKeyChordRequested;

View File

@@ -55,6 +55,8 @@ namespace Microsoft.Terminal.Settings.Editor
// View-model specific
String DisplayName { get; };
String FirstKeyChordText { get; };
Microsoft.Terminal.Control.KeyChord FirstKeyChord { get; };
Boolean HasNoKeyChords { get; };
String AdditionalKeyChordCountText { get; };
String AdditionalKeyChordTooltipText { get; };
String DisplayNameAndKeyChordAutomationPropName { get; };
@@ -138,9 +140,12 @@ namespace Microsoft.Terminal.Settings.Editor
String KeyChordText { get; };
// UI side
Microsoft.Terminal.Control.KeyChord CurrentKeys { get; };
Microsoft.Terminal.Control.KeyChord ProposedKeys;
Windows.UI.Xaml.Controls.Flyout AcceptChangesFlyout;
Boolean IsInEditMode { get; };
Int32 Index;
String DisplayLabel { get; };
void ToggleEditMode();
void AcceptChanges();
void CancelChanges();
@@ -148,6 +153,7 @@ namespace Microsoft.Terminal.Settings.Editor
String CancelButtonName { get; };
String AcceptButtonName { get; };
String DeleteButtonName { get; };
String EditButtonName { get; };
event Windows.Foundation.TypedEventHandler<KeyChordViewModel, Microsoft.Terminal.Control.KeyChord> AddKeyChordRequested;
event Windows.Foundation.TypedEventHandler<KeyChordViewModel, ModifyKeyChordEventArgs> ModifyKeyChordRequested;

View File

@@ -17,130 +17,11 @@
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="CommonResources.xaml" />
</ResourceDictionary.MergedDictionaries>
<!-- Theme Dictionary -->
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Dark">
<!-- KeyChordText styles -->
<Style x:Key="KeyChordBorderStyle"
TargetType="Button">
<Setter Property="BorderThickness" Value="1" />
<Setter Property="CornerRadius" Value="1" />
<Setter Property="Background" Value="{ThemeResource SystemAltMediumLowColor}" />
<Setter Property="BorderBrush" Value="{ThemeResource SystemControlForegroundBaseMediumBrush}" />
<!-- Override visual states -->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<!-- Define the appearance of the button -->
<Border x:Name="border"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}">
<ContentPresenter HorizontalAlignment="Center"
VerticalAlignment="Center" />
</Border>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="PointerOver">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="border"
Storyboard.TargetProperty="Background">
<DiscreteObjectKeyFrame KeyTime="0"
Value="{ThemeResource SystemControlHighlightAccentRevealBackgroundBrush}" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Pressed" />
<VisualState x:Name="Disabled" />
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="KeyChordTextBlockStyle"
TargetType="TextBlock">
<Setter Property="Foreground" Value="{ThemeResource SystemControlForegroundBaseMediumBrush}" />
</Style>
</ResourceDictionary>
<ResourceDictionary x:Key="Light">
<!-- KeyChordText styles -->
<Style x:Key="KeyChordBorderStyle"
TargetType="Button">
<Setter Property="BorderThickness" Value="1" />
<Setter Property="CornerRadius" Value="1" />
<Setter Property="Background" Value="{ThemeResource SystemAltMediumLowColor}" />
<Setter Property="BorderBrush" Value="{ThemeResource SystemControlForegroundBaseMediumBrush}" />
<!-- Override visual states -->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<!-- Define the appearance of the button -->
<Border x:Name="border"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}">
<ContentPresenter HorizontalAlignment="Center"
VerticalAlignment="Center" />
</Border>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="PointerOver">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="border"
Storyboard.TargetProperty="Background">
<DiscreteObjectKeyFrame KeyTime="0"
Value="{ThemeResource SystemControlHighlightAccentRevealBackgroundBrush}" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Pressed" />
<VisualState x:Name="Disabled" />
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="KeyChordTextBlockStyle"
TargetType="TextBlock">
<Setter Property="Foreground" Value="{ThemeResource SystemControlForegroundBaseMediumBrush}" />
</Style>
</ResourceDictionary>
<ResourceDictionary x:Key="HighContrast">
<!-- KeyChordText styles (use XAML defaults for High Contrast theme) -->
<Style x:Key="KeyChordBorderStyle"
TargetType="Button" />
<Style x:Key="KeyChordTextBlockStyle"
TargetType="TextBlock" />
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
<GridLength x:Key="ArgumentNameWidth">148</GridLength>
<!-- Styles -->
<Style x:Key="KeyBindingContainerStyle"
BasedOn="{StaticResource DefaultListViewItemStyle}"
TargetType="ListViewItem">
<Setter Property="Padding" Value="4" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="XYFocusKeyboardNavigation" Value="Enabled" />
</Style>
<Style x:Key="KeyChordEditorStyle"
TargetType="local:KeyChordListener">
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
<x:Int32 x:Key="EditButtonSize">32</x:Int32>
<x:Double x:Key="EditButtonIconSize">14</x:Double>
<Style x:Key="EditButtonStyle"
BasedOn="{StaticResource DefaultButtonStyle}"
TargetType="Button">
@@ -149,6 +30,7 @@
<Setter Property="Height" Value="{StaticResource EditButtonSize}" />
<Setter Property="Width" Value="{StaticResource EditButtonSize}" />
</Style>
<Style x:Key="AccentEditButtonStyle"
BasedOn="{StaticResource AccentButtonStyle}"
TargetType="Button">
@@ -157,42 +39,63 @@
<Setter Property="Height" Value="{StaticResource EditButtonSize}" />
<Setter Property="Width" Value="{StaticResource EditButtonSize}" />
</Style>
<Style x:Key="TextBlockGroupingStyle"
BasedOn="{StaticResource BodyStrongTextBlockStyle}"
TargetType="TextBlock">
<Setter Property="MaxWidth" Value="{StaticResource StandardControlMaxWidth}" />
<Setter Property="Margin" Value="0,0,0,4" />
<Setter Property="FontSize" Value="16" />
<Style x:Key="KeyChordEditorStyle"
TargetType="local:KeyChordListener">
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="MinWidth" Value="160" />
</Style>
<!-- Templates -->
<!--
Item container for the per-chord ListView. We're hosting a SettingContainer
inside each item, so strip the default ListViewItem visuals (padding, border,
hover/selection background) so they don't double up.
-->
<Style x:Key="KeyChordListViewItemStyle"
BasedOn="{StaticResource DefaultListViewItemStyle}"
TargetType="ListViewItem">
<Setter Property="Padding" Value="0" />
<Setter Property="Margin" Value="0" />
<Setter Property="MinHeight" Value="0" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderThickness" Value="0" />
</Style>
<!-- "Key Binding #N" template -->
<DataTemplate x:Key="KeyChordTemplate"
x:DataType="local:KeyChordViewModel">
<ListViewItem IsTabStop="False"
Style="{StaticResource KeyBindingContainerStyle}">
<Grid Padding="-4,0,0,0"
VerticalAlignment="Center">
<local:SettingContainer Header="{x:Bind DisplayLabel, Mode=OneWay}">
<Grid VerticalAlignment="Center"
ColumnSpacing="8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{StaticResource ArgumentNameWidth}" />
<!-- Key visual / key chord listener -->
<ColumnDefinition Width="Auto" />
<!-- Cancel button (visible only in edit mode) -->
<ColumnDefinition Width="Auto" />
<!-- Accept button (visible only in edit mode) -->
<ColumnDefinition Width="Auto" />
<!-- Edit (pencil) button (visible only NOT in edit mode) -->
<ColumnDefinition Width="Auto" />
<!-- Delete button -->
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Button Grid.Column="0"
Background="{ThemeResource AppBarItemBackgroundThemeBrush}"
Click="{x:Bind ToggleEditMode}"
Visibility="{x:Bind mtu:Converters.InvertedBooleanToVisibility(IsInEditMode), Mode=OneWay}">
<TextBlock FontSize="14"
Text="{x:Bind KeyChordText, Mode=OneWay}"
TextWrapping="WrapWholeWords" />
</Button>
<!-- Read-only key chord visual -->
<local:KeyChordVisual Grid.Column="0"
KeyChord="{x:Bind CurrentKeys, Mode=OneWay}"
Visibility="{x:Bind mtu:Converters.InvertedBooleanToVisibility(IsInEditMode), Mode=OneWay}" />
<!-- Editable key chord listener -->
<local:KeyChordListener Grid.Column="0"
Keys="{x:Bind ProposedKeys, Mode=TwoWay}"
Style="{StaticResource KeyChordEditorStyle}"
Visibility="{x:Bind IsInEditMode, Mode=OneWay}" />
<!-- Cancel changes (edit mode only) -->
<Button x:Uid="Actions_CancelButton"
Grid.Column="1"
Margin="8,0,0,0"
AutomationProperties.Name="{x:Bind CancelButtonName}"
Click="{x:Bind CancelChanges}"
Style="{StaticResource EditButtonStyle}"
@@ -201,9 +104,9 @@
Glyph="&#xE711;" />
</Button>
<!-- Accept changes (edit mode only) -->
<Button x:Uid="Actions_AcceptButton"
Grid.Column="2"
Margin="8,0,8,0"
AutomationProperties.Name="{x:Bind AcceptButtonName}"
Click="{x:Bind AcceptChanges}"
Flyout="{x:Bind AcceptChangesFlyout, Mode=OneWay}"
@@ -213,8 +116,19 @@
Glyph="&#xE8FB;" />
</Button>
<Button Grid.Column="3"
HorizontalAlignment="Left"
<!-- Edit button -->
<Button x:Uid="Actions_EditButton"
Grid.Column="3"
AutomationProperties.Name="{x:Bind EditButtonName}"
Click="{x:Bind ToggleEditMode}"
Style="{StaticResource EditButtonStyle}"
Visibility="{x:Bind mtu:Converters.InvertedBooleanToVisibility(IsInEditMode), Mode=OneWay}">
<FontIcon FontSize="{StaticResource EditButtonIconSize}"
Glyph="&#xE70F;" />
</Button>
<!-- Delete button -->
<Button Grid.Column="4"
AutomationProperties.Name="{x:Bind DeleteButtonName}"
Style="{StaticResource DeleteSmallButtonStyle}">
<Button.Content>
@@ -233,25 +147,23 @@
</Button.Flyout>
</Button>
</Grid>
</ListViewItem>
</local:SettingContainer>
</DataTemplate>
<!--
BODGY: Each ArgWrapper DataTemplate below wraps its editor control
in a <local:SettingContainer Header="{x:Bind Name}"> rather than sharing a
single outer template. This is because a bug in WinUI 2 prevents a
ContentPresenter + ContentTemplateSelector pattern from working correctly,
resulting in "Microsoft.Terminal.Settings.Editor.ArgWrapper" being shown.
-->
<!-- Example shortcut action to test this template: Adjust Opacity -->
<!-- Currently that is the only Int32 arg, so just clamp the min/max values according to that -->
<DataTemplate x:Key="Int32Template"
x:DataType="local:ArgWrapper">
<Grid Margin="0,4,0,4"
ColumnSpacing="8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{StaticResource ArgumentNameWidth}" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
VerticalAlignment="Center"
Text="{x:Bind Name}"
TextWrapping="WrapWholeWords" />
<muxc:NumberBox Grid.Column="1"
HorizontalAlignment="Stretch"
<local:SettingContainer Header="{x:Bind Name}">
<muxc:NumberBox MinWidth="160"
AutomationProperties.Name="{x:Bind Name}"
LargeChange="1"
Maximum="100"
@@ -259,24 +171,14 @@
SmallChange="10"
Style="{StaticResource NumberBoxSettingStyle}"
Value="{x:Bind UnboxInt32(Value), Mode=TwoWay, BindBack=Int32BindBack}" />
</Grid>
</local:SettingContainer>
</DataTemplate>
<!-- Example shortcut action to test this template: Switch To Tab -->
<DataTemplate x:Key="UInt32Template"
x:DataType="local:ArgWrapper">
<Grid Margin="0,4,0,4"
ColumnSpacing="8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{StaticResource ArgumentNameWidth}" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
VerticalAlignment="Center"
Text="{x:Bind Name}"
TextWrapping="WrapWholeWords" />
<muxc:NumberBox Grid.Column="1"
HorizontalAlignment="Stretch"
<local:SettingContainer Header="{x:Bind Name}">
<muxc:NumberBox MinWidth="160"
AutomationProperties.Name="{x:Bind Name}"
LargeChange="1"
Maximum="999"
@@ -284,24 +186,14 @@
SmallChange="1"
Style="{StaticResource NumberBoxSettingStyle}"
Value="{x:Bind UnboxUInt32(Value), Mode=TwoWay, BindBack=UInt32BindBack}" />
</Grid>
</local:SettingContainer>
</DataTemplate>
<!-- Example shortcut action to test this template: Close Other Tabs -->
<DataTemplate x:Key="UInt32OptionalTemplate"
x:DataType="local:ArgWrapper">
<Grid Margin="0,4,0,4"
ColumnSpacing="8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{StaticResource ArgumentNameWidth}" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
VerticalAlignment="Center"
Text="{x:Bind Name}"
TextWrapping="WrapWholeWords" />
<muxc:NumberBox Grid.Column="1"
HorizontalAlignment="Stretch"
<local:SettingContainer Header="{x:Bind Name}">
<muxc:NumberBox MinWidth="160"
AutomationProperties.Name="{x:Bind Name}"
LargeChange="1"
Maximum="999"
@@ -309,24 +201,14 @@
SmallChange="1"
Style="{StaticResource NumberBoxSettingStyle}"
Value="{x:Bind UnboxUInt32Optional(Value), Mode=TwoWay, BindBack=UInt32OptionalBindBack}" />
</Grid>
</local:SettingContainer>
</DataTemplate>
<!-- Example shortcut action to test this template: Split Pane -->
<DataTemplate x:Key="Int32OptionalTemplate"
x:DataType="local:ArgWrapper">
<Grid Margin="0,4,0,4"
ColumnSpacing="8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{StaticResource ArgumentNameWidth}" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
VerticalAlignment="Center"
Text="{x:Bind Name}"
TextWrapping="WrapWholeWords" />
<muxc:NumberBox Grid.Column="1"
HorizontalAlignment="Stretch"
<local:SettingContainer Header="{x:Bind Name}">
<muxc:NumberBox MinWidth="160"
AutomationProperties.Name="{x:Bind Name}"
LargeChange="1"
Maximum="999"
@@ -334,24 +216,14 @@
SmallChange="1"
Style="{StaticResource NumberBoxSettingStyle}"
Value="{x:Bind UnboxInt32Optional(Value), Mode=TwoWay, BindBack=Int32OptionalBindBack}" />
</Grid>
</local:SettingContainer>
</DataTemplate>
<!-- Example shortcut action to test this template: Adjust Font Size -->
<DataTemplate x:Key="FloatTemplate"
x:DataType="local:ArgWrapper">
<Grid Margin="0,4,0,4"
ColumnSpacing="8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{StaticResource ArgumentNameWidth}" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
VerticalAlignment="Center"
Text="{x:Bind Name}"
TextWrapping="WrapWholeWords" />
<muxc:NumberBox Grid.Column="1"
HorizontalAlignment="Stretch"
<local:SettingContainer Header="{x:Bind Name}">
<muxc:NumberBox MinWidth="160"
AutomationProperties.Name="{x:Bind Name}"
LargeChange="1"
Maximum="999"
@@ -359,24 +231,14 @@
SmallChange="1"
Style="{StaticResource NumberBoxSettingStyle}"
Value="{x:Bind UnboxFloat(Value), Mode=TwoWay, BindBack=FloatBindBack}" />
</Grid>
</local:SettingContainer>
</DataTemplate>
<!-- Example shortcut action to test this template: Split Pane -->
<DataTemplate x:Key="SplitSizeTemplate"
x:DataType="local:ArgWrapper">
<Grid Margin="0,4,0,4"
ColumnSpacing="8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{StaticResource ArgumentNameWidth}" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
VerticalAlignment="Center"
Text="{x:Bind Name}"
TextWrapping="WrapWholeWords" />
<muxc:NumberBox Grid.Column="1"
HorizontalAlignment="Stretch"
<local:SettingContainer Header="{x:Bind Name}">
<muxc:NumberBox MinWidth="160"
AutomationProperties.Name="{x:Bind Name}"
LargeChange="0.2"
Maximum="1"
@@ -384,144 +246,95 @@
SmallChange="0.1"
Style="{StaticResource NumberBoxSettingStyle}"
Value="{x:Bind UnboxFloat(Value), Mode=TwoWay, BindBack=FloatBindBack}" />
</Grid>
</local:SettingContainer>
</DataTemplate>
<!-- Example shortcut action to test this template: Send Input -->
<DataTemplate x:Key="StringTemplate"
x:DataType="local:ArgWrapper">
<Grid Margin="0,4,0,4"
ColumnSpacing="8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{StaticResource ArgumentNameWidth}" />
<ColumnDefinition Width="*"
MinWidth="196" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
VerticalAlignment="Center"
Text="{x:Bind Name}"
TextWrapping="WrapWholeWords" />
<TextBox Grid.Column="1"
<local:SettingContainer Header="{x:Bind Name}">
<TextBox MinWidth="248"
AutomationProperties.Name="{x:Bind Name}"
Text="{x:Bind UnboxString(Value), Mode=TwoWay, BindBack=StringBindBack}"
TextWrapping="Wrap" />
</Grid>
</local:SettingContainer>
</DataTemplate>
<!-- Example shortcut action to test this template: Set Color Scheme -->
<DataTemplate x:Key="ColorSchemeTemplate"
x:DataType="local:ArgWrapper">
<Grid Margin="0,4,0,4"
ColumnSpacing="8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{StaticResource ArgumentNameWidth}" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
VerticalAlignment="Center"
Text="{x:Bind Name}"
TextWrapping="WrapWholeWords" />
<ComboBox Grid.Column="1"
HorizontalAlignment="Stretch"
<local:SettingContainer Header="{x:Bind Name}">
<ComboBox MinWidth="248"
AutomationProperties.Name="{x:Bind Name}"
ItemTemplate="{StaticResource EnumComboBoxTemplate}"
ItemsSource="{x:Bind EnumList, Mode=OneWay}"
SelectedItem="{x:Bind EnumValue, Mode=TwoWay}"
Style="{StaticResource ComboBoxSettingStyle}" />
</Grid>
</local:SettingContainer>
</DataTemplate>
<!-- Example shortcut action to test this template: Export Buffer -->
<DataTemplate x:Key="FilePickerTemplate"
x:DataType="local:ArgWrapper">
<Grid Margin="0,4,0,4"
ColumnSpacing="8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{StaticResource ArgumentNameWidth}" />
<ColumnDefinition Width="*"
MinWidth="196" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
VerticalAlignment="Center"
Text="{x:Bind Name}"
TextWrapping="WrapWholeWords" />
<TextBox Grid.Column="1"
AutomationProperties.Name="{x:Bind Name}"
Text="{x:Bind UnboxString(Value), Mode=TwoWay, BindBack=StringBindBack}"
TextWrapping="Wrap" />
<Button x:Uid="Actions_Browse"
Grid.Column="2"
Click="{x:Bind BrowseForFile_Click}"
Style="{StaticResource BrowseButtonStyle}" />
</Grid>
<local:SettingContainer Header="{x:Bind Name}">
<Grid ColumnSpacing="4">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"
MinWidth="196" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBox Grid.Column="0"
AutomationProperties.Name="{x:Bind Name}"
Text="{x:Bind UnboxString(Value), Mode=TwoWay, BindBack=StringBindBack}"
TextWrapping="Wrap" />
<Button x:Uid="Actions_Browse"
Grid.Column="1"
Click="{x:Bind BrowseForFile_Click}"
Style="{StaticResource BrowseButtonStyle}" />
</Grid>
</local:SettingContainer>
</DataTemplate>
<!-- Example shortcut action to test this template: New Tab -->
<DataTemplate x:Key="FolderPickerTemplate"
x:DataType="local:ArgWrapper">
<Grid Margin="0,4,0,4"
ColumnSpacing="8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{StaticResource ArgumentNameWidth}" />
<ColumnDefinition Width="*"
MinWidth="196" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
VerticalAlignment="Center"
Text="{x:Bind Name}"
TextWrapping="WrapWholeWords" />
<TextBox Grid.Column="1"
AutomationProperties.Name="{x:Bind Name}"
Text="{x:Bind UnboxString(Value), Mode=TwoWay, BindBack=StringBindBack}"
TextWrapping="Wrap" />
<Button x:Uid="Actions_Browse"
Grid.Column="2"
Click="{x:Bind BrowseForFolder_Click}"
Style="{StaticResource BrowseButtonStyle}" />
</Grid>
<local:SettingContainer Header="{x:Bind Name}">
<Grid ColumnSpacing="4">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"
MinWidth="196" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBox Grid.Column="0"
AutomationProperties.Name="{x:Bind Name}"
Text="{x:Bind UnboxString(Value), Mode=TwoWay, BindBack=StringBindBack}"
TextWrapping="Wrap" />
<Button x:Uid="Actions_Browse"
Grid.Column="1"
Click="{x:Bind BrowseForFolder_Click}"
Style="{StaticResource BrowseButtonStyle}" />
</Grid>
</local:SettingContainer>
</DataTemplate>
<!-- Example shortcut action to test this template: Set Focus Mode -->
<DataTemplate x:Key="BoolTemplate"
x:DataType="local:ArgWrapper">
<Grid Margin="0,4,0,4"
ColumnSpacing="8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{StaticResource ArgumentNameWidth}" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
VerticalAlignment="Center"
Text="{x:Bind Name}"
TextWrapping="WrapWholeWords" />
<ToggleSwitch Grid.Column="1"
HorizontalAlignment="Left"
AutomationProperties.Name="{x:Bind Name}"
IsOn="{x:Bind UnboxBool(Value), Mode=TwoWay, BindBack=BoolOptionalBindBack}" />
</Grid>
<local:SettingContainer Header="{x:Bind Name}">
<ToggleSwitch AutomationProperties.Name="{x:Bind Name}"
IsOn="{x:Bind UnboxBool(Value), Mode=TwoWay, BindBack=BoolOptionalBindBack}"
Style="{StaticResource ToggleSwitchInExpanderStyle}" />
</local:SettingContainer>
</DataTemplate>
<!-- Example shortcut action to test this template: Split Pane -->
<DataTemplate x:Key="BoolOptionalTemplate"
x:DataType="local:ArgWrapper">
<Grid Margin="0,4,0,4"
ColumnSpacing="8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{StaticResource ArgumentNameWidth}" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
VerticalAlignment="Center"
Text="{x:Bind Name}"
TextWrapping="WrapWholeWords" />
<CheckBox Grid.Column="1"
HorizontalAlignment="Left"
AutomationProperties.Name="{x:Bind Name}"
<local:SettingContainer Header="{x:Bind Name}">
<CheckBox AutomationProperties.Name="{x:Bind Name}"
IsChecked="{x:Bind UnboxBoolOptional(Value), Mode=TwoWay, BindBack=BoolOptionalBindBack}"
IsThreeState="True" />
</Grid>
</local:SettingContainer>
</DataTemplate>
<!-- Example shortcut action to test this template: Resize Pane -->
@@ -532,24 +345,14 @@
<DataTemplate x:Key="EnumTemplate"
x:DataType="local:ArgWrapper">
<Grid Margin="0,4,0,4"
ColumnSpacing="8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{StaticResource ArgumentNameWidth}" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
VerticalAlignment="Center"
Text="{x:Bind Name}"
TextWrapping="WrapWholeWords" />
<ComboBox Grid.Column="1"
HorizontalAlignment="Stretch"
<local:SettingContainer Header="{x:Bind Name}">
<ComboBox MinWidth="248"
AutomationProperties.Name="{x:Bind Name}"
ItemTemplate="{StaticResource EnumComboBoxTemplate}"
ItemsSource="{x:Bind EnumList, Mode=OneWay}"
SelectedItem="{x:Bind EnumValue, Mode=TwoWay}"
Style="{StaticResource ComboBoxSettingStyle}" />
</Grid>
</local:SettingContainer>
</DataTemplate>
<!-- Example shortcut action to test this template: Copy Text -->
@@ -572,66 +375,35 @@
<DataTemplate x:Key="FlagTemplate"
x:DataType="local:ArgWrapper">
<Grid Margin="0,4,0,4">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{StaticResource ArgumentNameWidth}" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
VerticalAlignment="Center"
Text="{x:Bind Name}"
TextWrapping="WrapWholeWords" />
<ItemsControl Grid.Column="1"
Margin="0"
HorizontalAlignment="Left"
AutomationProperties.Name="{x:Bind Name}"
<local:SettingContainer Header="{x:Bind Name}">
<ItemsControl AutomationProperties.Name="{x:Bind Name}"
ItemTemplate="{StaticResource FlagItemTemplate}"
ItemsSource="{x:Bind FlagList, Mode=OneWay}" />
</Grid>
</local:SettingContainer>
</DataTemplate>
<!-- Example shortcut action to test this template: Add Mark -->
<DataTemplate x:Key="TerminalCoreColorOptionalTemplate"
x:DataType="local:ArgWrapper">
<Grid Margin="0,4,0,4"
ColumnSpacing="8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{StaticResource ArgumentNameWidth}" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
VerticalAlignment="Center"
Text="{x:Bind Name}"
TextWrapping="WrapWholeWords" />
<local:SettingContainer Header="{x:Bind Name}">
<local:NullableColorPicker x:Uid="Actions_NullableColorPicker"
Grid.Column="1"
AutomationProperties.Name="{x:Bind Name}"
ColorSchemeVM="{x:Bind DefaultColorScheme, Mode=OneWay}"
CurrentColor="{x:Bind UnboxTerminalCoreColorOptional(Value), Mode=TwoWay, BindBack=TerminalCoreColorBindBack}"
NullColorPreview="{x:Bind DefaultColorScheme.ForegroundColor.Color, Mode=OneWay}" />
</Grid>
</local:SettingContainer>
</DataTemplate>
<!-- Example shortcut action to test this template: Set Tab Color -->
<DataTemplate x:Key="WindowsUIColorOptionalTemplate"
x:DataType="local:ArgWrapper">
<Grid Margin="0,4,0,4"
ColumnSpacing="8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{StaticResource ArgumentNameWidth}" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
VerticalAlignment="Center"
Text="{x:Bind Name}"
TextWrapping="WrapWholeWords" />
<local:SettingContainer Header="{x:Bind Name}">
<local:NullableColorPicker x:Uid="Actions_NullableColorPicker"
Grid.Column="1"
AutomationProperties.Name="{x:Bind Name}"
ColorSchemeVM="{x:Bind DefaultColorScheme, Mode=OneWay}"
CurrentColor="{x:Bind UnboxWindowsUIColorOptional(Value), Mode=TwoWay, BindBack=WindowsUIColorBindBack}"
NullColorPreview="{x:Bind DefaultColorScheme.ForegroundColor.Color, Mode=OneWay}" />
</Grid>
</local:SettingContainer>
</DataTemplate>
<local:ArgsTemplateSelectors x:Key="ArgsTemplateSelector"
@@ -655,122 +427,106 @@
</ResourceDictionary>
</Page.Resources>
<Border MaxWidth="{StaticResource StandardControlMaxWidth}"
Margin="{StaticResource SettingStackMargin}">
<Grid Margin="{StaticResource SettingStackMargin}"
HorizontalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{StaticResource ArgumentNameWidth}" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock x:Uid="Actions_CommandDetails"
Grid.Row="0"
Grid.Column="0"
Grid.ColumnSpan="2"
Margin="0,0,0,12"
VerticalAlignment="Center"
Style="{StaticResource TextBlockGroupingStyle}" />
<TextBlock x:Uid="Actions_Name"
Grid.Row="1"
Grid.Column="0"
Margin="0,0,0,8"
VerticalAlignment="Center" />
<TextBox x:Name="CommandNameTextBox"
Grid.Row="1"
Grid.Column="1"
Margin="0,0,0,8"
HorizontalAlignment="Stretch"
AutomationProperties.Name="{x:Bind ViewModel.ActionNameTextBoxAutomationPropName}"
PlaceholderText="{x:Bind ViewModel.DisplayName, Mode=OneWay}"
Text="{x:Bind ViewModel.Name, Mode=TwoWay}" />
<TextBlock x:Uid="Actions_ShortcutAction"
Grid.Row="2"
Grid.Column="0"
Margin="0,0,0,12"
VerticalAlignment="Center" />
<AutoSuggestBox x:Name="ShortcutActionBox"
Grid.Row="2"
Grid.Column="1"
Margin="0,0,0,12"
VerticalAlignment="Center"
AutomationProperties.Name="{x:Bind ViewModel.ShortcutActionComboBoxAutomationPropName}"
GotFocus="ShortcutActionBox_GotFocus"
LostFocus="ShortcutActionBox_LostFocus"
QuerySubmitted="ShortcutActionBox_QuerySubmitted"
TextChanged="ShortcutActionBox_TextChanged" />
<TextBlock x:Uid="Actions_Keybindings"
Grid.Row="3"
Grid.Column="0"
Grid.ColumnSpan="2"
Margin="0,0,0,12"
VerticalAlignment="Center"
Style="{StaticResource TextBlockGroupingStyle}" />
<ListView x:Name="KeyChordListView"
x:Uid="Actions_KeyBindingsListView"
Grid.Row="4"
Grid.Column="0"
Grid.ColumnSpan="2"
Margin="0,0,0,12"
ItemTemplate="{StaticResource KeyChordTemplate}"
ItemsSource="{x:Bind ViewModel.KeyChordList, Mode=OneWay}"
SelectionMode="None">
<ListView.Footer>
<Button Margin="0,4,0,0"
Click="{x:Bind ViewModel.AddKeybinding_Click}">
<TextBlock x:Uid="Actions_AddKeyChord" />
</Button>
</ListView.Footer>
</ListView>
<TextBlock x:Uid="Actions_Arguments"
Grid.Row="5"
Grid.Column="0"
Grid.ColumnSpan="2"
Margin="0,0,0,12"
VerticalAlignment="Center"
Style="{StaticResource TextBlockGroupingStyle}"
Visibility="{x:Bind ViewModel.ActionArgsVM.HasArgs, Mode=OneWay}" />
<ItemsControl Grid.Row="6"
Grid.Column="0"
Grid.ColumnSpan="2"
Margin="0,0,0,12"
HorizontalAlignment="Stretch"
AutomationProperties.Name="{x:Bind ViewModel.AdditionalArgumentsControlAutomationPropName}"
IsTabStop="False"
ItemTemplateSelector="{StaticResource ArgsTemplateSelector}"
ItemsSource="{x:Bind ViewModel.ActionArgsVM.ArgValues, Mode=OneWay}" />
<Button Grid.Row="7"
Grid.Column="0"
IsEnabled="{x:Bind ViewModel.IsUserAction, Mode=OneWay}"
Style="{StaticResource DeleteButtonStyle}">
<Button.Content>
<StackPanel Orientation="Horizontal">
<FontIcon FontSize="{StaticResource StandardIconSize}"
Glyph="&#xE74D;" />
<TextBlock x:Uid="Actions_DeleteButton2"
Style="{StaticResource IconButtonTextBlockStyle}" />
</StackPanel>
</Button.Content>
<Button.Flyout>
<Flyout>
<StackPanel>
<TextBlock x:Uid="Actions_CommandDeleteConfirmationMessage"
Style="{StaticResource CustomFlyoutTextStyle}" />
<Button x:Uid="Actions_CommandDeleteConfirmationButton"
Click="{x:Bind ViewModel.Delete_Click}" />
<Border MaxWidth="{StaticResource StandardControlMaxWidth}">
<StackPanel HorizontalAlignment="Stretch"
Style="{StaticResource SettingsStackStyle}">
<!-- Action type (top-most setting on the page) -->
<local:SettingContainer x:Name="ActionType"
x:Uid="EditAction_ActionType">
<AutoSuggestBox x:Name="ShortcutActionBox"
MinWidth="248"
AutomationProperties.Name="{x:Bind ViewModel.ShortcutActionComboBoxAutomationPropName}"
GotFocus="ShortcutActionBox_GotFocus"
LostFocus="ShortcutActionBox_LostFocus"
QuerySubmitted="ShortcutActionBox_QuerySubmitted"
TextChanged="ShortcutActionBox_TextChanged" />
</local:SettingContainer>
<!-- Key bindings expander -->
<local:SettingContainer x:Name="KeyBindingsContainer"
x:Uid="EditAction_KeyBindings"
StartExpanded="{x:Bind mtu:Converters.InvertBoolean(ViewModel.HasNoKeyChords), Mode=OneWay}"
Style="{StaticResource ExpanderSettingContainerStyle}">
<StackPanel>
<!-- "New key binding" button -->
<local:SettingContainer x:Name="NewKeyBinding"
x:Uid="EditAction_NewKeyBinding">
<Button x:Uid="EditAction_AddKeyBinding"
Click="{x:Bind ViewModel.AddKeybinding_Click}"
Style="{StaticResource AccentButtonStyle}" />
</local:SettingContainer>
<!-- Existing key bindings, one container per chord -->
<ListView x:Name="KeyChordListView"
x:Uid="Actions_KeyBindingsListView"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
IsItemClickEnabled="False"
ItemContainerStyle="{StaticResource KeyChordListViewItemStyle}"
ItemTemplate="{StaticResource KeyChordTemplate}"
ItemsSource="{x:Bind ViewModel.KeyChordList, Mode=OneWay}"
SelectionMode="None" />
</StackPanel>
</local:SettingContainer>
<!-- Additional customizations expander -->
<local:SettingContainer x:Name="AdditionalCustomizations"
x:Uid="EditAction_AdditionalCustomizations"
Style="{StaticResource ExpanderSettingContainerStyle}">
<StackPanel>
<!-- Action name -->
<local:SettingContainer x:Name="ActionName"
x:Uid="EditAction_ActionName">
<TextBox x:Name="CommandNameTextBox"
MinWidth="248"
AutomationProperties.Name="{x:Bind ViewModel.ActionNameTextBoxAutomationPropName}"
PlaceholderText="{x:Bind ViewModel.DisplayName, Mode=OneWay}"
Text="{x:Bind ViewModel.Name, Mode=TwoWay}" />
</local:SettingContainer>
<!-- Action argument controls -->
<ItemsControl HorizontalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
AutomationProperties.Name="{x:Bind ViewModel.AdditionalArgumentsControlAutomationPropName}"
IsTabStop="False"
ItemTemplateSelector="{StaticResource ArgsTemplateSelector}"
ItemsSource="{x:Bind ViewModel.ActionArgsVM.ArgValues, Mode=OneWay}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel HorizontalAlignment="Stretch" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</StackPanel>
</local:SettingContainer>
<!-- Delete command button -->
<local:SettingContainer x:Name="DeleteCommand"
x:Uid="EditAction_DeleteCommand">
<Button IsEnabled="{x:Bind ViewModel.IsUserAction, Mode=OneWay}"
Style="{StaticResource DeleteButtonStyle}">
<Button.Content>
<StackPanel Orientation="Horizontal">
<FontIcon FontSize="{StaticResource StandardIconSize}"
Glyph="&#xE74D;" />
<TextBlock x:Uid="Actions_DeleteButton2"
Style="{StaticResource IconButtonTextBlockStyle}" />
</StackPanel>
</Flyout>
</Button.Flyout>
</Button>
</Grid>
</Button.Content>
<Button.Flyout>
<Flyout>
<StackPanel>
<TextBlock x:Uid="Actions_CommandDeleteConfirmationMessage"
Style="{StaticResource CustomFlyoutTextStyle}" />
<Button x:Uid="Actions_CommandDeleteConfirmationButton"
Click="{x:Bind ViewModel.Delete_Click}" />
</StackPanel>
</Flyout>
</Button.Flyout>
</Button>
</local:SettingContainer>
</StackPanel>
</Border>
</Page>

View File

@@ -0,0 +1,131 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#include "pch.h"
#include "KeyChordVisual.h"
#include "KeyChordVisual.g.cpp"
using namespace winrt::Windows::UI::Xaml;
using namespace winrt::Windows::UI::Xaml::Controls;
using namespace winrt::Windows::Foundation;
namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
{
DependencyProperty KeyChordVisual::_KeyChordProperty{ nullptr };
KeyChordVisual::KeyChordVisual()
{
InitializeComponent();
_InitializeProperties();
}
void KeyChordVisual::_InitializeProperties()
{
if (!_KeyChordProperty)
{
_KeyChordProperty =
DependencyProperty::Register(
L"KeyChord",
xaml_typename<Control::KeyChord>(),
xaml_typename<Editor::KeyChordVisual>(),
PropertyMetadata{ nullptr, PropertyChangedCallback{ &KeyChordVisual::_OnKeyChordChanged } });
}
}
void KeyChordVisual::_OnKeyChordChanged(const DependencyObject& d, const DependencyPropertyChangedEventArgs& /*e*/)
{
if (const auto control{ d.try_as<Editor::KeyChordVisual>() })
{
const auto controlImpl{ get_self<KeyChordVisual>(control) };
controlImpl->_UpdateKeyVisuals();
}
}
// Capitalizes the first character of the provided string.
// Examples: "enter" -> "Enter", "f1" -> "F1", "v" -> "V"
static winrt::hstring _formatMainKeyName(std::wstring_view part)
{
if (part.empty())
{
return {};
}
std::wstring buffer{ part };
buffer[0] = til::toupper_ascii(buffer[0]);
return winrt::hstring{ buffer };
}
void KeyChordVisual::_UpdateKeyVisuals()
{
auto panel{ KeysPanel() };
if (!panel)
{
return;
}
panel.Children().Clear();
const auto kc{ KeyChord() };
if (!kc)
{
return;
}
// Reuse the canonical serialization so the key naming stays in sync with the
// rest of the app. Then split on '+' (no key name in the table contains a literal
// '+'; VK_OEM_PLUS serializes as "plus") and render each part as its own visual.
const auto serialized{ Model::KeyChordSerialization::ToString(kc) };
if (serialized.empty())
{
return;
}
const std::wstring_view full{ serialized };
for (const auto part : til::split_iterator{ full, L'+' })
{
if (til::equals_insensitive_ascii(part, L"win"))
{
_AddGlyphKey();
}
else if (til::equals_insensitive_ascii(part, L"ctrl"))
{
_AddTextKey(L"Ctrl");
}
else if (til::equals_insensitive_ascii(part, L"alt"))
{
_AddTextKey(L"Alt");
}
else if (til::equals_insensitive_ascii(part, L"shift"))
{
_AddTextKey(L"Shift");
}
else
{
_AddTextKey(_formatMainKeyName(part));
}
}
}
void KeyChordVisual::_AddTextKey(const winrt::hstring& text)
{
const auto tmpl{ Resources().Lookup(box_value(L"KeyChordVisualTextKeyTemplate")).as<DataTemplate>() };
const auto border{ tmpl.LoadContent().as<Border>() };
if (const auto tb{ border.Child().try_as<TextBlock>() })
{
tb.Text(text);
}
KeysPanel().Children().Append(border);
}
void KeyChordVisual::_AddGlyphKey()
{
const auto tmpl{ Resources().Lookup(box_value(L"KeyChordVisualWindowsKeyTemplate")).as<DataTemplate>() };
const auto border{ tmpl.LoadContent().as<Border>() };
// Provide an accessible name for the glyph since it has no text fallback.
if (const auto path{ border.Child() })
{
Automation::AutomationProperties::SetName(path, L"Win");
}
KeysPanel().Children().Append(border);
}
}

View File

@@ -0,0 +1,31 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#pragma once
#include "KeyChordVisual.g.h"
#include "Utils.h"
namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
{
struct KeyChordVisual : KeyChordVisualT<KeyChordVisual>
{
public:
KeyChordVisual();
DEPENDENCY_PROPERTY(Control::KeyChord, KeyChord);
private:
static void _InitializeProperties();
static void _OnKeyChordChanged(const Windows::UI::Xaml::DependencyObject& d, const Windows::UI::Xaml::DependencyPropertyChangedEventArgs& e);
void _UpdateKeyVisuals();
void _AddTextKey(const winrt::hstring& text);
void _AddGlyphKey();
};
}
namespace winrt::Microsoft::Terminal::Settings::Editor::factory_implementation
{
BASIC_FACTORY(KeyChordVisual);
}

View File

@@ -0,0 +1,13 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
namespace Microsoft.Terminal.Settings.Editor
{
[default_interface] runtimeclass KeyChordVisual : Windows.UI.Xaml.Controls.UserControl
{
KeyChordVisual();
Microsoft.Terminal.Control.KeyChord KeyChord;
static Windows.UI.Xaml.DependencyProperty KeyChordProperty { get; };
}
}

View File

@@ -0,0 +1,82 @@
<!--
Copyright (c) Microsoft Corporation. All rights reserved. Licensed under
the MIT License. See LICENSE in the project root for license information.
-->
<UserControl x:Class="Microsoft.Terminal.Settings.Editor.KeyChordVisual"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
HorizontalAlignment="Right"
VerticalAlignment="Center"
IsTabStop="False"
mc:Ignorable="d">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Default">
<StaticResource x:Key="KeyChordVisualKeyBackground"
ResourceKey="AccentFillColorDefaultBrush" />
<StaticResource x:Key="KeyChordVisualKeyForeground"
ResourceKey="TextOnAccentFillColorPrimaryBrush" />
<StaticResource x:Key="KeyChordVisualKeyBorderBrush"
ResourceKey="AccentControlElevationBorderBrush" />
</ResourceDictionary>
<ResourceDictionary x:Key="HighContrast">
<StaticResource x:Key="KeyChordVisualKeyBackground"
ResourceKey="SystemColorButtonFaceColorBrush" />
<StaticResource x:Key="KeyChordVisualKeyForeground"
ResourceKey="SystemColorButtonTextColorBrush" />
<StaticResource x:Key="KeyChordVisualKeyBorderBrush"
ResourceKey="SystemColorButtonTextColorBrush" />
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
<Style x:Key="KeyChordVisualKeyBorderStyle"
TargetType="Border">
<Setter Property="MinWidth" Value="32" />
<Setter Property="MinHeight" Value="28" />
<Setter Property="Padding" Value="8,2,8,2" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Background" Value="{ThemeResource KeyChordVisualKeyBackground}" />
<Setter Property="BorderBrush" Value="{ThemeResource KeyChordVisualKeyBorderBrush}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="CornerRadius" Value="{ThemeResource ControlCornerRadius}" />
</Style>
<Style x:Key="KeyChordVisualKeyTextStyle"
TargetType="TextBlock">
<Setter Property="FontSize" Value="13" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="TextAlignment" Value="Center" />
<Setter Property="Foreground" Value="{ThemeResource KeyChordVisualKeyForeground}" />
</Style>
<DataTemplate x:Key="KeyChordVisualTextKeyTemplate">
<Border Style="{StaticResource KeyChordVisualKeyBorderStyle}">
<TextBlock Style="{StaticResource KeyChordVisualKeyTextStyle}" />
</Border>
</DataTemplate>
<DataTemplate x:Key="KeyChordVisualWindowsKeyTemplate">
<Border Style="{StaticResource KeyChordVisualKeyBorderStyle}">
<Path Width="11"
Height="11"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Data="M9 20H0V11H9V20ZM20 20H11V11H20V20ZM9 9H0V0H9V9ZM20 9H11V0H20V9Z"
Fill="{ThemeResource KeyChordVisualKeyForeground}"
Stretch="Uniform" />
</Border>
</DataTemplate>
</ResourceDictionary>
</UserControl.Resources>
<StackPanel x:Name="KeysPanel"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Orientation="Horizontal"
Spacing="2" />
</UserControl>

View File

@@ -86,6 +86,9 @@
<ClInclude Include="KeyChordListener.h">
<DependentUpon>KeyChordListener.xaml</DependentUpon>
</ClInclude>
<ClInclude Include="KeyChordVisual.h">
<DependentUpon>KeyChordVisual.xaml</DependentUpon>
</ClInclude>
<ClInclude Include="Launch.h">
<DependentUpon>Launch.xaml</DependentUpon>
</ClInclude>
@@ -216,6 +219,9 @@
<Page Include="KeyChordListener.xaml">
<SubType>Designer</SubType>
</Page>
<Page Include="KeyChordVisual.xaml">
<SubType>Designer</SubType>
</Page>
<Page Include="Launch.xaml">
<SubType>Designer</SubType>
</Page>
@@ -297,6 +303,9 @@
<ClCompile Include="KeyChordListener.cpp">
<DependentUpon>KeyChordListener.xaml</DependentUpon>
</ClCompile>
<ClCompile Include="KeyChordVisual.cpp">
<DependentUpon>KeyChordVisual.xaml</DependentUpon>
</ClCompile>
<ClCompile Include="Launch.cpp">
<DependentUpon>Launch.xaml</DependentUpon>
</ClCompile>
@@ -427,6 +436,10 @@
<DependentUpon>KeyChordListener.xaml</DependentUpon>
<SubType>Code</SubType>
</Midl>
<Midl Include="KeyChordVisual.idl">
<DependentUpon>KeyChordVisual.xaml</DependentUpon>
<SubType>Code</SubType>
</Midl>
<Midl Include="Launch.idl">
<DependentUpon>Launch.xaml</DependentUpon>
<SubType>Code</SubType>

View File

@@ -54,6 +54,7 @@
<Page Include="SettingContainerStyle.xaml" />
<Page Include="AddProfile.xaml" />
<Page Include="KeyChordListener.xaml" />
<Page Include="KeyChordVisual.xaml" />
<Page Include="NullableColorPicker.xaml" />
<Page Include="IconPicker.xaml" />
<Page Include="NewTabMenu.xaml" />

View File

@@ -289,8 +289,8 @@
<comment>Header for a control to toggle whether the terminal should automatically detect URLs and make them clickable, or not.</comment>
</data>
<data name="Globals_SearchWebDefaultQueryUrl.Header" xml:space="preserve">
<value>Default URL to use for the "Search web" action</value>
<comment>Header for a control to set the query URL when using the "search web" action.</comment>
<value>Default URL to use for the "Search web" shortcut</value>
<comment>Header for a control to set the query URL when using the "search web" shortcut.</comment>
</data>
<data name="Globals_SearchWebDefaultQueryUrl.HelpText" xml:space="preserve">
<value>The placeholder "%s" will be replaced with the search query.</value>
@@ -590,7 +590,7 @@
<comment>Additional description for what the "force vt input" setting does. Presented near "Globals_ForceVTInput.Header".</comment>
</data>
<data name="Globals_AllowHeadless.HelpText" xml:space="preserve">
<value>This allows actions such as Global Summon and Quake Mode actions to work even when no windows are open.</value>
<value>This allows shortcuts such as Global Summon and Quake Mode shortcuts to work even when no windows are open.</value>
<comment>Additional description for what the "allow headless" setting does. Presented near "Globals_AllowHeadless.Header".</comment>
</data>
<data name="Globals_TabWidthMode.Header" xml:space="preserve">
@@ -682,12 +682,12 @@
<comment>Header for the "rendering" menu item. This navigates to a page that lets you see and modify settings related to the app's rendering of text in the terminal.</comment>
</data>
<data name="Nav_Actions.Content" xml:space="preserve">
<value>Actions</value>
<comment>Header for the "actions" menu item. This navigates to a page that lets you see the available commands in the app.</comment>
<value>Shortcuts</value>
<comment>Header for the "shortcuts" menu item. This navigates to a page that lets you see the available keyboard shortcuts in the app. (Resource key kept as "Nav_Actions" for stability.)</comment>
</data>
<data name="Nav_EditAction.Content" xml:space="preserve">
<value>Edit Action...</value>
<comment>Header for the "edit action" page. This is the page that lets you modify a specific command and its key bindings.</comment>
<value>Edit Shortcut...</value>
<comment>Header for the "edit shortcut" page. This is the page that lets you modify a specific command and its key bindings. (Resource key kept as "Nav_EditAction" for stability.)</comment>
</data>
<data name="Nav_Extensions.Content" xml:space="preserve">
<value>Extensions</value>
@@ -1766,28 +1766,28 @@
<comment>A description for what the delete unfocused appearance button does.</comment>
</data>
<data name="Actions_Disclaimer.Content" xml:space="preserve">
<value>Learn more about actions</value>
<comment>Disclaimer presented at the top of the actions page to redirect the user to documentation regarding actions.</comment>
<value>Learn more about shortcuts</value>
<comment>Disclaimer presented at the top of the shortcuts page to redirect the user to documentation regarding keyboard shortcuts.</comment>
</data>
<data name="Actions_DeleteButton2.Text" xml:space="preserve">
<value>Delete action</value>
<comment>Button label that deletes the selected action.</comment>
<value>Delete shortcut</value>
<comment>Button label that deletes the selected shortcut.</comment>
</data>
<data name="Actions_Name.Text" xml:space="preserve">
<value>Action name</value>
<comment>Label for the text box that edits the action name.</comment>
<value>Shortcut name</value>
<comment>Label for the text box that edits the shortcut name.</comment>
</data>
<data name="Actions_NameEntryBox.PlaceholderText" xml:space="preserve">
<value>Action name</value>
<comment>Placeholder text for the text box where the user can edit the action name.</comment>
<value>Shortcut name</value>
<comment>Placeholder text for the text box where the user can edit the shortcut name.</comment>
</data>
<data name="Actions_ShortcutAction.Text" xml:space="preserve">
<value>Action type</value>
<comment>Label for the combo box that edits the action type.</comment>
<value>Shortcut type</value>
<comment>Label for the combo box that edits the shortcut type (which action runs when this shortcut is invoked).</comment>
</data>
<data name="Actions_KeyBindingsListView.[using:Windows.UI.Xaml.Automation]AutomationProperties.Name" xml:space="preserve">
<value>Keybindings</value>
<comment>Name for a control which contains the list of keybindings for the current command.</comment>
<value>Shortcuts</value>
<comment>Name for a control which contains the list of keyboard shortcuts for the current command.</comment>
</data>
<data name="Actions_CommandDetails.Text" xml:space="preserve">
<value>Command details</value>
@@ -1798,44 +1798,44 @@
<comment>Label for the list of editable arguments for the currently selected action.</comment>
</data>
<data name="Actions_Keybindings.Text" xml:space="preserve">
<value>Keybindings</value>
<comment>Label for the list of editable keybindings for the current command.</comment>
<value>Shortcuts</value>
<comment>Label for the list of editable keyboard shortcuts for the current command.</comment>
</data>
<data name="Actions_AddKeyChord.Text" xml:space="preserve">
<value>Add keybinding</value>
<comment>Button label that adds a keybinding to the current action.</comment>
<value>Add shortcut</value>
<comment>Button label that adds a keyboard shortcut to the current action.</comment>
</data>
<data name="Actions_AdditionalKeyChords" xml:space="preserve">
<value>and {} more</value>
<comment>Text that will be read out by a screen reader indicating that additional keybindings exist for this command. {} will be replaced by the number of additional keybindings.</comment>
</data>
<data name="Actions_DeleteConfirmationButton.Content" xml:space="preserve">
<value>Yes, delete key binding</value>
<comment>Button label that confirms deletion of a key binding entry.</comment>
<value>Yes, delete shortcut</value>
<comment>Button label that confirms deletion of a keyboard shortcut entry.</comment>
</data>
<data name="Actions_DeleteConfirmationMessage.Text" xml:space="preserve">
<value>Are you sure you want to delete this key binding?</value>
<comment>Confirmation message displayed when the user attempts to delete a key binding entry.</comment>
<value>Are you sure you want to delete this shortcut?</value>
<comment>Confirmation message displayed when the user attempts to delete a keyboard shortcut entry.</comment>
</data>
<data name="Actions_CommandDeleteConfirmationButton.Content" xml:space="preserve">
<value>Yes, delete action</value>
<comment>Button label that confirms deletion of an action.</comment>
<value>Yes, delete shortcut</value>
<comment>Button label that confirms deletion of a shortcut entry.</comment>
</data>
<data name="Actions_CommandDeleteConfirmationMessage.Text" xml:space="preserve">
<value>Are you sure you want to delete this action?</value>
<comment>Confirmation message displayed when the user attempts to delete an action.</comment>
<value>Are you sure you want to delete this shortcut?</value>
<comment>Confirmation message displayed when the user attempts to delete a shortcut entry.</comment>
</data>
<data name="Actions_InvalidKeyChordMessage" xml:space="preserve">
<value>Invalid key chord. Please enter a valid key chord.</value>
<comment>Error message displayed when an invalid key chord is input by the user.</comment>
<value>Invalid shortcut. Please enter a valid keyboard shortcut.</value>
<comment>Error message displayed when an invalid keyboard shortcut is input by the user.</comment>
</data>
<data name="Actions_RenameConflictConfirmationAcceptButton" xml:space="preserve">
<value>Yes</value>
<comment>Button label that confirms the deletion of a conflicting key binding to allow the current key binding to be registered.</comment>
</data>
<data name="Actions_RenameConflictConfirmationMessage" xml:space="preserve">
<value>The provided key chord is already being used by the following action:</value>
<comment>Error message displayed when a key chord that is already in use is input by the user. The name of the conflicting key chord is displayed after this message.</comment>
<value>The provided shortcut is already being used by the following action:</value>
<comment>Error message displayed when a keyboard shortcut that is already in use is input by the user. The name of the conflicting shortcut is displayed after this message.</comment>
</data>
<data name="Actions_RenameConflictConfirmationQuestion" xml:space="preserve">
<value>Would you like to overwrite it?</value>
@@ -1862,12 +1862,60 @@
<comment>Text label for a button that can be used to begin making changes to a key binding entry.</comment>
</data>
<data name="Actions_AddNewTextBlock.Text" xml:space="preserve">
<value>Add new</value>
<comment>Button label that creates a new action on the actions page.</comment>
<value>Add new shortcut</value>
<comment>Button label that creates a new keyboard shortcut on the shortcuts page.</comment>
</data>
<data name="Actions_ActionComboBox.[using:Windows.UI.Xaml.Automation]AutomationProperties.Name" xml:space="preserve">
<value>Action</value>
<comment>Label for a control that sets the action of a key binding.</comment>
<data name="Actions_ViewAllKeyChordsButton.[using:Windows.UI.Xaml.Controls]ToolTipService.ToolTip" xml:space="preserve">
<value>View all shortcuts</value>
<comment>Tooltip for a button on each row of the Shortcuts page that opens a flyout listing every keyboard shortcut registered for that action.</comment>
</data>
<data name="Actions_NoKeyBindings.Text" xml:space="preserve">
<value>No shortcuts</value>
<comment>Empty-state message shown inside the "view all shortcuts" flyout (opened from each row's "..." button on the Shortcuts page) when the action has no keyboard shortcuts registered.</comment>
</data>
<data name="EditAction_ActionType.Header" xml:space="preserve">
<value>Shortcut type</value>
<comment>Header for the shortcut-type setting on the Edit Shortcut page (lets the user pick which action runs when this shortcut is invoked).</comment>
</data>
<data name="EditAction_ActionName.Header" xml:space="preserve">
<value>Shortcut name</value>
<comment>Header for the shortcut-name setting on the Edit Shortcut page (lets the user provide a friendly name for this shortcut).</comment>
</data>
<data name="EditAction_KeyBindings.Header" xml:space="preserve">
<value>Shortcuts</value>
<comment>Header for the shortcuts expander on the Edit Shortcut page.</comment>
</data>
<data name="EditAction_KeyBindings.HelpText" xml:space="preserve">
<value>Customize keyboard shortcuts to speed up common actions and workflows.</value>
<comment>Help text shown under the "Shortcuts" header on the Edit Shortcut page.</comment>
</data>
<data name="EditAction_NewKeyBinding.Header" xml:space="preserve">
<value>New shortcut</value>
<comment>Header for the "add a new shortcut" row on the Edit Shortcut page.</comment>
</data>
<data name="EditAction_AddKeyBinding.Content" xml:space="preserve">
<value>Add shortcut</value>
<comment>Label for the accent button that appends a new keyboard shortcut to the current action.</comment>
</data>
<data name="EditAction_AdditionalCustomizations.Header" xml:space="preserve">
<value>Additional customizations</value>
<comment>Header for the additional customizations expander on the Edit Action page (contains action name and per-action argument settings).</comment>
</data>
<data name="EditAction_AdditionalCustomizations.HelpText" xml:space="preserve">
<value>Fine tune how shortcuts behave.</value>
<comment>Help text shown under the "Additional customizations" header on the Edit Shortcut page.</comment>
</data>
<data name="EditAction_KeyBindingNumberFormat" xml:space="preserve">
<value>Shortcut #{}</value>
<comment>{Locked="#{}"} Header label for an individual keyboard shortcut inside the "Shortcuts" expander on the Edit Shortcut page. {} is replaced with the 1-based index of the shortcut (e.g. "Shortcut #1").</comment>
</data>
<data name="EditAction_DeleteCommand.Header" xml:space="preserve">
<value>Delete this shortcut</value>
<comment>Header for the setting container that holds the "Delete shortcut" button at the bottom of the Edit Shortcut page.</comment>
</data>
<data name="EditAction_DeleteCommand.HelpText" xml:space="preserve">
<value>This shortcut will be removed and any shortcuts associated with it will no longer work.</value>
<comment>Help text shown under the "Delete this shortcut" setting container on the Edit Shortcut page.</comment>
</data>
<data name="Actions_NullEnumValue" xml:space="preserve">
<value>Use global setting</value>

View File

@@ -121,6 +121,11 @@
<Thickness x:Key="SettingContainerIconMargin">0,4,8,4</Thickness>
<x:Double x:Key="SettingContainerIconFontSize">16</x:Double>
<!-- Shared sizing for SettingContainer-style "card" rows (used by SettingsCardStyle and Actions page rows). -->
<Thickness x:Key="SettingsCardPadding">16,8,8,8</Thickness>
<x:Double x:Key="SettingsCardMinHeight">64</x:Double>
<Thickness x:Key="SettingsCardItemMargin">0,4,0,0</Thickness>
<Style x:Key="StackPanelInExpanderStyle"
TargetType="StackPanel">
<Setter Property="VerticalAlignment" Value="Center" />
@@ -157,6 +162,21 @@
<Setter Property="CornerRadius" Value="{ThemeResource ControlCornerRadius}" />
</Style>
<!--
Similar to a local:SettingContainer without actually being one.
Used by data-templated rows (i.e. Actions page).
-->
<Style x:Key="SettingsCardStyle"
TargetType="Grid">
<Setter Property="MinHeight" Value="{StaticResource SettingsCardMinHeight}" />
<Setter Property="Padding" Value="{StaticResource SettingsCardPadding}" />
<Setter Property="Background" Value="{ThemeResource ExpanderHeaderBackground}" />
<Setter Property="BorderBrush" Value="{ThemeResource ExpanderHeaderBorderBrush}" />
<Setter Property="BorderThickness" Value="{ThemeResource ExpanderHeaderBorderThickness}" />
<Setter Property="CornerRadius" Value="{ThemeResource ControlCornerRadius}" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
</Style>
<Style x:Key="SettingsPageItemHeaderStyle"
BasedOn="{StaticResource BodyTextBlockStyle}"
TargetType="TextBlock">