Skip to content

Commit 752de8f

Browse files
authored
Give Avalonia controls real accessible names (#5498, #5499) (#5501)
1 parent 7da7f7c commit 752de8f

6 files changed

Lines changed: 76 additions & 16 deletions

File tree

‎src/Languages/lang_en.json‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1917,5 +1917,9 @@
19171917
"The GitHub sign-in code has expired. Please try again.": "The GitHub sign-in code has expired. Please try again.",
19181918
"WinGet repair exited with code {0}.": "WinGet repair exited with code {0}.",
19191919
"Waiting for another {0} operation to finish...": "Waiting for another {0} operation to finish...",
1920-
"A file of {package} is in use by another program. Close any program that may be using it, then try again": "A file of {package} is in use by another program. Close any program that may be using it, then try again"
1920+
"A file of {package} is in use by another program. Close any program that may be using it, then try again": "A file of {package} is in use by another program. Close any program that may be using it, then try again",
1921+
"Previous screenshot": "Previous screenshot",
1922+
"Next screenshot": "Next screenshot",
1923+
"Screenshot {0} of {1}": "Screenshot {0} of {1}",
1924+
"Screenshot {0} of {1}, current": "Screenshot {0} of {1}, current"
19211925
}

‎src/UniGetUI.Avalonia/Assets/Styles/Styles.Common.axaml‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
33
xmlns:controls="using:UniGetUI.Avalonia.Views.Controls"
44
xmlns:settings="using:UniGetUI.Avalonia.Views.Controls.Settings"
5-
xmlns:primitives="using:Avalonia.Controls.Primitives">
5+
xmlns:primitives="using:Avalonia.Controls.Primitives"
6+
xmlns:automation="clr-namespace:Avalonia.Automation;assembly=Avalonia.Controls">
67

78
<Styles.Resources>
89
<ResourceDictionary>
@@ -632,6 +633,14 @@
632633
</Setter>
633634
</Style>
634635

636+
<Style Selector="Expander /template/ ToggleButton#ExpanderHeader">
637+
<Setter Property="automation:AutomationProperties.Name" Value="{TemplateBinding automation:AutomationProperties.Name}"/>
638+
</Style>
639+
640+
<Style Selector="DataGridCell">
641+
<Setter Property="automation:AutomationProperties.Name" Value="{Binding $self.((Control)Content).(automation:AutomationProperties.Name)}"/>
642+
</Style>
643+
635644
<Style Selector="RadioButton:checked /template/ Ellipse#CheckOuterEllipse">
636645
<Setter Property="Fill" Value="{DynamicResource AccentFillColorDefaultBrush}"/>
637646
<Setter Property="Stroke" Value="{DynamicResource AccentFillColorDefaultBrush}"/>

‎src/UniGetUI.Avalonia/Models/PackageCollections.cs‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,20 @@ public bool IsChecked
203203
public string InstallerHostText { get; private set; } = "";
204204
public string? InstallerHostTooltip { get; private set; }
205205

206+
public string VersionAutomationName =>
207+
InstalledVersionIsUnverified && InstalledVersionTooltip is { } notice
208+
? $"{VersionComboString}, {notice}"
209+
: VersionComboString;
210+
211+
public string NewVersionAutomationName =>
212+
WithInstallerHostWarning(Package.NewVersionString);
213+
214+
public string InstallerHostAutomationName =>
215+
WithInstallerHostWarning(InstallerHostText);
216+
217+
private string WithInstallerHostWarning(string value) =>
218+
InstallerHostChanged ? $"{value}, {InstallerHostChangeTooltip}" : value;
219+
206220
public string DownloadSizeText { get; private set; } = "";
207221
public long DownloadSizeBytes { get; private set; }
208222

@@ -365,6 +379,7 @@ private void ApplyInstallerHost(string host, string urls)
365379
InstallerHostTooltip = urls.Length > 0 ? urls : null;
366380
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(InstallerHostText)));
367381
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(InstallerHostTooltip)));
382+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(InstallerHostAutomationName)));
368383
}
369384

