|
|
@ -1,16 +1,23 @@ |
|
|
using System; |
|
|
using System; |
|
|
using System.Collections.Generic; |
|
|
using System.Collections.Generic; |
|
|
|
|
|
using System.Linq; |
|
|
using Avalonia; |
|
|
using Avalonia; |
|
|
using Avalonia.Controls; |
|
|
using Avalonia.Controls; |
|
|
|
|
|
using Avalonia.Controls.Notifications; |
|
|
using Avalonia.Input; |
|
|
using Avalonia.Input; |
|
|
using Avalonia.Interactivity; |
|
|
using Avalonia.Interactivity; |
|
|
using Avalonia.Markup.Xaml; |
|
|
using Avalonia.Markup.Xaml; |
|
|
|
|
|
using Avalonia.Platform; |
|
|
|
|
|
using Avalonia.Platform.Storage; |
|
|
|
|
|
using Avalonia.Platform.Storage.FileIO; |
|
|
|
|
|
|
|
|
namespace ControlCatalog.Pages |
|
|
namespace ControlCatalog.Pages |
|
|
{ |
|
|
{ |
|
|
public partial class ClipboardPage : UserControl |
|
|
public partial class ClipboardPage : UserControl |
|
|
{ |
|
|
{ |
|
|
|
|
|
private INotificationManager? _notificationManager; |
|
|
|
|
|
private INotificationManager NotificationManager => _notificationManager |
|
|
|
|
|
??= new WindowNotificationManager(TopLevel.GetTopLevel(this)!); |
|
|
public ClipboardPage() |
|
|
public ClipboardPage() |
|
|
{ |
|
|
{ |
|
|
InitializeComponent(); |
|
|
InitializeComponent(); |
|
|
@ -31,7 +38,7 @@ namespace ControlCatalog.Pages |
|
|
|
|
|
|
|
|
private async void PasteText(object? sender, RoutedEventArgs args) |
|
|
private async void PasteText(object? sender, RoutedEventArgs args) |
|
|
{ |
|
|
{ |
|
|
if(Application.Current!.Clipboard is { } clipboard) |
|
|
if (Application.Current!.Clipboard is { } clipboard) |
|
|
{ |
|
|
{ |
|
|
ClipboardContent.Text = await clipboard.GetTextAsync(); |
|
|
ClipboardContent.Text = await clipboard.GetTextAsync(); |
|
|
} |
|
|
} |
|
|
@ -59,15 +66,45 @@ namespace ControlCatalog.Pages |
|
|
{ |
|
|
{ |
|
|
if (Application.Current!.Clipboard is { } clipboard) |
|
|
if (Application.Current!.Clipboard is { } clipboard) |
|
|
{ |
|
|
{ |
|
|
var files = (ClipboardContent.Text ?? String.Empty) |
|
|
var storageProvider = TopLevel.GetTopLevel(this)!.StorageProvider; |
|
|
.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); |
|
|
var filesPath = (ClipboardContent.Text ?? string.Empty) |
|
|
if (files.Length == 0) |
|
|
.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); |
|
|
|
|
|
if (filesPath.Length == 0) |
|
|
{ |
|
|
{ |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
var dataObject = new DataObject(); |
|
|
List<string> invalidFile = new(filesPath.Length); |
|
|
dataObject.Set(DataFormats.FileNames, files); |
|
|
List<IStorageFile> files = new(filesPath.Length); |
|
|
await clipboard.SetDataObjectAsync(dataObject); |
|
|
|
|
|
|
|
|
for (int i = 0; i < filesPath.Length; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
var file = await storageProvider.TryGetFileFromPathAsync(filesPath[i]); |
|
|
|
|
|
if (file is null) |
|
|
|
|
|
{ |
|
|
|
|
|
invalidFile.Add(filesPath[i]); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
files.Add(file); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (invalidFile.Count > 0) |
|
|
|
|
|
{ |
|
|
|
|
|
NotificationManager.Show(new Notification("Warning", "There is one o more invalid path.", NotificationType.Warning)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (files.Count > 0) |
|
|
|
|
|
{ |
|
|
|
|
|
var dataObject = new DataObject(); |
|
|
|
|
|
dataObject.Set(DataFormats.Files, files); |
|
|
|
|
|
await clipboard.SetDataObjectAsync(dataObject); |
|
|
|
|
|
NotificationManager.Show(new Notification("Success", "Copy completated.", NotificationType.Success)); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
NotificationManager.Show(new Notification("Warning", "Any files to copy in Clipboard.", NotificationType.Warning)); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -75,8 +112,9 @@ namespace ControlCatalog.Pages |
|
|
{ |
|
|
{ |
|
|
if (Application.Current!.Clipboard is { } clipboard) |
|
|
if (Application.Current!.Clipboard is { } clipboard) |
|
|
{ |
|
|
{ |
|
|
var fiels = await clipboard.GetDataAsync(DataFormats.FileNames) as IEnumerable<string>; |
|
|
var files = await clipboard.GetDataAsync(DataFormats.Files) as IEnumerable<Avalonia.Platform.Storage.IStorageItem>; |
|
|
ClipboardContent.Text = fiels != null ? string.Join(Environment.NewLine, fiels) : string.Empty; |
|
|
|
|
|
|
|
|
ClipboardContent.Text = files != null ? string.Join(Environment.NewLine, files.Select(f => f.TryGetLocalPath() ?? f.Name)) : string.Empty; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -95,7 +133,7 @@ namespace ControlCatalog.Pages |
|
|
{ |
|
|
{ |
|
|
await clipboard.ClearAsync(); |
|
|
await clipboard.ClearAsync(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|