Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AdvancedPaste] Fixed issues with Screen Reader integration #36778

Merged
merged 2 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using AdvancedPaste.Models;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;

namespace AdvancedPaste.Controls;

public sealed partial class PasteFormatTemplateSelector : DataTemplateSelector
{
public DataTemplate ItemTemplate { get; set; }

public DataTemplate ItemTemplateDisabled { get; set; }

protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
{
bool isEnabled = item is PasteFormat pasteFormat && pasteFormat.IsEnabled;

if (container is SelectorItem selector)
{
selector.IsEnabled = isEnabled;
}

return isEnabled ? ItemTemplate : ItemTemplateDisabled;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -410,26 +410,28 @@
Spacing="2">
<Button
Padding="4"
AutomationProperties.LabeledBy="{x:Bind ThumbsUpFeedback}"
Click="ThumbUpDown_Click"
CommandParameter="True"
Content="{ui:FontIcon Glyph=&#xE8E1;,
FontSize=14}"
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
Style="{StaticResource SubtleButtonStyle}">
<ToolTipService.ToolTip>
<TextBlock x:Uid="ThumbsUpFeedback" />
<TextBlock x:Name="ThumbsUpFeedback" x:Uid="ThumbsUpFeedback" />
</ToolTipService.ToolTip>
</Button>
<Button
Padding="4"
AutomationProperties.LabeledBy="{x:Bind ThumbsDownFeedback}"
Click="ThumbUpDown_Click"
CommandParameter="False"
Content="{ui:FontIcon Glyph=&#xE8E0;,
FontSize=14}"
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
Style="{StaticResource SubtleButtonStyle}">
<ToolTipService.ToolTip>
<TextBlock x:Uid="ThumbsDownFeedback" />
<TextBlock x:Name="ThumbsDownFeedback" x:Uid="ThumbsDownFeedback" />
</ToolTipService.ToolTip>
</Button>
</StackPanel>
Expand Down Expand Up @@ -537,6 +539,7 @@
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
ui:VisualExtensions.NormalizedCenterPoint="0.5,0.5"
AutomationProperties.HelpText="{x:Bind ViewModel.CustomAIUnavailableErrorText, Mode=OneWay}"
Command="{x:Bind GenerateCustomAICommand}"
Content="{ui:FontIcon Glyph=&#xE724;,
FontSize=16}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,77 @@
x:Name="customActionsToMinHeightConverter"
ValueIfNonZero="40"
ValueIfZero="0" />
<controls:PasteFormatTemplateSelector x:Key="PasteFormatTemplateSelector">
<controls:PasteFormatTemplateSelector.ItemTemplate>
<DataTemplate x:DataType="local:PasteFormat">
<Grid
Margin="0"
Padding="-9,0,0,0"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
AutomationProperties.AcceleratorKey="{x:Bind ShortcutText, Mode=OneWay}"
AutomationProperties.AutomationControlType="ListItem"
AutomationProperties.FullDescription="{x:Bind ToolTip, Mode=OneWay}"
AutomationProperties.HelpText="{x:Bind Name, Mode=OneWay}"
AutomationProperties.Name="{x:Bind AccessibleName, Mode=OneWay}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="26" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ToolTipService.ToolTip>
<TextBlock Text="{x:Bind ToolTip, Mode=OneWay}" />
</ToolTipService.ToolTip>
<FontIcon
Margin="0,0,0,0"
VerticalAlignment="Center"
AutomationProperties.AccessibilityView="Raw"
FontSize="16"
Glyph="{x:Bind IconGlyph, Mode=OneWay}" />
<TextBlock
Grid.Column="1"
VerticalAlignment="Center"
x:Phase="1"
Text="{x:Bind Name, Mode=OneWay}" />
<TextBlock
Grid.Column="2"
Margin="0,0,8,0"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
Style="{StaticResource CaptionTextBlockStyle}"
Text="{x:Bind ShortcutText, Mode=OneWay}" />
</Grid>
</DataTemplate>
</controls:PasteFormatTemplateSelector.ItemTemplate>
<controls:PasteFormatTemplateSelector.ItemTemplateDisabled>
<DataTemplate x:DataType="local:PasteFormat" AutomationProperties.AccessibilityView="Raw">
<Grid
Margin="0"
Padding="-9,0,0,0"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
AutomationProperties.AccessibilityView="Raw"
Opacity="0.5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="26" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<FontIcon
Margin="0,0,0,0"
VerticalAlignment="Center"
FontSize="16"
Glyph="{x:Bind IconGlyph, Mode=OneWay}" />
<TextBlock
Grid.Column="1"
VerticalAlignment="Center"
x:Phase="1"
Text="{x:Bind Name, Mode=OneWay}" />
</Grid>
</DataTemplate>
</controls:PasteFormatTemplateSelector.ItemTemplateDisabled>
</controls:PasteFormatTemplateSelector>
<Style
x:Key="PaddingLessFlyoutPresenterStyle"
BasedOn="{StaticResource DefaultFlyoutPresenterStyle}"
Expand All @@ -29,57 +100,6 @@
<Setter Property="Padding" Value="0" />
</Style.Setters>
</Style>
<Style x:Key="PasteFormatListViewItemStyle" TargetType="ListViewItem">
<Setter Property="Padding" Value="0" />
<Setter Property="Margin" Value="0" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Stretch" />
</Style>
<DataTemplate x:Key="PasteFormatTemplate" x:DataType="local:PasteFormat">
<Button
Margin="0"
Padding="5,0,5,0"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
AllowFocusOnInteraction="False"
BorderThickness="0"
Click="ListView_Button_Click"
IsEnabled="{x:Bind IsEnabled, Mode=OneWay}">
<Grid Opacity="{x:Bind Opacity, Mode=OneWay}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="26" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<ToolTipService.ToolTip>
<TextBlock Text="{x:Bind ToolTip, Mode=OneWay}" />
</ToolTipService.ToolTip>
<FontIcon
Margin="0,0,0,0"
VerticalAlignment="Center"
AutomationProperties.AccessibilityView="Raw"
FontSize="16"
Glyph="{x:Bind IconGlyph, Mode=OneWay}" />
<TextBlock
Grid.Column="1"
VerticalAlignment="Center"
x:Phase="1"
Text="{x:Bind Name, Mode=OneWay}" />
<TextBlock
Grid.Column="2"
Margin="0,0,8,0"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
Style="{StaticResource CaptionTextBlockStyle}"
Text="{x:Bind ShortcutText, Mode=OneWay}"
Visibility="{x:Bind ShortcutText.Length, Mode=OneWay, Converter={StaticResource countToVisibilityConverter}}" />
</Grid>
</Button>
</DataTemplate>
</Page.Resources>
<Page.KeyboardAccelerators>
<KeyboardAccelerator Key="Escape" Invoked="KeyboardAccelerator_Invoked" />
Expand Down Expand Up @@ -196,10 +216,10 @@
x:Name="PasteOptionsListView"
Grid.Row="0"
VerticalAlignment="Bottom"
IsItemClickEnabled="False"
ItemContainerStyle="{StaticResource PasteFormatListViewItemStyle}"
IsItemClickEnabled="True"
ItemClick="PasteFormat_ItemClick"
ItemContainerTransitions="{x:Null}"
ItemTemplate="{StaticResource PasteFormatTemplate}"
ItemTemplateSelector="{StaticResource PasteFormatTemplateSelector}"
ItemsSource="{x:Bind ViewModel.StandardPasteFormats, Mode=OneWay}"
ScrollViewer.VerticalScrollBarVisibility="Visible"
ScrollViewer.VerticalScrollMode="Auto"
Expand All @@ -217,10 +237,10 @@
x:Name="CustomActionsListView"
Grid.Row="2"
VerticalAlignment="Top"
IsItemClickEnabled="False"
ItemContainerStyle="{StaticResource PasteFormatListViewItemStyle}"
IsItemClickEnabled="True"
ItemClick="PasteFormat_ItemClick"
ItemContainerTransitions="{x:Null}"
ItemTemplate="{StaticResource PasteFormatTemplate}"
ItemTemplateSelector="{StaticResource PasteFormatTemplateSelector}"
ItemsSource="{x:Bind ViewModel.CustomActionPasteFormats, Mode=OneWay}"
ScrollViewer.VerticalScrollBarVisibility="Visible"
ScrollViewer.VerticalScrollMode="Auto"
Expand All @@ -232,7 +252,6 @@
Height="1"
HorizontalAlignment="Stretch"
Fill="{ThemeResource DividerStrokeColorDefaultBrush}" />
<!-- x:Uid="ClipboardHistoryButton" -->
<Button
Grid.Row="4"
Height="32"
Expand All @@ -241,6 +260,7 @@
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
AutomationProperties.LabeledBy="{x:Bind ClipboardHistoryButton}"
IsEnabled="{x:Bind ViewModel.ClipboardHistoryEnabled, Mode=TwoWay}"
Style="{StaticResource SubtleButtonStyle}">
<Grid
Expand All @@ -259,6 +279,7 @@
FontSize="16"
Glyph="&#xE81C;" />
<TextBlock
x:Name="ClipboardHistoryButton"
x:Uid="ClipboardHistoryButton"
Grid.Column="1"
VerticalAlignment="Center" />
Expand Down Expand Up @@ -287,6 +308,7 @@
<Grid
Height="40"
HorizontalAlignment="Stretch"
AutomationProperties.Name="{x:Bind Description, Mode=OneWay}"
ColumnSpacing="8"
ToolTipService.ToolTip="{x:Bind Content}">
<Grid.ColumnDefinitions>
Expand All @@ -308,7 +330,8 @@
TextTrimming="CharacterEllipsis"
Visibility="Visible" />
<Button
x:Name="moreInfo"
x:Name="ClipboardHistoryItemMoreOptionsButton"
x:Uid="ClipboardHistoryItemMoreOptionsButton"
Grid.Column="1"
VerticalAlignment="Center"
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ private void ClipboardHistoryItemDeleteButton_Click(object sender, RoutedEventAr
}
}

