|
|
|
@ -119,9 +119,24 @@ namespace ControlCatalog.Pages |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void CopyBitmapDataObject(object? sender, RoutedEventArgs args) |
|
|
|
private async void CopyBitmapDataObject(object? sender, RoutedEventArgs args) |
|
|
|
{ |
|
|
|
throw new NotSupportedException(); |
|
|
|
if (TopLevel.GetTopLevel(this)?.Clipboard is { } clipboard) |
|
|
|
{ |
|
|
|
var lines = (ClipboardContent.Text ?? string.Empty) |
|
|
|
.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); |
|
|
|
if (lines.Length < 3) |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
var format = lines[0]; |
|
|
|
var hexLine = string.Join(" ", lines.Skip(2)); |
|
|
|
var hexBytes = hexLine.Split(new[] { ' ', '-' }, StringSplitOptions.RemoveEmptyEntries); |
|
|
|
var bytes = hexBytes.Select(x => Convert.ToByte(x, 16)); |
|
|
|
var dataObject = new DataObject(); |
|
|
|
dataObject.Set(format, bytes); |
|
|
|
await clipboard.SetDataObjectAsync(dataObject); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private async void PasteBitmapDataObject(object? sender, RoutedEventArgs args) |
|
|
|
@ -133,6 +148,12 @@ namespace ControlCatalog.Pages |
|
|
|
var obj = await clipboard.GetDataAsync(format); |
|
|
|
var bytes = obj as IEnumerable<byte>; |
|
|
|
if (bytes == null) |
|
|
|
{ |
|
|
|
format = "Unknown_Format_8"; |
|
|
|
obj = await clipboard.GetDataAsync(format); |
|
|
|
bytes = obj as IEnumerable<byte>; |
|
|
|
} |
|
|
|
if (bytes == null) |
|
|
|
{ |
|
|
|
format = "Dib"; |
|
|
|
obj = await clipboard.GetDataAsync(format); |
|
|
|
@ -159,11 +180,14 @@ namespace ControlCatalog.Pages |
|
|
|
|
|
|
|
if (bytes != null) |
|
|
|
{ |
|
|
|
var printable = bytes.Take(1000); |
|
|
|
var printable = bytes.ToArray(); |
|
|
|
var sb = new StringBuilder(256 + printable.Count() * 3); |
|
|
|
sb.AppendLine($"format: {format}, {bytes.Count()} bytes, list of first {printable.Count()}"); |
|
|
|
sb.AppendJoin(" ", printable.Select(x => x.ToString("X2"))); |
|
|
|
sb.AppendLine($"{format}"); |
|
|
|
sb.AppendLine($"{bytes.Count()} bytes (list of first {printable.Count()} bytes)"); |
|
|
|
sb.Append(BitConverter.ToString(printable).Replace('-', ' ')); |
|
|
|
ClipboardContent.TextWrapping = Avalonia.Media.TextWrapping.NoWrap; |
|
|
|
ClipboardContent.Text = sb.ToString(); |
|
|
|
ClipboardContent.TextWrapping = Avalonia.Media.TextWrapping.Wrap; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
|