From 7278d62307cff4195ce8d7120deb1f1b6f256ff5 Mon Sep 17 00:00:00 2001 From: Jaime Bernardo Date: Tue, 10 Aug 2021 15:03:04 +0100 Subject: [PATCH] [Settings] Announces open/close navigation pane (#12648) * [Settings] Announces open/close navigation pane * Add localization support --- .../Strings/en-us/Resources.resw | 14 ++++- .../Views/ShellPage.xaml | 2 + .../Views/ShellPage.xaml.cs | 58 +++++++++++++++++++ 3 files changed, 71 insertions(+), 3 deletions(-) diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Strings/en-us/Resources.resw b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Strings/en-us/Resources.resw index a3a4ce388d..d34379b9d6 100644 --- a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Strings/en-us/Resources.resw +++ b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Strings/en-us/Resources.resw @@ -249,6 +249,14 @@ Disabling this module or closing PowerToys will unmute the microphone and camera Keyboard Manager Product name: Navigation view item name for Keyboard Manager + + Navigation closed + Accessibility announcement when the navigation pane collapses + + + Navigation opened + Accessibility announcement when the navigation pane opens + Current configuration Keyboard Manager current configuration header @@ -1376,14 +1384,14 @@ From there, simply click on a Markdown file or SVG icon in the File Explorer and Are you sure you want to delete this item? - + Yes Label of a confirmation button - + Learn more - + Show format in editor \ No newline at end of file diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Views/ShellPage.xaml b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Views/ShellPage.xaml index 87ef6bef0e..db375f5f2c 100644 --- a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Views/ShellPage.xaml +++ b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Views/ShellPage.xaml @@ -28,6 +28,8 @@ OpenPaneLength="296" CompactModeThresholdWidth="0" Background="{ThemeResource SystemControlBackgroundAltHighBrush}" + PaneOpened="NavigationView_PaneOpened" + PaneClosed="NavigationView_PaneClosed" SelectionChanged="NavigationView_SelectionChanged"> diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Views/ShellPage.xaml.cs b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Views/ShellPage.xaml.cs index 110104ee75..9791021990 100644 --- a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Views/ShellPage.xaml.cs +++ b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Views/ShellPage.xaml.cs @@ -7,7 +7,9 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using Microsoft.PowerToys.Settings.UI.Services; using Microsoft.PowerToys.Settings.UI.ViewModels; +using Windows.ApplicationModel.Resources; using Windows.Data.Json; +using Windows.UI.Xaml.Automation.Peers; using Windows.UI.Xaml.Controls; namespace Microsoft.PowerToys.Settings.UI.Views @@ -161,5 +163,61 @@ namespace Microsoft.PowerToys.Settings.UI.Views { scrollViewer.ChangeView(null, 0, null, true); } + + private bool navigationViewInitialStateProcessed; // avoid announcing initial state of the navigation pane. + + [SuppressMessage("Usage", "CA1801:Review unused parameters", Justification = "Params are required for event handler signature requirements.")] +#pragma warning disable CA1822 // Mark members as static + private void NavigationView_PaneOpened(Microsoft.UI.Xaml.Controls.NavigationView sender, object args) + { + if (!navigationViewInitialStateProcessed) + { + navigationViewInitialStateProcessed = true; + return; + } + + var peer = FrameworkElementAutomationPeer.FromElement(sender); + if (peer == null) + { + peer = FrameworkElementAutomationPeer.CreatePeerForElement(sender); + } + + if (AutomationPeer.ListenerExists(AutomationEvents.MenuOpened)) + { + var loader = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView(); + peer.RaiseNotificationEvent( + AutomationNotificationKind.ActionCompleted, + AutomationNotificationProcessing.ImportantMostRecent, + loader.GetString("Shell_NavigationMenu_Announce_Open"), + "navigationMenuPaneOpened"); + } + } + + [SuppressMessage("Usage", "CA1801:Review unused parameters", Justification = "Params are required for event handler signature requirements.")] + private void NavigationView_PaneClosed(Microsoft.UI.Xaml.Controls.NavigationView sender, object args) + { + if (!navigationViewInitialStateProcessed) + { + navigationViewInitialStateProcessed = true; + return; + } + + var peer = FrameworkElementAutomationPeer.FromElement(sender); + if (peer == null) + { + peer = FrameworkElementAutomationPeer.CreatePeerForElement(sender); + } + + if (AutomationPeer.ListenerExists(AutomationEvents.MenuClosed)) + { + var loader = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView(); + peer.RaiseNotificationEvent( + AutomationNotificationKind.ActionCompleted, + AutomationNotificationProcessing.ImportantMostRecent, + loader.GetString("Shell_NavigationMenu_Announce_Collapse"), + "navigationMenuPaneClosed"); + } + } +#pragma warning restore CA1822 // Mark members as static } }