diff --git a/src/AppCommon/FileTime.App.Core.Abstraction/UserCommand/IdentifiableRunOrOpenCommand.cs b/src/AppCommon/FileTime.App.Core.Abstraction/UserCommand/IdentifiableRunOrOpenCommand.cs new file mode 100644 index 0000000..69f8534 --- /dev/null +++ b/src/AppCommon/FileTime.App.Core.Abstraction/UserCommand/IdentifiableRunOrOpenCommand.cs @@ -0,0 +1,23 @@ +using FileTime.App.Core.ViewModels; + +namespace FileTime.App.Core.UserCommand; + + +public class RunOrOpenCommand : IUserCommand +{ + public IItemViewModel? Item { get; init; } +} + +public sealed class IdentifiableRunOrOpenCommand : RunOrOpenCommand, IIdentifiableUserCommand +{ + public const string CommandName = "run_or_open"; + public static IdentifiableRunOrOpenCommand Instance { get; } = new(); + + private IdentifiableRunOrOpenCommand() + { + } + + public string UserCommandID => CommandName; + + public string Title => "Open or run"; +} \ No newline at end of file diff --git a/src/AppCommon/FileTime.App.Core.Abstraction/UserCommand/RunOrOpenCommand.cs b/src/AppCommon/FileTime.App.Core.Abstraction/UserCommand/RunOrOpenCommand.cs deleted file mode 100644 index 8f05811..0000000 --- a/src/AppCommon/FileTime.App.Core.Abstraction/UserCommand/RunOrOpenCommand.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace FileTime.App.Core.UserCommand; - -public sealed class RunOrOpenCommand : IIdentifiableUserCommand -{ - public const string CommandName = "run_or_open"; - public static RunOrOpenCommand Instance { get; } = new(); - - private RunOrOpenCommand() - { - } - - public string UserCommandID => CommandName; - - public string Title => "Open or run"; -} \ No newline at end of file diff --git a/src/AppCommon/FileTime.App.Core/Services/UserCommandHandler/NavigationUserCommandHandlerService.cs b/src/AppCommon/FileTime.App.Core/Services/UserCommandHandler/NavigationUserCommandHandlerService.cs index 64f2873..d14458d 100644 --- a/src/AppCommon/FileTime.App.Core/Services/UserCommandHandler/NavigationUserCommandHandlerService.cs +++ b/src/AppCommon/FileTime.App.Core/Services/UserCommandHandler/NavigationUserCommandHandlerService.cs @@ -89,14 +89,15 @@ public class NavigationUserCommandHandlerService : UserCommandHandlerServiceBase }); } - private async Task RunOrOpen() + private async Task RunOrOpen(RunOrOpenCommand command) { - if (_currentSelectedItem?.Value is IContainerViewModel) + var item = command.Item ?? _currentSelectedItem?.Value; + if (item is IContainerViewModel) { await OpenSelected(); } else if ( - _currentSelectedItem?.Value is IElementViewModel + item is IElementViewModel { Element: {NativePath: not null, Provider: ILocalContentProvider} localFile } @@ -344,7 +345,7 @@ public class NavigationUserCommandHandlerService : UserCommandHandlerServiceBase ? (IContainer) await _timelessContentProvider.GetItemByFullNameAsync(fullName, PointInTime.Present) : _localContentProvider; } - catch(Exception ex) + catch (Exception ex) { var fullName = _currentLocation?.Value?.FullName?.Path ?? "unknown"; _logger.LogError(ex, "Could not resolve container while switching to tab {TabNumber} to path {FullName}", number, fullName); diff --git a/src/AppCommon/FileTime.App.Core/Services/UserCommandHandlerService.cs b/src/AppCommon/FileTime.App.Core/Services/UserCommandHandlerService.cs index 6e202b3..238f352 100644 --- a/src/AppCommon/FileTime.App.Core/Services/UserCommandHandlerService.cs +++ b/src/AppCommon/FileTime.App.Core/Services/UserCommandHandlerService.cs @@ -9,61 +9,6 @@ public class UserCommandHandlerService : IUserCommandHandlerService public UserCommandHandlerService(IServiceProvider serviceProvider) { _commandHandlers = new Lazy>(serviceProvider.GetServices); - - //(Commands.AutoRefresh, ToggleAutoRefresh), - //(Commands.ChangeTimelineMode, ChangeTimelineMode), - //(Commands.CloseTab, CloseTab), - //(Commands.Compress, Compress), - //(Commands.Copy, Copy), - //(Commands.CopyHash, CopyHash), - //(Commands.CopyPath, CopyPath), - //(Commands.CreateContainer, CreateContainer), - //(Commands.CreateElement, CreateElement), - //(Commands.Cut, Cut), - //(Commands.Edit, Edit), - //(Commands.EnterRapidTravel, EnterRapidTravelMode), - //(Commands.FindByName, FindByName), - //(Commands.FindByNameRegex, FindByNameRegex), - //(Commands.GoToHome, GotToHome), - //(Commands.GoToPath, GoToContainer), - //(Commands.GoToProvider, GotToProvider), - //(Commands.GoToRoot, GotToRoot), - //(Commands.HardDelete, HardDelete), - //(Commands.Mark, MarkCurrentItem), - //(Commands.MoveCursorDownPage, MoveCursorDownPage), - //(Commands.MoveCursorUpPage, MoveCursorUpPage), - //(Commands.MoveToFirst, MoveToFirst), - //(Commands.MoveToLast, MoveToLast), - //(Commands.NextTimelineBlock, SelectNextTimelineBlock), - //(Commands.NextTimelineCommand, SelectNextTimelineCommand), - //(Commands.OpenInFileBrowser, OpenInDefaultFileExplorer), - //(Commands.OpenOrRun, OpenOrRun), - //(Commands.PasteMerge, PasteMerge), - //(Commands.PasteOverwrite, PasteOverwrite), - //(Commands.PasteSkip, PasteSkip), - //(Commands.PinFavorite, PinFavorite), - //(Commands.PreviousTimelineBlock, SelectPreviousTimelineBlock), - //(Commands.PreviousTimelineCommand, SelectPreviousTimelineCommand), - //(Commands.Refresh, RefreshCurrentLocation), - //(Commands.Rename, Rename), - //(Commands.RunCommand, RunCommandInContainer), - //(Commands.ScanContainerSize, ScanContainerSize), - //(Commands.ShowAllShotcut, ShowAllShortcut), - //(Commands.SoftDelete, SoftDelete), - //(Commands.SwitchToLastTab, async() => await SwitchToTab(-1)), - //(Commands.SwitchToTab1, async() => await SwitchToTab(1)), - //(Commands.SwitchToTab2, async() => await SwitchToTab(2)), - //(Commands.SwitchToTab3, async() => await SwitchToTab(3)), - //(Commands.SwitchToTab4, async() => await SwitchToTab(4)), - //(Commands.SwitchToTab5, async() => await SwitchToTab(5)), - //(Commands.SwitchToTab6, async() => await SwitchToTab(6)), - //(Commands.SwitchToTab7, async() => await SwitchToTab(7)), - //(Commands.SwitchToTab8, async() => await SwitchToTab(8)), - //(Commands.TimelinePause, PauseTimeline), - //(Commands.TimelineRefresh, RefreshTimeline), - //(Commands.TimelineStart, ContinueTimeline), - //(Commands.ToggleAdvancedIcons, ToggleAdvancedIcons), - //(Commands.ToggleHidden, ToggleHidden), } public async Task HandleCommandAsync(UserCommand.IUserCommand command) diff --git a/src/AppCommon/FileTime.App.Core/StartupServices/DefaultIdentifiableCommandHandlerRegister.cs b/src/AppCommon/FileTime.App.Core/StartupServices/DefaultIdentifiableCommandHandlerRegister.cs index f1f9742..5e264ef 100644 --- a/src/AppCommon/FileTime.App.Core/StartupServices/DefaultIdentifiableCommandHandlerRegister.cs +++ b/src/AppCommon/FileTime.App.Core/StartupServices/DefaultIdentifiableCommandHandlerRegister.cs @@ -47,7 +47,7 @@ public class DefaultIdentifiableCommandHandlerRegister : IStartupHandler AddUserCommand(PauseCommandSchedulerCommand.Instance); AddUserCommand(RefreshCommand.Instance); AddUserCommand(RenameCommand.Instance); - AddUserCommand(RunOrOpenCommand.Instance); + AddUserCommand(IdentifiableRunOrOpenCommand.Instance); AddUserCommand(ScanSizeCommand.Instance); AddUserCommand(StartCommandSchedulerCommand.Instance); AddUserCommand(SortItemsCommand.OrderByNameCommand); diff --git a/src/GuiApp/Avalonia/FileTime.GuiApp.Abstractions/Configuration/MainConfiguration.cs b/src/GuiApp/Avalonia/FileTime.GuiApp.Abstractions/Configuration/MainConfiguration.cs index d415335..f05c734 100644 --- a/src/GuiApp/Avalonia/FileTime.GuiApp.Abstractions/Configuration/MainConfiguration.cs +++ b/src/GuiApp/Avalonia/FileTime.GuiApp.Abstractions/Configuration/MainConfiguration.cs @@ -97,7 +97,7 @@ public static class MainConfiguration new(RefreshCommand.CommandName, Key.R), new(RenameCommand.CommandName, Key.F2), new(RenameCommand.CommandName, new[] {Key.C, Key.W}), - new(RunOrOpenCommand.CommandName, Key.Enter), + new(IdentifiableRunOrOpenCommand.CommandName, Key.Enter), //new CommandBindingConfiguration(ConfigCommand.RunCommand, new KeyConfig(Key.D4, shift: true)), //new CommandBindingConfiguration(ConfigCommand.ScanContainerSize, new[] { Key.C, Key.S }), //new CommandBindingConfiguration(ConfigCommand.ShowAllShortcut, Key.F1), diff --git a/src/GuiApp/Avalonia/FileTime.GuiApp/ViewModels/IMainWindowViewModel.cs b/src/GuiApp/Avalonia/FileTime.GuiApp/ViewModels/IMainWindowViewModel.cs index 480e832..f6e4f87 100644 --- a/src/GuiApp/Avalonia/FileTime.GuiApp/ViewModels/IMainWindowViewModel.cs +++ b/src/GuiApp/Avalonia/FileTime.GuiApp/ViewModels/IMainWindowViewModel.cs @@ -1,5 +1,6 @@ using FileTime.App.CommandPalette.Services; using FileTime.App.Core.Services; +using FileTime.App.Core.ViewModels; using FileTime.App.FrequencyNavigation.Services; using FileTime.GuiApp.Services; using FileTime.Providers.LocalAdmin; @@ -17,4 +18,5 @@ public interface IMainWindowViewModel : IMainWindowViewModelBase IRefreshSmoothnessCalculator RefreshSmoothnessCalculator { get; } IAdminElevationManager AdminElevationManager { get; } IClipboardService ClipboardService { get; } + Task RunOrOpenItem(IItemViewModel itemViewModel); } \ No newline at end of file diff --git a/src/GuiApp/Avalonia/FileTime.GuiApp/ViewModels/MainWindowViewModel.cs b/src/GuiApp/Avalonia/FileTime.GuiApp/ViewModels/MainWindowViewModel.cs index 913f948..08df503 100644 --- a/src/GuiApp/Avalonia/FileTime.GuiApp/ViewModels/MainWindowViewModel.cs +++ b/src/GuiApp/Avalonia/FileTime.GuiApp/ViewModels/MainWindowViewModel.cs @@ -4,6 +4,7 @@ using Avalonia.Input; using FileTime.App.CommandPalette.Services; using FileTime.App.Core.Services; using FileTime.App.Core.UserCommand; +using FileTime.App.Core.ViewModels; using FileTime.App.FrequencyNavigation.Services; using FileTime.Core.Models; using FileTime.Core.Timeline; @@ -77,6 +78,13 @@ public partial class MainWindowViewModel : IMainWindowViewModel new OpenContainerCommand(new AbsolutePath(_timelessContentProvider, resolvedContainer))); } + public async Task RunOrOpenItem(IItemViewModel itemViewModel) => + await UserCommandHandlerService.HandleCommandAsync( + new RunOrOpenCommand + { + Item = itemViewModel + }); + public async Task OnExit() => await _lifecycleService.ExitAsync(); } \ 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 4e65630..6b7940b 100644 --- a/src/GuiApp/Avalonia/FileTime.GuiApp/Views/MainWindow.axaml +++ b/src/GuiApp/Avalonia/FileTime.GuiApp/Views/MainWindow.axaml @@ -478,7 +478,10 @@ x:Name="CurrentItems"> - + diff --git a/src/GuiApp/Avalonia/FileTime.GuiApp/Views/MainWindow.axaml.cs b/src/GuiApp/Avalonia/FileTime.GuiApp/Views/MainWindow.axaml.cs index 712087c..186217b 100644 --- a/src/GuiApp/Avalonia/FileTime.GuiApp/Views/MainWindow.axaml.cs +++ b/src/GuiApp/Avalonia/FileTime.GuiApp/Views/MainWindow.axaml.cs @@ -184,4 +184,26 @@ public partial class MainWindow : Window, IUiAccessor public async Task InvokeOnUIThread(Func func) => await Dispatcher.UIThread.InvokeAsync(func); public async Task InvokeOnUIThread(Func> func) => await Dispatcher.UIThread.InvokeAsync(func); + + private async void Child_OnPointerPressed(object? sender, PointerPressedEventArgs e) + { + if (e is {Handled: false, ClickCount: 2} + && ViewModel != null + && e.GetCurrentPoint(this).Properties.IsLeftButtonPressed + && sender is StyledElement {DataContext: IItemViewModel itemViewModel}) + { + try + { + await ViewModel.RunOrOpenItem(itemViewModel); + } + catch (Exception ex) + { + _logger?.LogError( + ex, + "Error while opening item {Item}", + itemViewModel.BaseItem?.FullName?.Path ?? itemViewModel.DisplayNameText + ); + } + } + } } \ No newline at end of file