From 96158160bd89d932a94b0f00609c7ba2113950e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81d=C3=A1m=20Kov=C3=A1cs?= Date: Wed, 25 May 2022 14:05:14 +0200 Subject: [PATCH] Loading fix, CopyPath, Open in explorer --- .../Services/ISystemClipboardService.cs | 6 +++ .../UserCommand/CopyNativePathCommand.cs | 13 +++++++ .../OpenInDefaultFileExplorerCommand.cs | 13 +++++++ .../Persistence/TabPersistenceService.cs | 1 - .../NavigationUserCommandHandlerService.cs | 1 - .../ToolUserCommandHandlerService.cs | 39 +++++++++++++++++++ src/AppCommon/FileTime.App.Core/Startup.cs | 3 +- ...faultIdentifiableCommandHandlerRegister.cs | 2 + .../Configuration/MainConfiguration.cs | 4 +- .../Avalonia/FileTime.GuiApp.App/Startup.cs | 1 + .../Services/SystemClipboardService.cs | 14 +++++++ .../FileTime.GuiApp/Views/MainWindow.axaml | 7 ++-- 12 files changed, 96 insertions(+), 8 deletions(-) create mode 100644 src/AppCommon/FileTime.App.Core.Abstraction/Services/ISystemClipboardService.cs create mode 100644 src/AppCommon/FileTime.App.Core.Abstraction/UserCommand/CopyNativePathCommand.cs create mode 100644 src/AppCommon/FileTime.App.Core.Abstraction/UserCommand/OpenInDefaultFileExplorerCommand.cs create mode 100644 src/AppCommon/FileTime.App.Core/Services/UserCommandHandler/ToolUserCommandHandlerService.cs create mode 100644 src/GuiApp/Avalonia/FileTime.GuiApp/Services/SystemClipboardService.cs diff --git a/src/AppCommon/FileTime.App.Core.Abstraction/Services/ISystemClipboardService.cs b/src/AppCommon/FileTime.App.Core.Abstraction/Services/ISystemClipboardService.cs new file mode 100644 index 0000000..9e1926b --- /dev/null +++ b/src/AppCommon/FileTime.App.Core.Abstraction/Services/ISystemClipboardService.cs @@ -0,0 +1,6 @@ +namespace FileTime.App.Core.Services; + +public interface ISystemClipboardService +{ + Task CopyToClipboardAsync(string text); +} \ No newline at end of file diff --git a/src/AppCommon/FileTime.App.Core.Abstraction/UserCommand/CopyNativePathCommand.cs b/src/AppCommon/FileTime.App.Core.Abstraction/UserCommand/CopyNativePathCommand.cs new file mode 100644 index 0000000..a73cdaf --- /dev/null +++ b/src/AppCommon/FileTime.App.Core.Abstraction/UserCommand/CopyNativePathCommand.cs @@ -0,0 +1,13 @@ +namespace FileTime.App.Core.UserCommand; + +public class CopyNativePathCommand : IIdentifiableUserCommand +{ + public const string CommandName = "copy_path"; + public static CopyNativePathCommand Instance { get; } = new CopyNativePathCommand(); + + private CopyNativePathCommand() + { + } + + public string UserCommandID => CommandName; +} \ No newline at end of file diff --git a/src/AppCommon/FileTime.App.Core.Abstraction/UserCommand/OpenInDefaultFileExplorerCommand.cs b/src/AppCommon/FileTime.App.Core.Abstraction/UserCommand/OpenInDefaultFileExplorerCommand.cs new file mode 100644 index 0000000..606cbbf --- /dev/null +++ b/src/AppCommon/FileTime.App.Core.Abstraction/UserCommand/OpenInDefaultFileExplorerCommand.cs @@ -0,0 +1,13 @@ +namespace FileTime.App.Core.UserCommand; + +public class OpenInDefaultFileExplorerCommand : IIdentifiableUserCommand +{ + public const string CommandName = "open_in_default_explorer"; + public static OpenInDefaultFileExplorerCommand Instance { get; } = new OpenInDefaultFileExplorerCommand(); + + private OpenInDefaultFileExplorerCommand() + { + } + + public string UserCommandID => CommandName; +} \ No newline at end of file diff --git a/src/AppCommon/FileTime.App.Core/Services/Persistence/TabPersistenceService.cs b/src/AppCommon/FileTime.App.Core/Services/Persistence/TabPersistenceService.cs index 886caf3..322504a 100644 --- a/src/AppCommon/FileTime.App.Core/Services/Persistence/TabPersistenceService.cs +++ b/src/AppCommon/FileTime.App.Core/Services/Persistence/TabPersistenceService.cs @@ -1,4 +1,3 @@ -using System.Reactive.Linq; using System.Text.Json; using FileTime.App.Core.Models; using FileTime.App.Core.ViewModels; diff --git a/src/AppCommon/FileTime.App.Core/Services/UserCommandHandler/NavigationUserCommandHandlerService.cs b/src/AppCommon/FileTime.App.Core/Services/UserCommandHandler/NavigationUserCommandHandlerService.cs index 298c072..1c2c5d7 100644 --- a/src/AppCommon/FileTime.App.Core/Services/UserCommandHandler/NavigationUserCommandHandlerService.cs +++ b/src/AppCommon/FileTime.App.Core/Services/UserCommandHandler/NavigationUserCommandHandlerService.cs @@ -7,7 +7,6 @@ using FileTime.Core.Services; using FileTime.Core.Timeline; using FileTime.Providers.Local; using InitableService; -using Microsoft.Extensions.DependencyInjection; namespace FileTime.App.Core.Services.UserCommandHandler; diff --git a/src/AppCommon/FileTime.App.Core/Services/UserCommandHandler/ToolUserCommandHandlerService.cs b/src/AppCommon/FileTime.App.Core/Services/UserCommandHandler/ToolUserCommandHandlerService.cs new file mode 100644 index 0000000..a333ea5 --- /dev/null +++ b/src/AppCommon/FileTime.App.Core/Services/UserCommandHandler/ToolUserCommandHandlerService.cs @@ -0,0 +1,39 @@ +using System.Diagnostics; +using FileTime.App.Core.UserCommand; +using FileTime.App.Core.ViewModels; +using FileTime.Core.Models; + +namespace FileTime.App.Core.Services.UserCommandHandler; + +public class ToolUserCommandHandlerService : UserCommandHandlerServiceBase +{ + private readonly ISystemClipboardService _systemClipboardService; + private IContainer? _currentLocation; + private IItemViewModel? _currentSelectedItem; + + public ToolUserCommandHandlerService(IAppState appState, ISystemClipboardService systemClipboardService) : base(appState) + { + _systemClipboardService = systemClipboardService; + SaveCurrentLocation(l => _currentLocation = l); + SaveCurrentSelectedItem(i => _currentSelectedItem = i); + + AddCommandHandlers(new IUserCommandHandler[] + { + new TypeUserCommandHandler(OpenInDefaultFileExplorer), + new TypeUserCommandHandler(CopyNativePath), + }); + } + + private async Task CopyNativePath() + { + if (_currentSelectedItem?.BaseItem?.NativePath is null) return; + await _systemClipboardService.CopyToClipboardAsync(_currentSelectedItem.BaseItem.NativePath.Path); + } + + private Task OpenInDefaultFileExplorer() + { + if (_currentLocation?.NativePath is null) return Task.CompletedTask; + Process.Start("explorer.exe", "\"" + _currentLocation.NativePath.Path + "\""); + return Task.CompletedTask; + } +} \ No newline at end of file diff --git a/src/AppCommon/FileTime.App.Core/Startup.cs b/src/AppCommon/FileTime.App.Core/Startup.cs index 3f28678..a87aca9 100644 --- a/src/AppCommon/FileTime.App.Core/Startup.cs +++ b/src/AppCommon/FileTime.App.Core/Startup.cs @@ -33,6 +33,7 @@ public static class Startup { return serviceCollection .AddSingleton() - .AddSingleton(); + .AddSingleton() + .AddSingleton(); } } \ No newline at end of file diff --git a/src/AppCommon/FileTime.App.Core/StartupServices/DefaultIdentifiableCommandHandlerRegister.cs b/src/AppCommon/FileTime.App.Core/StartupServices/DefaultIdentifiableCommandHandlerRegister.cs index 9ee1e88..e990828 100644 --- a/src/AppCommon/FileTime.App.Core/StartupServices/DefaultIdentifiableCommandHandlerRegister.cs +++ b/src/AppCommon/FileTime.App.Core/StartupServices/DefaultIdentifiableCommandHandlerRegister.cs @@ -13,6 +13,7 @@ public class DefaultIdentifiableCommandHandlerRegister : IStartupHandler AddUserCommand(CloseTabCommand.Instance); AddUserCommand(CopyCommand.Instance); + AddUserCommand(CopyNativePathCommand.Instance); AddUserCommand(CreateContainer.Instance); AddUserCommand(CreateElement.Instance); AddUserCommand(EnterRapidTravelCommand.Instance); @@ -28,6 +29,7 @@ public class DefaultIdentifiableCommandHandlerRegister : IStartupHandler AddUserCommand(MoveCursorToLastCommand.Instance); AddUserCommand(MoveCursorUpCommand.Instance); AddUserCommand(MoveCursorUpPageCommand.Instance); + AddUserCommand(OpenInDefaultFileExplorerCommand.Instance); AddUserCommand(OpenSelectedCommand.Instance); AddUserCommand(PasteCommand.Merge); AddUserCommand(PasteCommand.Overwrite); diff --git a/src/GuiApp/Avalonia/FileTime.GuiApp.Abstractions/Configuration/MainConfiguration.cs b/src/GuiApp/Avalonia/FileTime.GuiApp.Abstractions/Configuration/MainConfiguration.cs index c5a363f..58a2e03 100644 --- a/src/GuiApp/Avalonia/FileTime.GuiApp.Abstractions/Configuration/MainConfiguration.cs +++ b/src/GuiApp/Avalonia/FileTime.GuiApp.Abstractions/Configuration/MainConfiguration.cs @@ -49,7 +49,7 @@ public static class MainConfiguration //new CommandBindingConfiguration(ConfigCommand.Compress, new[] { Key.Y, Key.C }), new CommandBindingConfiguration(CopyCommand.CommandName, new[] { Key.Y, Key.Y }), //new CommandBindingConfiguration(ConfigCommand.CopyHash, new[] { Key.C, Key.H }), - //new CommandBindingConfiguration(ConfigCommand.CopyPath, new[] { Key.C, Key.P }), + new CommandBindingConfiguration(CopyNativePathCommand.CommandName, new[] { Key.C, Key.P }), new CommandBindingConfiguration(CreateContainer.CommandName, Key.F7), new CommandBindingConfiguration(CreateContainer.CommandName, new[] { Key.C, Key.C }), new CommandBindingConfiguration(CreateElement.CommandName, new[] { Key.C, Key.E }), @@ -69,7 +69,7 @@ public static class MainConfiguration new CommandBindingConfiguration(MoveCursorToFirstCommand.CommandName, new[] { Key.G, Key.G }), //new CommandBindingConfiguration(ConfigCommand.NextTimelineBlock, Key.L ), //new CommandBindingConfiguration(ConfigCommand.NextTimelineCommand, Key.J ), - //new CommandBindingConfiguration(ConfigCommand.OpenInFileBrowser, new[] { Key.O, Key.E }), + new CommandBindingConfiguration(OpenInDefaultFileExplorerCommand.CommandName, new[] { Key.O, Key.E }), new CommandBindingConfiguration(PasteCommand.PasteMergeCommandName, new[] { Key.P, Key.P }), new CommandBindingConfiguration(PasteCommand.PasteOverwriteCommandName, new[] { Key.P, Key.O }), new CommandBindingConfiguration(PasteCommand.PasteSkipCommandName, new[] { Key.P, Key.S }), diff --git a/src/GuiApp/Avalonia/FileTime.GuiApp.App/Startup.cs b/src/GuiApp/Avalonia/FileTime.GuiApp.App/Startup.cs index fc0d24e..d8168a5 100644 --- a/src/GuiApp/Avalonia/FileTime.GuiApp.App/Startup.cs +++ b/src/GuiApp/Avalonia/FileTime.GuiApp.App/Startup.cs @@ -39,6 +39,7 @@ public static class Startup serviceCollection.TryAddSingleton(); serviceCollection.TryAddSingleton(); serviceCollection.TryAddSingleton(); + serviceCollection.TryAddSingleton(); serviceCollection.TryAddSingleton(s => s.GetRequiredService()); return serviceCollection diff --git a/src/GuiApp/Avalonia/FileTime.GuiApp/Services/SystemClipboardService.cs b/src/GuiApp/Avalonia/FileTime.GuiApp/Services/SystemClipboardService.cs new file mode 100644 index 0000000..9a07788 --- /dev/null +++ b/src/GuiApp/Avalonia/FileTime.GuiApp/Services/SystemClipboardService.cs @@ -0,0 +1,14 @@ +using FileTime.App.Core.Services; + +namespace FileTime.GuiApp.Services; + +public class SystemClipboardService : ISystemClipboardService +{ + public async Task CopyToClipboardAsync(string text) + { + if (global::Avalonia.Application.Current?.Clipboard is { } clipboard) + { + await clipboard.SetTextAsync(text); + } + } +} \ No newline at end of file diff --git a/src/GuiApp/Avalonia/FileTime.GuiApp/Views/MainWindow.axaml b/src/GuiApp/Avalonia/FileTime.GuiApp/Views/MainWindow.axaml index 3cd976d..f0b4d09 100644 --- a/src/GuiApp/Avalonia/FileTime.GuiApp/Views/MainWindow.axaml +++ b/src/GuiApp/Avalonia/FileTime.GuiApp/Views/MainWindow.axaml @@ -28,11 +28,12 @@ + x:DataType="vm:MainWindowViewModel" + IsVisible="{Binding Loading, Converter={x:Static BoolConverters.Not}, FallbackValue=False}"> + + RowDefinitions="Auto,*">