370385
private static bool TryGetCachedInstallerHost(long hash, out (string Host, string Urls) entry)
@@ -620,6 +635,14 @@ await Dispatcher.UIThread.InvokeAsync(() =>
620635
this,
621636
new PropertyChangedEventArgs(nameof(InstallerHostChangeTooltip))
622637
);
638+
PropertyChanged?.Invoke(
639+
this,
640+
new PropertyChangedEventArgs(nameof(NewVersionAutomationName))
641+
);
642+
PropertyChanged?.Invoke(
643+
this,
644+
new PropertyChangedEventArgs(nameof(InstallerHostAutomationName))
645+
);
623646
});
624647
}
625648
catch (Exception ex)

‎src/UniGetUI.Avalonia/Views/DialogPages/PackageDetailsWindow.axaml‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@
254254
<Button x:Name="ActionVariantsButton"
255255
Grid.Column="2"
256256
Classes="accent action-chevron"
257-
automation:AutomationProperties.Name="{Binding MainActionLabel}">
257+
automation:AutomationProperties.Name="{t:Translate More options}">
258258
<Path Data="M 0,0 L 4,4 L 8,0"
259259
Stroke="{DynamicResource TextOnAccentFillColorPrimaryBrush}"
260260
StrokeThickness="1.5"
@@ -279,7 +279,8 @@
279279
IsExpanded="False"
280280
CornerRadius="8"
281281
Padding="0"
282-
Background="Transparent">
282+
Background="Transparent"
283+
automation:AutomationProperties.Name="{Binding LabelInstallationOptions}">
283284
<Expander.Header>
284285
<Grid ColumnDefinitions="Auto,*,Auto"
285286
ColumnSpacing="12">
@@ -362,7 +363,8 @@
362363
Classes="carousel-nav"
363364
HorizontalAlignment="Left"
364365
Margin="6,0,0,0"
365-
IsVisible="{Binding HasScreenshots}">
366+
IsVisible="{Binding HasScreenshots}"
367+
automation:AutomationProperties.Name="{t:Translate Previous screenshot}">
366368
<!-- WinUI FlipView's EDD9 CaretLeftSolid8, expressed as geometry so it
367369
stays identical on systems without Segoe Fluent Icons. -->
368370
<Path Data="M 5,0 L 0,4 L 5,8 Z"
@@ -373,7 +375,8 @@
373375
Classes="carousel-nav"
374376
HorizontalAlignment="Right"
375377
Margin="0,0,6,0"
376-
IsVisible="{Binding HasScreenshots}">
378+
IsVisible="{Binding HasScreenshots}"
379+
automation:AutomationProperties.Name="{t:Translate Next screenshot}">
377380
<!-- WinUI FlipView's EDDA CaretRightSolid8 glyph. -->
378381
<Path Data="M 0,0 L 5,4 L 0,8 Z"
379382
Width="5" Height="8"

