Compare commits

...

2 Commits

Author SHA1 Message Date
copilot-swe-agent[bot]
ecd0dde13e Fix ZoomIt ShortcutControl automation names and peers
Agent-Logs-Url: https://github.com/microsoft/PowerToys/sessions/524885d7-7c19-41d4-a48e-2130072f6489

Co-authored-by: niels9001 <9866362+niels9001@users.noreply.github.com>
2026-04-23 07:58:49 +00:00
copilot-swe-agent[bot]
563f55b36c Initial plan 2026-04-23 07:49:40 +00:00
3 changed files with 134 additions and 12 deletions

View File

@@ -16,6 +16,7 @@ using Microsoft.PowerToys.Settings.UI.Views;
using Microsoft.PowerToys.Telemetry;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Automation;
using Microsoft.UI.Xaml.Automation.Peers;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
@@ -289,11 +290,16 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
};
shortcutDialog.RightTapped += ShortcutDialog_Disable;
AutomationProperties.SetName(EditButton, resourceLoader.GetString("Activation_Shortcut_Title"));
UpdateAutomationName();
OnAllowDisableChanged(this, null);
}
protected override AutomationPeer OnCreateAutomationPeer()
{
return new ShortcutControlAutomationPeer(this);
}
private void C_LearnMoreClick(object sender, RoutedEventArgs e)
{
// Close the current shortcut dialog
@@ -368,6 +374,7 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
// Initialize tooltip when loaded
UpdateTooltip();
UpdateAutomationName();
}
private void KeyEventHandler(int key, bool matchValue, int matchValueCode)
@@ -813,18 +820,50 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
private void SetKeys()
{
var keys = HotkeySettings?.GetKeysList();
string helpText;
if (keys != null && keys.Count > 0)
{
VisualStateManager.GoToState(this, "Configured", true);
PreviewKeysControl.ItemsSource = keys;
AutomationProperties.SetHelpText(EditButton, HotkeySettings.ToString());
helpText = HotkeySettings.ToString();
}
else
{
VisualStateManager.GoToState(this, "Normal", true);
AutomationProperties.SetHelpText(EditButton, resourceLoader.GetString("ConfigureShortcut"));
helpText = resourceLoader.GetString("ConfigureShortcut");
}
AutomationProperties.SetHelpText(EditButton, helpText);
AutomationProperties.SetHelpText(this, helpText);
}
internal void Invoke()
{
OpenDialogButton_Click(EditButton, new RoutedEventArgs());
}
internal string GetAutomationValue()
{
return HotkeySettings?.GetKeysList()?.Count > 0
? HotkeySettings.ToString()
: resourceLoader.GetString("ConfigureShortcut");
}
internal string GetAutomationName()
{
var name = AutomationProperties.GetName(this);
return string.IsNullOrWhiteSpace(name) ? resourceLoader.GetString("Activation_Shortcut_Title") : name;
}
internal bool IsShortcutEnabled()
{
return EditButton?.IsEnabled ?? false;
}
private void UpdateAutomationName()
{
AutomationProperties.SetName(EditButton, GetAutomationName());
}
}
}

View File

@@ -0,0 +1,63 @@
// 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 System;
using Microsoft.UI.Xaml.Automation.Peers;
using Microsoft.UI.Xaml.Automation.Provider;
namespace Microsoft.PowerToys.Settings.UI.Controls
{
public partial class ShortcutControlAutomationPeer : FrameworkElementAutomationPeer, IInvokeProvider, IValueProvider
{
public ShortcutControlAutomationPeer(ShortcutControl owner)
: base(owner)
{
}
protected override string GetClassNameCore() => nameof(ShortcutControl);
protected override AutomationControlType GetAutomationControlTypeCore()
=> AutomationControlType.Button;
protected override string GetNameCore()
{
var owner = (ShortcutControl)Owner;
var name = owner.GetAutomationName();
return string.IsNullOrWhiteSpace(name)
? base.GetNameCore()
: name;
}
public override object GetPattern(PatternInterface patternInterface)
{
return patternInterface switch
{
PatternInterface.Invoke => this,
PatternInterface.Value => this,
_ => base.GetPattern(patternInterface),
};
}
public void Invoke()
{
var owner = (ShortcutControl)Owner;
if (!owner.IsShortcutEnabled())
{
throw new InvalidOperationException("Cannot invoke shortcut control: the control is currently disabled.");
}
owner.Invoke();
}
public string Value => ((ShortcutControl)Owner).GetAutomationValue();
public bool IsReadOnly => true;
public void SetValue(string value)
{
throw new InvalidOperationException("Cannot modify shortcut value: the shortcut control value is read-only. Use Invoke to open the shortcut configuration dialog.");
}
}
}

