Browse Source

Add compatibility guards for image copy

pull/165/head
Ionite 1 year ago
parent
commit
c4342a8336
No known key found for this signature in database
  1. 1
      StabilityMatrix.Avalonia/Controls/ImageGalleryCard.axaml
  2. 2
      StabilityMatrix.Avalonia/Helpers/WindowsClipboard.cs
  3. 13
      StabilityMatrix.Avalonia/ViewModels/Inference/ImageGalleryCardViewModel.cs

1
StabilityMatrix.Avalonia/Controls/ImageGalleryCard.axaml

@ -70,6 +70,7 @@
<controls:BetterAdvancedImage.ContextFlyout>
<ui:FAMenuFlyout>
<ui:MenuFlyoutItem
IsEnabled="{OnPlatform Windows=True, Default=False}"
Command="{ReflectionBinding #ImageCarousel.DataContext.FlyoutCopyCommand}"
CommandParameter="{Binding #ImageView.CurrentImage}"
Text="Copy"

2
StabilityMatrix.Avalonia/Helpers/WindowsClipboard.cs

@ -2,10 +2,12 @@
using System.ComponentModel;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using Avalonia.Media.Imaging;
namespace StabilityMatrix.Avalonia.Helpers;
[SupportedOSPlatform("windows")]
public static class WindowsClipboard
{
public static void SetBitmap(Bitmap bitmap)

13
StabilityMatrix.Avalonia/ViewModels/Inference/ImageGalleryCardViewModel.cs

@ -1,4 +1,6 @@
using Avalonia.Collections;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
using Avalonia.Collections;
using Avalonia.Media;
using Avalonia.Media.Imaging;
using CommunityToolkit.Mvvm.ComponentModel;
@ -7,6 +9,7 @@ using NLog;
using StabilityMatrix.Avalonia.Controls;
using StabilityMatrix.Avalonia.Helpers;
using StabilityMatrix.Core.Attributes;
using StabilityMatrix.Core.Helper;
namespace StabilityMatrix.Avalonia.ViewModels.Inference;
@ -23,14 +26,18 @@ public partial class ImageGalleryCardViewModel : ViewModelBase
[ObservableProperty] private string? selectedImage;
[RelayCommand]
private void FlyoutCopy(IImage? image)
[SuppressMessage("Interoperability", "CA1416:Validate platform compatibility")]
// ReSharper disable once UnusedMember.Local
private async Task FlyoutCopy(IImage? image)
{
if (!Compat.IsWindows) return;
if (image is null)
{
Logger.Trace("FlyoutCopy: image is null");
return;
}
Logger.Trace($"FlyoutCopy is copying {image}");
WindowsClipboard.SetBitmap((Bitmap) image);
await Task.Run(() => WindowsClipboard.SetBitmap((Bitmap) image));
}
}

Loading…
Cancel
Save