From e53078bc0d3b196d7f68760ca085d0e912223c98 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Mon, 9 Mar 2020 12:37:12 +0100 Subject: [PATCH] Expose platform KeyGesture conversion as static method. --- .../Converters/PlatformKeyGestureConverter.cs | 47 ++++++++++++------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/src/Avalonia.Controls/Converters/PlatformKeyGestureConverter.cs b/src/Avalonia.Controls/Converters/PlatformKeyGestureConverter.cs index 5ee96c73d5..d0f9c7131f 100644 --- a/src/Avalonia.Controls/Converters/PlatformKeyGestureConverter.cs +++ b/src/Avalonia.Controls/Converters/PlatformKeyGestureConverter.cs @@ -7,6 +7,10 @@ using Avalonia.Input; namespace Avalonia.Controls.Converters { + /// + /// Converts a to a string, formatting it according to the current + /// platform's style guidelines. + /// public class PlatformKeyGestureConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) @@ -17,22 +21,7 @@ namespace Avalonia.Controls.Converters } else if (value is KeyGesture gesture && targetType == typeof(string)) { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - return ToString(gesture, "Win"); - } - else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) - { - return ToString(gesture, "Super"); - } - else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) - { - return ToOSXString(gesture); - } - else - { - return gesture.ToString(); - } + return ToPlatformString(gesture); } else { @@ -45,6 +34,32 @@ namespace Avalonia.Controls.Converters throw new NotImplementedException(); } + /// + /// Converts a to a string, formatting it according to the current + /// platform's style guidelines. + /// + /// The gesture. + /// The gesture formatted according to the current platform. + public static string ToPlatformString(KeyGesture gesture) + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + return ToString(gesture, "Win"); + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + return ToString(gesture, "Super"); + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + return ToOSXString(gesture); + } + else + { + return gesture.ToString(); + } + } + private static string ToString(KeyGesture gesture, string meta) { var s = new StringBuilder();