View File

@@ -49,7 +49,9 @@
x:Uid="ZoomIt_Zoom_Shortcut"
HeaderIcon="{ui:FontIcon Glyph=&#xE71E;}"
IsExpanded="True">
<controls:ShortcutControl HotkeySettings="{x:Bind ViewModel.ZoomToggleKey, Mode=TwoWay}" />
<controls:ShortcutControl
AutomationProperties.Name="{Binding ElementName=ZoomItZoomShortcut, Path=Header}"
HotkeySettings="{x:Bind ViewModel.ZoomToggleKey, Mode=TwoWay}" />
<tkcontrols:SettingsExpander.Items>
<tkcontrols:SettingsCard Name="ZoomItToggleAnimateZoom" ContentAlignment="Left">
<CheckBox x:Uid="ZoomIt_Toggle_AnimateZoom" IsChecked="{x:Bind ViewModel.AnimateZoom, Mode=TwoWay}" />
@@ -81,7 +83,9 @@
x:Uid="ZoomIt_LiveZoom_Shortcut"
HeaderIcon="{ui:FontIcon Glyph=&#xE773;}"
IsExpanded="True">
<controls:ShortcutControl HotkeySettings="{x:Bind ViewModel.LiveZoomToggleKey, Mode=TwoWay}" />
<controls:ShortcutControl
AutomationProperties.Name="{Binding ElementName=ZoomItLiveZoomShortcut, Path=Header}"
HotkeySettings="{x:Bind ViewModel.LiveZoomToggleKey, Mode=TwoWay}" />
<tkcontrols:SettingsExpander.Items>
<tkcontrols:SettingsCard>
<tkcontrols:SettingsCard.Description>
@@ -97,7 +101,9 @@
x:Uid="ZoomIt_Draw_Shortcut"
HeaderIcon="{ui:FontIcon Glyph=&#xEE56;}"
IsExpanded="True">
<controls:ShortcutControl HotkeySettings="{x:Bind ViewModel.DrawToggleKey, Mode=TwoWay}" />
<controls:ShortcutControl
AutomationProperties.Name="{Binding ElementName=ZoomItDrawShortcut, Path=Header}"
HotkeySettings="{x:Bind ViewModel.DrawToggleKey, Mode=TwoWay}" />
<tkcontrols:SettingsExpander.Items>
<tkcontrols:SettingsCard>
<tkcontrols:SettingsCard.Description>
@@ -138,7 +144,9 @@
x:Uid="ZoomIt_DemoType_Shortcut"
HeaderIcon="{ui:FontIcon Glyph=&#xE8AC;}"
IsExpanded="True">
<controls:ShortcutControl HotkeySettings="{x:Bind ViewModel.DemoTypeToggleKey, Mode=TwoWay}" />
<controls:ShortcutControl
AutomationProperties.Name="{Binding ElementName=ZoomItDemoTypeShortcut, Path=Header}"
HotkeySettings="{x:Bind ViewModel.DemoTypeToggleKey, Mode=TwoWay}" />
<tkcontrols:SettingsExpander.Items>
<tkcontrols:SettingsCard
Name="ZoomItDemoTypeFile"
@@ -172,7 +180,9 @@
x:Uid="ZoomIt_Break_Shortcut"
HeaderIcon="{ui:FontIcon Glyph=&#xE916;}"
IsExpanded="True">
<controls:ShortcutControl HotkeySettings="{x:Bind ViewModel.BreakTimerKey, Mode=TwoWay}" />
<controls:ShortcutControl
AutomationProperties.Name="{Binding ElementName=ZoomItBreakShortcut, Path=Header}"
HotkeySettings="{x:Bind ViewModel.BreakTimerKey, Mode=TwoWay}" />
<tkcontrols:SettingsExpander.Items>
<tkcontrols:SettingsCard Name="ZoomItBreakTimeout" x:Uid="ZoomIt_Break_Timeout">
<NumberBox
@@ -260,7 +270,9 @@
x:Uid="ZoomIt_Record_Shortcut"
HeaderIcon="{ui:FontIcon Glyph=&#xE7C8;}"
IsExpanded="True">
<controls:ShortcutControl HotkeySettings="{x:Bind ViewModel.RecordToggleKey, Mode=TwoWay}" />
<controls:ShortcutControl
AutomationProperties.Name="{Binding ElementName=ZoomItRecordShortcut, Path=Header}"
HotkeySettings="{x:Bind ViewModel.RecordToggleKey, Mode=TwoWay}" />
<tkcontrols:SettingsExpander.Items>
<tkcontrols:SettingsCard Name="ZoomItRecordScaling" x:Uid="ZoomIt_Record_Scaling">
<Slider
@@ -319,7 +331,9 @@
x:Uid="ZoomIt_Snip_Shortcut"
HeaderIcon="{ui:FontIcon Glyph=&#xF7ED;}"
IsExpanded="True">
<controls:ShortcutControl HotkeySettings="{x:Bind ViewModel.SnipToggleKey, Mode=TwoWay}" />
<controls:ShortcutControl
AutomationProperties.Name="{Binding ElementName=ZoomItSnipShortcut, Path=Header}"
HotkeySettings="{x:Bind ViewModel.SnipToggleKey, Mode=TwoWay}" />
<tkcontrols:SettingsExpander.Items>
<tkcontrols:SettingsCard Name="ZoomItSnipShortcutSave">
<tkcontrols:SettingsCard.Description>
@@ -332,7 +346,10 @@
Name="ZoomItSnipOcrShortcut"
x:Uid="ZoomIt_SnipOcr_Shortcut"
HeaderIcon="{ui:FontIcon Glyph=&#xF7ED;}">
<controls:ShortcutControl MinWidth="{StaticResource SettingActionControlMinWidth}" HotkeySettings="{x:Bind ViewModel.SnipOcrToggleKey, Mode=TwoWay}" />
<controls:ShortcutControl
MinWidth="{StaticResource SettingActionControlMinWidth}"
AutomationProperties.Name="{Binding ElementName=ZoomItSnipOcrShortcut, Path=Header}"
HotkeySettings="{x:Bind ViewModel.SnipOcrToggleKey, Mode=TwoWay}" />
</tkcontrols:SettingsCard>
</controls:SettingsGroup>
<controls:SettingsGroup x:Uid="ZoomIt_PanoramaGroup" IsEnabled="{x:Bind ViewModel.IsEnabled, Mode=OneWay}">
@@ -340,7 +357,10 @@
Name="ZoomItPanoramaShortcut"
x:Uid="ZoomIt_Panorama_Shortcut"
HeaderIcon="{ui:FontIcon Glyph=&#xE7C5;}">
<controls:ShortcutControl MinWidth="{StaticResource SettingActionControlMinWidth}" HotkeySettings="{x:Bind ViewModel.SnipPanoramaToggleKey, Mode=TwoWay}" />
<controls:ShortcutControl
MinWidth="{StaticResource SettingActionControlMinWidth}"
AutomationProperties.Name="{Binding ElementName=ZoomItPanoramaShortcut, Path=Header}"
HotkeySettings="{x:Bind ViewModel.SnipPanoramaToggleKey, Mode=TwoWay}" />
</tkcontrols:SettingsCard>
</controls:SettingsGroup>
</StackPanel>