Browse Source
Exclude access key markers from native menu titles on macOS. (#13338 )
* Add integration test for access key indicators in macOS menu bar titles.
Tests for access key indicators displaying as plain underscores in macOS menu bar items.
* Exclude access key markers from native menu titles on macOS.
macOS does not support access key markers, so they just display as extra underscores.
pull/13350/head
Steveice10
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with
44 additions and
3 deletions
samples/IntegrationTestApp/MainWindow.axaml
src/Avalonia.Native/IAvnMenu.cs
src/Avalonia.Native/IAvnMenuItem.cs
tests/Avalonia.IntegrationTests.Appium/NativeMenuTests.cs
@ -18,6 +18,9 @@
<NativeMenuItem Header="View">
<NativeMenu/>
</NativeMenuItem>
<NativeMenuItem Header="_Options">
<NativeMenu/>
</NativeMenuItem>
</NativeMenu>
</NativeMenu.Menu>
<DockPanel>
@ -1,8 +1,10 @@
using System ;
using System.Collections.Generic ;
using System.Collections.Specialized ;
using Avalonia.Compatibility ;
using Avalonia.Reactive ;
using Avalonia.Controls ;
using Avalonia.Controls.Primitives ;
namespace Avalonia.Native.Interop
{
@ -47,6 +49,20 @@ namespace Avalonia.Native.Interop.Impl
private List < _ _ MicroComIAvnMenuItemProxy > _ menuItems = new List < _ _ MicroComIAvnMenuItemProxy > ( ) ;
private Dictionary < NativeMenuItemBase , _ _ MicroComIAvnMenuItemProxy > _ menuItemLookup = new Dictionary < NativeMenuItemBase , _ _ MicroComIAvnMenuItemProxy > ( ) ;
private void UpdateTitle ( string title )
{
if ( OperatingSystemEx . IsMacOS ( ) )
{
// macOS does not process access key markers, so remove them.
title = AccessText . RemoveAccessKeyMarker ( title ) ;
}
if ( string . IsNullOrWhiteSpace ( title ) )
{
title = "" ;
}
SetTitle ( title ) ;
}
public void RaiseNeedsUpdate ( )
{
( ManagedMenu as INativeMenuExporterEventsImplBridge ) . RaiseNeedsUpdate ( ) ;
@ -127,8 +143,7 @@ namespace Avalonia.Native.Interop.Impl
( ( INotifyCollectionChanged ) ManagedMenu . Items ) . CollectionChanged + = OnMenuItemsChanged ;
if ( ! string . IsNullOrWhiteSpace ( title ) )
SetTitle ( title ) ;
UpdateTitle ( title ) ;
}
public void Deinitialise ( )
@ -1,7 +1,9 @@
using System ;
using System.IO ;
using Avalonia.Compatibility ;
using Avalonia.Reactive ;
using Avalonia.Controls ;
using Avalonia.Controls.Primitives ;
using Avalonia.Media.Imaging ;
using Avalonia.Platform.Interop ;
@ -22,7 +24,19 @@ namespace Avalonia.Native.Interop.Impl
public NativeMenuItemBase ManagedMenuItem { get ; set ; }
private void UpdateTitle ( string title ) = > SetTitle ( title ? ? "" ) ;
private void UpdateTitle ( string title )
{
if ( OperatingSystemEx . IsMacOS ( ) )
{
// macOS does not process access key markers, so remove them.
title = AccessText . RemoveAccessKeyMarker ( title ) ;
}
if ( string . IsNullOrWhiteSpace ( title ) )
{
title = "" ;
}
SetTitle ( title ) ;
}
private void UpdateIsChecked ( bool isChecked ) = > SetIsChecked ( isChecked . AsComBool ( ) ) ;
@ -49,5 +49,14 @@ namespace Avalonia.IntegrationTests.Appium
Assert . True ( buttonTab . Selected ) ;
}
[PlatformFact(TestPlatforms.MacOS)]
public void MacOS_Sanitizes_Access_Key_Markers_When_Included_In_Menu_Title ( )
{
var menuBar = _ session . FindElementByXPath ( "/XCUIElementTypeApplication/XCUIElementTypeMenuBar" ) ;
Assert . True ( menuBar . FindElementsByName ( "_Options" ) . Count = = 0 ) ;
Assert . True ( menuBar . FindElementsByName ( "Options" ) . Count = = 1 ) ;
}
}
}