private async void ListView_Button_Click(object sender, RoutedEventArgs e)
private async void PasteFormat_ItemClick(object sender, ItemClickEventArgs e)
{
if (sender is Button { DataContext: PasteFormat format })
if (e.ClickedItem is PasteFormat format)
{
await ViewModel.ExecutePasteFormatAsync(format, PasteActionSource.ContextMenu);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using AdvancedPaste.Helpers;
using Microsoft.UI.Xaml.Media.Imaging;
using Windows.ApplicationModel.DataTransfer;

Expand All @@ -14,4 +15,8 @@ public class ClipboardItem
public ClipboardHistoryItem Item { get; set; }

public BitmapImage Image { get; set; }

public string Description => !string.IsNullOrEmpty(Content) ? Content :
Image is not null ? ResourceLoaderInstance.ResourceLoader.GetString("ClipboardHistoryImage") :
string.Empty;
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static PasteFormat CreateCustomAIFormat(PasteFormats format, string name,

public bool IsEnabled { get; private init; }

public double Opacity => IsEnabled ? 1 : 0.5;
public string AccessibleName => $"{Name} ({ShortcutText})";

public string ToolTip => string.IsNullOrEmpty(Prompt) ? $"{Name} ({ShortcutText})" : Prompt;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@
<data name="ClipboardHistoryButton.Text" xml:space="preserve">
<value>Clipboard history</value>
</data>
<data name="ClipboardHistoryButton.[using:Microsoft.UI.Xaml.Automation]AutomationProperties.Name" xml:space="preserve">
<value>Clipboard history</value>
</data>
<data name="ClipboardHistoryImage" xml:space="preserve">
<value>Image data</value>
</data>
<data name="ClipboardHistoryItemMoreOptionsButton.[using:Microsoft.UI.Xaml.Automation]AutomationProperties.Name" xml:space="preserve">
<value>More options</value>
</data>
<data name="ClipboardHistoryItemDeleteButton.Text" xml:space="preserve">
<value>Delete</value>
</data>
Expand Down
Loading