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. 26
      StabilityMatrix.Avalonia/Controls/AdvancedImageBoxView.axaml.cs

6
StabilityMatrix.Avalonia/Controls/AdvancedImageBoxView.axaml

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

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

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

Loading…
Cancel
Save