Paste from clipboard WIP

This commit is contained in:
2023-04-25 17:25:02 +02:00
parent bde131f422
commit 97069386c6
6 changed files with 53 additions and 5 deletions

View File

@@ -3,4 +3,5 @@ namespace FileTime.App.Core.Services;
public interface ISystemClipboardService public interface ISystemClipboardService
{ {
Task CopyToClipboardAsync(string text); Task CopyToClipboardAsync(string text);
Task GetFiles();
} }

View File

@@ -0,0 +1,19 @@
using FileTime.App.Core.Models.Enums;
namespace FileTime.App.Core.UserCommand;
public class PasteFilesFromClipboardCommand : IIdentifiableUserCommand
{
public const string PasteMergeCommandName = "paste_clipboard_merge";
public static readonly PasteFilesFromClipboardCommand Merge = new(PasteMode.Merge, PasteMergeCommandName);
public PasteMode PasteMode { get; }
private PasteFilesFromClipboardCommand(PasteMode pasteMode, string commandName)
{
PasteMode = pasteMode;
UserCommandID = commandName;
}
public string UserCommandID { get; }
}

View File

@@ -27,6 +27,7 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
private readonly ITimelessContentProvider _timelessContentProvider; private readonly ITimelessContentProvider _timelessContentProvider;
private readonly ICommandScheduler _commandScheduler; private readonly ICommandScheduler _commandScheduler;
private readonly IServiceProvider _serviceProvider; private readonly IServiceProvider _serviceProvider;
private readonly ISystemClipboardService _systemClipboardService;
private readonly BindedCollection<FullName>? _markedItems; private readonly BindedCollection<FullName>? _markedItems;
private IContainer? _currentLocation; private IContainer? _currentLocation;
@@ -38,7 +39,8 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
ILogger<ItemManipulationUserCommandHandlerService> logger, ILogger<ItemManipulationUserCommandHandlerService> logger,
ITimelessContentProvider timelessContentProvider, ITimelessContentProvider timelessContentProvider,
ICommandScheduler commandScheduler, ICommandScheduler commandScheduler,
IServiceProvider serviceProvider) : base(appState, timelessContentProvider) IServiceProvider serviceProvider,
ISystemClipboardService systemClipboardService) : base(appState, timelessContentProvider)
{ {
_userCommandHandlerService = userCommandHandlerService; _userCommandHandlerService = userCommandHandlerService;
_clipboardService = clipboardService; _clipboardService = clipboardService;
@@ -47,6 +49,7 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
_timelessContentProvider = timelessContentProvider; _timelessContentProvider = timelessContentProvider;
_commandScheduler = commandScheduler; _commandScheduler = commandScheduler;
_serviceProvider = serviceProvider; _serviceProvider = serviceProvider;
_systemClipboardService = systemClipboardService;
SaveSelectedTab(t => _selectedTab = t); SaveSelectedTab(t => _selectedTab = t);
SaveCurrentLocation(l => _currentLocation = l); SaveCurrentLocation(l => _currentLocation = l);
@@ -62,9 +65,15 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
new TypeUserCommandHandler<PasteCommand>(Paste), new TypeUserCommandHandler<PasteCommand>(Paste),
new TypeUserCommandHandler<CreateContainer>(CreateContainer), new TypeUserCommandHandler<CreateContainer>(CreateContainer),
new TypeUserCommandHandler<CreateElement>(CreateElement), new TypeUserCommandHandler<CreateElement>(CreateElement),
new TypeUserCommandHandler<PasteFilesFromClipboardCommand>(PasteFilesFromClipboard),
}); });
} }
private async Task PasteFilesFromClipboard(PasteFilesFromClipboardCommand arg)
{
await _systemClipboardService.GetFiles();
}
private async Task MarkItem() private async Task MarkItem()
{ {
if (_selectedTab == null || _currentSelectedItem?.BaseItem?.FullName == null) return; if (_selectedTab == null || _currentSelectedItem?.BaseItem?.FullName == null) return;

View File

@@ -38,6 +38,7 @@ public class DefaultIdentifiableCommandHandlerRegister : IStartupHandler
AddUserCommand(PasteCommand.Merge); AddUserCommand(PasteCommand.Merge);
AddUserCommand(PasteCommand.Overwrite); AddUserCommand(PasteCommand.Overwrite);
AddUserCommand(PasteCommand.Skip); AddUserCommand(PasteCommand.Skip);
AddUserCommand(PasteFilesFromClipboardCommand.Merge);
AddUserCommand(PauseCommandSchedulerCommand.Instance); AddUserCommand(PauseCommandSchedulerCommand.Instance);
AddUserCommand(RefreshCommand.Instance); AddUserCommand(RefreshCommand.Instance);
AddUserCommand(StartCommandSchedulerCommand.Instance); AddUserCommand(StartCommandSchedulerCommand.Instance);

View File

@@ -74,6 +74,7 @@ public static class MainConfiguration
new(PasteCommand.PasteMergeCommandName, new[] {Key.P, Key.P}), new(PasteCommand.PasteMergeCommandName, new[] {Key.P, Key.P}),
new(PasteCommand.PasteOverwriteCommandName, new[] {Key.P, Key.O}), new(PasteCommand.PasteOverwriteCommandName, new[] {Key.P, Key.O}),
new(PasteCommand.PasteSkipCommandName, new[] {Key.P, Key.S}), new(PasteCommand.PasteSkipCommandName, new[] {Key.P, Key.S}),
new(PasteFilesFromClipboardCommand.PasteMergeCommandName, new[] {Key.C, Key.X}),
//new CommandBindingConfiguration(ConfigCommand.PinFavorite, new[] { Key.F, Key.P }), //new CommandBindingConfiguration(ConfigCommand.PinFavorite, new[] { Key.F, Key.P }),
//new CommandBindingConfiguration(ConfigCommand.PreviousTimelineBlock, Key.H ), //new CommandBindingConfiguration(ConfigCommand.PreviousTimelineBlock, Key.H ),
//new CommandBindingConfiguration(ConfigCommand.PreviousTimelineCommand, Key.K ), //new CommandBindingConfiguration(ConfigCommand.PreviousTimelineCommand, Key.K ),

View File

@@ -9,9 +9,26 @@ public class SystemClipboardService : ISystemClipboardService
public async Task CopyToClipboardAsync(string text) public async Task CopyToClipboardAsync(string text)
{ {
var clipboard = AvaloniaLocator.Current.GetService<IClipboard>(); var clipboard = AvaloniaLocator.Current.GetService<IClipboard>();
if (clipboard is not null)
{ if (clipboard is null) { return; }
await clipboard.SetTextAsync(text);
} await clipboard.SetTextAsync(text);
}
public async Task GetFiles()
{
var clipboard = AvaloniaLocator.Current.GetService<IClipboard>();
if (clipboard is null) { return; }
await clipboard.ClearAsync();
var formats = await clipboard.GetFormatsAsync();
if (!formats.Contains("asd")) return;
var obj = (await clipboard.GetDataAsync("PNG"));
/*var ms = new MemoryStream();
Serializer.Serialize(ms, obj);
byte[] data = ms.ToArray().Skip(4).ToArray();
ms = new MemoryStream(data);*/
;
} }
} }