|
@@ -1,5 +1,6 @@
|
|
|
using System.Collections.Generic;
|
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
+using System.Linq;
|
|
|
using System.Text.RegularExpressions;
|
|
|
using Avalonia.Input;
|
|
|
|
|
@@ -7,11 +8,42 @@ namespace PixiEditor.AvaloniaUI.Helpers;
|
|
|
|
|
|
public class ColorHelper
|
|
|
{
|
|
|
+ public const string PaletteColorDaoFormat = "PixiEditor.PaletteColor";
|
|
|
+
|
|
|
public static bool ParseAnyFormat(IDataObject data, [NotNullWhen(true)] out DrawingApi.Core.ColorsImpl.Color? result) =>
|
|
|
- ParseAnyFormat(((DataObject)data).GetText().Trim(), out result);
|
|
|
+ ParseAnyFormat(GetTextFromData(data), out result);
|
|
|
|
|
|
- public static bool ParseAnyFormatList(IDataObject data, [NotNullWhen(true)] out List<DrawingApi.Core.ColorsImpl.Color> result) =>
|
|
|
- ParseAnyFormatList(((DataObject)data).GetText().Trim(), out result);
|
|
|
+ public static bool ParseAnyFormatList(IDataObject data, [NotNullWhen(true)] out List<DrawingApi.Core.ColorsImpl.Color> result)
|
|
|
+ {
|
|
|
+ var text = GetTextFromData(data);
|
|
|
+
|
|
|
+ if (string.IsNullOrEmpty(text))
|
|
|
+ {
|
|
|
+ result = new List<DrawingApi.Core.ColorsImpl.Color>();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return ParseAnyFormatList(text, out result);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static string GetTextFromData(IDataObject data)
|
|
|
+ {
|
|
|
+ string text = "";
|
|
|
+ if (data.Contains(DataFormats.Text))
|
|
|
+ {
|
|
|
+ text = ((DataObject)data).GetText().Trim();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var formats = data.GetDataFormats().ToList();
|
|
|
+ if(formats.Count > 0)
|
|
|
+ {
|
|
|
+ text = ((DataObject)data).Get(formats[0]).ToString().Trim();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return text;
|
|
|
+ }
|
|
|
|
|
|
public static bool ParseAnyFormat(string value, [NotNullWhen(true)] out DrawingApi.Core.ColorsImpl.Color? result)
|
|
|
{
|