‎src/UniGetUI.Avalonia/Views/DialogPages/PackageDetailsWindow.axaml.cs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.ComponentModel;
22
using System.Diagnostics;
33
using Avalonia;
4+
using Avalonia.Automation;
45
using Avalonia.Controls;
56
using Avalonia.Controls.Documents;
67
using Avalonia.Controls.Shapes;
@@ -665,6 +666,16 @@ private void UpdatePips()
665666
foreach (var container in ScreenshotPips.GetRealizedContainers())
666667
{
667668
int index = ScreenshotPips.IndexFromContainer(container);
669+
Button? pip = container as Button
670+
?? container.GetVisualDescendants().OfType<Button>().FirstOrDefault();
671+
if (pip is not null)
672+
{
673+
AutomationProperties.SetName(
674+
pip,
675+
index == active
676+
? CoreTools.Translate("Screenshot {0} of {1}, current", index + 1, _vm.ScreenshotCount)
677+
: CoreTools.Translate("Screenshot {0} of {1}", index + 1, _vm.ScreenshotCount));
678+
}
668679
Ellipse? ellipse = container is Button { Content: Ellipse direct }
669680
? direct
670681
: container.GetVisualDescendants()

‎src/UniGetUI.Avalonia/Views/SoftwarePages/AbstractPackagesPage.axaml‎

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,8 @@
393393
IsExpanded="True"
394394
CornerRadius="8"
395395
Padding="16,8,16,8"
396-
Background="{DynamicResource FilterExpanderContentBackground}">
396+
Background="{DynamicResource FilterExpanderContentBackground}"
397+
automation:AutomationProperties.Name="{t:Translate Sources}">
397398
<Expander.Header>
398399
<Grid ColumnDefinitions="Auto,*" ColumnSpacing="8">
399400
<controls:SvgIcon Grid.Column="0"
@@ -457,7 +458,8 @@
457458
<DataTemplate x:DataType="vm:SourceTreeNode">
458459
<StackPanel>
459460
<CheckBox IsChecked="{Binding IsSelected, Mode=TwoWay}"
460-
VerticalAlignment="Center">
461+
VerticalAlignment="Center"
462+
automation:AutomationProperties.Name="{Binding PackageName}">
461463
<CheckBox.Content>
462464
<Grid ColumnDefinitions="Auto,*" ColumnSpacing="4">
463465
<ToggleButton Grid.Column="0" IsChecked="{Binding IsExpanded, Mode=TwoWay}"
@@ -520,7 +522,8 @@
520522
IsExpanded="False"
521523
CornerRadius="8"
522524
Padding="16,8,16,8"
523-
Background="{DynamicResource FilterExpanderContentBackground}">
525+
Background="{DynamicResource FilterExpanderContentBackground}"
526+
automation:AutomationProperties.Name="{t:Translate Filters}">
524527
<Expander.Header>
525528
<Grid ColumnDefinitions="Auto,*" ColumnSpacing="8">
526529
<controls:SvgIcon Grid.Column="0"
@@ -559,7 +562,8 @@
559562
IsExpanded="True"
560563
CornerRadius="8"
561564
Padding="16,8,16,8"
562-
Background="{DynamicResource FilterExpanderContentBackground}">
565+
Background="{DynamicResource FilterExpanderContentBackground}"
566+
automation:AutomationProperties.Name="{t:Translate Search mode}">
563567
<Expander.Header>
564568
<Grid ColumnDefinitions="Auto,*" ColumnSpacing="8">
565569
<controls:SvgIcon Grid.Column="0"
@@ -765,7 +769,8 @@
765769
Width="*">
766770
<DataGridTemplateColumn.CellTemplate>
767771
<DataTemplate x:DataType="pkg:PackageWrapper">
768-
<Grid ColumnDefinitions="Auto,*" ColumnSpacing="6" VerticalAlignment="Center" Margin="4,0">
772+
<Grid ColumnDefinitions="Auto,*" ColumnSpacing="6" VerticalAlignment="Center" Margin="4,0"
773+
automation:AutomationProperties.Name="{Binding Package.Id}">
769774
<controls:SvgIcon Grid.Column="0" Path="avares://UniGetUI/Assets/Symbols/id.svg"
770775
Width="24" Height="24" VerticalAlignment="Center"/>
771776
<TextBlock Grid.Column="1" Text="{Binding Package.Id}" VerticalAlignment="Center"
@@ -779,7 +784,8 @@
779784
Width="*">
780785
<DataGridTemplateColumn.CellTemplate>
781786
<DataTemplate x:DataType="pkg:PackageWrapper">
782-
<Grid ColumnDefinitions="Auto,*" ColumnSpacing="6" VerticalAlignment="Center" Margin="4,0">
787+
<Grid ColumnDefinitions="Auto,*" ColumnSpacing="6" VerticalAlignment="Center" Margin="4,0"
788+
automation:AutomationProperties.Name="{Binding VersionAutomationName}">
783789
<controls:SvgIcon Grid.Column="0" Path="avares://UniGetUI/Assets/Symbols/version.svg"
784790
Width="24" Height="24" VerticalAlignment="Center"
785791
IsVisible="{Binding !InstalledVersionIsUnverified}"/>
@@ -801,7 +807,8 @@
801807
IsVisible="{Binding $parent[UserControl].((vm:PackagesPageViewModel)DataContext).NewVersionHeaderVisible}">
802808
<DataGridTemplateColumn.CellTemplate>
803809
<DataTemplate x:DataType="pkg:PackageWrapper">
804-
<Grid ColumnDefinitions="Auto,*" ColumnSpacing="6" VerticalAlignment="Center" Margin="4,0">
810+
<Grid ColumnDefinitions="Auto,*" ColumnSpacing="6" VerticalAlignment="Center" Margin="4,0"
811+
automation:AutomationProperties.Name="{Binding NewVersionAutomationName}">
805812
<controls:SvgIcon Grid.Column="0" Path="avares://UniGetUI/Assets/Symbols/download.svg"
806813
Width="24" Height="24" VerticalAlignment="Center"
807814
IsVisible="{Binding !InstallerHostChanged}"/>
@@ -821,7 +828,8 @@
821828
Width="*">
822829
<DataGridTemplateColumn.CellTemplate>
823830
<DataTemplate x:DataType="pkg:PackageWrapper">
824-
<Grid ColumnDefinitions="Auto,*" ColumnSpacing="6" VerticalAlignment="Center" Margin="4,0">
831+
<Grid ColumnDefinitions="Auto,*" ColumnSpacing="6" VerticalAlignment="Center" Margin="4,0"
832+
automation:AutomationProperties.Name="{Binding Package.Source.AsString_DisplayName}">
825833
<controls:SvgIcon Grid.Column="0" Path="{Binding SourceIconPath}"
826834
Width="24" Height="24" VerticalAlignment="Center"/>
827835
<TextBlock Grid.Column="1" Text="{Binding Package.Source.AsString_DisplayName}" VerticalAlignment="Center"
@@ -837,7 +845,8 @@
837845
<DataGridTemplateColumn.CellTemplate>
838846
<DataTemplate x:DataType="pkg:PackageWrapper">
839847
<Grid ColumnDefinitions="Auto,*" ColumnSpacing="6" VerticalAlignment="Center" Margin="4,0"
840-
controls:PackageRowValueLoader.Track="True">
848+
controls:PackageRowValueLoader.Track="True"
849+
automation:AutomationProperties.Name="{Binding InstallerHostAutomationName}">
841850
<controls:SvgIcon Grid.Column="0" Path="avares://UniGetUI/Assets/Symbols/launch.svg"
842851
Width="24" Height="24" VerticalAlignment="Center"
843852
IsVisible="{Binding !InstallerHostChanged}"/>
@@ -860,7 +869,8 @@
860869
<DataGridTemplateColumn.CellTemplate>
861870
<DataTemplate x:DataType="pkg:PackageWrapper">
862871
<Grid ColumnDefinitions="Auto,*" ColumnSpacing="6" VerticalAlignment="Center" Margin="4,0"
863-
controls:PackageRowValueLoader.Track="True">
872+
controls:PackageRowValueLoader.Track="True"
873+
automation:AutomationProperties.Name="{Binding DownloadSizeText}">
864874
<controls:SvgIcon Grid.Column="0" Path="avares://UniGetUI/Assets/Symbols/disk.svg"
865875
Width="24" Height="24" VerticalAlignment="Center"/>
866876
<TextBlock Grid.Column="1" Text="{Binding DownloadSizeText}" VerticalAlignment="Center"

0 commit comments

Comments
 (0)