Browse Source

Add file copy mode for non windows

pull/495/head
Ionite 9 months ago
parent
commit
97c1d15e20
No known key found for this signature in database
  1. 6
      StabilityMatrix.Avalonia/Controls/AdvancedImageBoxView.axaml
  2. 22
      StabilityMatrix.Avalonia/Controls/AdvancedImageBoxView.axaml.cs

6
StabilityMatrix.Avalonia/Controls/AdvancedImageBoxView.axaml

@ -9,6 +9,7 @@
xmlns:models="clr-namespace:StabilityMatrix.Avalonia.Models"
xmlns:ui="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia"
xmlns:gif="clr-namespace:Avalonia.Gif;assembly=Avalonia.Gif"
xmlns:lang="clr-namespace:StabilityMatrix.Avalonia.Languages"
d:DataContext="{x:Static mocks:DesignData.SampleImageSource}"
d:DesignHeight="450"
d:DesignWidth="800"
@ -36,11 +37,10 @@
<ui:FAMenuFlyout>
<ui:MenuFlyoutItem
Command="{x:Static controls:AdvancedImageBoxView.FlyoutCopyCommand}"
CommandParameter="{Binding $parent[controls:AdvancedImageBox].Image}"
CommandParameter="{Binding}"
HotKey="Ctrl+C"
IconSource="Copy"
IsEnabled="{OnPlatform Windows=True, Default=False}"
Text="Copy" />
Text="{x:Static lang:Resources.Action_Copy}" />
</ui:FAMenuFlyout>
</controls:AdvancedImageBox.ContextFlyout>
</controls:AdvancedImageBox>

22
StabilityMatrix.Avalonia/Controls/AdvancedImageBoxView.axaml.cs

@ -1,8 +1,9 @@
using System.Threading.Tasks;
using Avalonia.Controls;
using Avalonia.Media.Imaging;
using CommunityToolkit.Mvvm.Input;
using StabilityMatrix.Avalonia.Extensions;
using StabilityMatrix.Avalonia.Helpers;
using StabilityMatrix.Avalonia.Models;
using StabilityMatrix.Core.Helper;
namespace StabilityMatrix.Avalonia.Controls;
@ -14,19 +15,26 @@ public partial class AdvancedImageBoxView : UserControl
InitializeComponent();
}
public static AsyncRelayCommand<Bitmap?> FlyoutCopyCommand { get; } = new(FlyoutCopy);
public static AsyncRelayCommand<ImageSource?> FlyoutCopyCommand { get; } = new(FlyoutCopy);
public static async Task FlyoutCopy(Bitmap? image)
private static async Task FlyoutCopy(ImageSource? imageSource)
{
if (image is null || !Compat.IsWindows)
if (imageSource is null)
return;
if (Compat.IsWindows && imageSource.Bitmap is { } bitmap)
{
// Use bitmap on Windows if available
await Task.Run(() =>
{
if (Compat.IsWindows)
WindowsClipboard.SetBitmap(bitmap);
});
}
else if (imageSource.LocalFile is { } imagePath)
{
WindowsClipboard.SetBitmap(image);
// Other OS or no bitmap, use image source
var clipboard = App.Clipboard;
await clipboard.SetFileDataObjectAsync(imagePath);
}
});
}
}

Loading…
Cancel
Save