|
@@ -1,5 +1,4 @@
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
-using System.Collections.Specialized;
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using System.IO;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Linq;
|
|
@@ -7,7 +6,6 @@ using System.Runtime.InteropServices;
|
|
using System.Threading.Tasks;
|
|
using System.Threading.Tasks;
|
|
using Avalonia.Input;
|
|
using Avalonia.Input;
|
|
using Avalonia.Input.Platform;
|
|
using Avalonia.Input.Platform;
|
|
-using Avalonia.Media;
|
|
|
|
using Avalonia.Media.Imaging;
|
|
using Avalonia.Media.Imaging;
|
|
using Avalonia.Platform;
|
|
using Avalonia.Platform;
|
|
using ChunkyImageLib;
|
|
using ChunkyImageLib;
|
|
@@ -15,13 +13,11 @@ using PixiEditor.Avalonia.Helpers;
|
|
using PixiEditor.Avalonia.Helpers.Extensions;
|
|
using PixiEditor.Avalonia.Helpers.Extensions;
|
|
using PixiEditor.ChangeableDocument.Enums;
|
|
using PixiEditor.ChangeableDocument.Enums;
|
|
using PixiEditor.DrawingApi.Core.Numerics;
|
|
using PixiEditor.DrawingApi.Core.Numerics;
|
|
-using PixiEditor.DrawingApi.Core.Surface;
|
|
|
|
using PixiEditor.DrawingApi.Core.Surface.ImageData;
|
|
using PixiEditor.DrawingApi.Core.Surface.ImageData;
|
|
using PixiEditor.Helpers;
|
|
using PixiEditor.Helpers;
|
|
using PixiEditor.Helpers.Extensions;
|
|
using PixiEditor.Helpers.Extensions;
|
|
using PixiEditor.Models.Dialogs;
|
|
using PixiEditor.Models.Dialogs;
|
|
using PixiEditor.Models.IO;
|
|
using PixiEditor.Models.IO;
|
|
-using PixiEditor.Models.IO.FileEncoders;
|
|
|
|
using PixiEditor.Parser;
|
|
using PixiEditor.Parser;
|
|
using PixiEditor.Parser.Deprecated;
|
|
using PixiEditor.Parser.Deprecated;
|
|
using PixiEditor.ViewModels.SubViewModels.Document;
|
|
using PixiEditor.ViewModels.SubViewModels.Document;
|
|
@@ -50,8 +46,7 @@ internal static class ClipboardController
|
|
/// </summary>
|
|
/// </summary>
|
|
public static async Task CopyToClipboard(DocumentViewModel document)
|
|
public static async Task CopyToClipboard(DocumentViewModel document)
|
|
{
|
|
{
|
|
- if (!(await ClipboardHelper.TryClear()))
|
|
|
|
- return;
|
|
|
|
|
|
+ await Clipboard.ClearAsync();
|
|
|
|
|
|
var surface = document.MaybeExtractSelectedArea();
|
|
var surface = document.MaybeExtractSelectedArea();
|
|
if (surface.IsT0)
|
|
if (surface.IsT0)
|
|
@@ -89,7 +84,7 @@ internal static class ClipboardController
|
|
data.SetVecI(PositionFormat, area.Pos);
|
|
data.SetVecI(PositionFormat, area.Pos);
|
|
}
|
|
}
|
|
|
|
|
|
- await ClipboardHelper.TrySetDataObject(data);
|
|
|
|
|
|
+ await Clipboard.SetDataObjectAsync(data);
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -138,10 +133,38 @@ internal static class ClipboardController
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Pastes image from clipboard into new layer.
|
|
/// Pastes image from clipboard into new layer.
|
|
/// </summary>
|
|
/// </summary>
|
|
- public static bool TryPasteFromClipboard(DocumentViewModel document, bool pasteAsNew = false) =>
|
|
|
|
- TryPaste(document, ClipboardHelper.TryGetDataObject(), pasteAsNew);
|
|
|
|
|
|
+ public static async Task<bool> TryPasteFromClipboard(DocumentViewModel document, bool pasteAsNew = false)
|
|
|
|
+ {
|
|
|
|
+ //TODO: maybe if we have access to more formats, we can check them as well
|
|
|
|
+ var data = await TryGetDataObject();
|
|
|
|
+ if (data == null)
|
|
|
|
+ return false;
|
|
|
|
+
|
|
|
|
+ return TryPaste(document, data, pasteAsNew);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static async Task<DataObject?> TryGetDataObject()
|
|
|
|
+ {
|
|
|
|
+ string[] formats = await Clipboard.GetFormatsAsync();
|
|
|
|
+ if (formats.Length == 0)
|
|
|
|
+ return null;
|
|
|
|
|
|
- public static List<DataImage> GetImagesFromClipboard() => GetImage(ClipboardHelper.TryGetDataObject());
|
|
|
|
|
|
+ string format = formats[0];
|
|
|
|
+ var obj = await Clipboard.GetDataAsync(format);
|
|
|
|
+
|
|
|
|
+ if (obj == null)
|
|
|
|
+ return null;
|
|
|
|
+
|
|
|
|
+ DataObject data = new DataObject();
|
|
|
|
+ data.Set(format, obj);
|
|
|
|
+ return data;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static async Task<List<DataImage>> GetImagesFromClipboard()
|
|
|
|
+ {
|
|
|
|
+ var dataObj = await TryGetDataObject();
|
|
|
|
+ return GetImage(dataObj);
|
|
|
|
+ }
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Gets images from clipboard, supported PNG, Dib and Bitmap.
|
|
/// Gets images from clipboard, supported PNG, Dib and Bitmap.
|
|
@@ -215,7 +238,16 @@ internal static class ClipboardController
|
|
}
|
|
}
|
|
|
|
|
|
[Evaluator.CanExecute("PixiEditor.Clipboard.HasImageInClipboard")]
|
|
[Evaluator.CanExecute("PixiEditor.Clipboard.HasImageInClipboard")]
|
|
- public static bool IsImageInClipboard() => IsImage(ClipboardHelper.TryGetDataObject());
|
|
|
|
|
|
+ public static async Task<bool> IsImageInClipboard()
|
|
|
|
+ {
|
|
|
|
+ var files = await Clipboard.GetDataAsync(DataFormats.Files);
|
|
|
|
+ if (files == null)
|
|
|
|
+ return false;
|
|
|
|
+
|
|
|
|
+ string[] fileArray = ((IEnumerable<string>)files).ToArray();
|
|
|
|
+
|
|
|
|
+ return IsImageFormat(fileArray);
|
|
|
|
+ }
|
|
|
|
|
|
public static bool IsImage(DataObject? dataObject)
|
|
public static bool IsImage(DataObject? dataObject)
|
|
{
|
|
{
|
|
@@ -227,12 +259,9 @@ internal static class ClipboardController
|
|
var files = dataObject.GetFileDropList();
|
|
var files = dataObject.GetFileDropList();
|
|
if (files != null)
|
|
if (files != null)
|
|
{
|
|
{
|
|
- foreach (var file in files)
|
|
|
|
|
|
+ if (IsImageFormat(files))
|
|
{
|
|
{
|
|
- if (Importer.IsSupportedFile(file))
|
|
|
|
- {
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
|
|
+ return true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -244,6 +273,19 @@ internal static class ClipboardController
|
|
return HasData(dataObject, "PNG", ClipboardDataFormats.Dib, ClipboardDataFormats.Bitmap);
|
|
return HasData(dataObject, "PNG", ClipboardDataFormats.Dib, ClipboardDataFormats.Bitmap);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private static bool IsImageFormat(string[] files)
|
|
|
|
+ {
|
|
|
|
+ foreach (var file in files)
|
|
|
|
+ {
|
|
|
|
+ if (Importer.IsSupportedFile(file))
|
|
|
|
+ {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
private static Bitmap FromPNG(DataObject data)
|
|
private static Bitmap FromPNG(DataObject data)
|
|
{
|
|
{
|
|
MemoryStream pngStream = (MemoryStream)data.Get("PNG");
|
|
MemoryStream pngStream = (MemoryStream)data.Get("PNG");
|