Item double click (run or open)

This commit is contained in:
2023-08-03 11:17:51 +02:00
parent 558a0a08bb
commit 3304d775f5
10 changed files with 66 additions and 77 deletions

View File

@@ -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),

View File

@@ -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);
}

View File

@@ -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();
}

View File

@@ -478,7 +478,10 @@
x:Name="CurrentItems">
<ListBox.ItemTemplate>
<DataTemplate x:DataType="corevm:IItemViewModel">
<local:ItemView HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" />
<local:ItemView
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
PointerPressed="Child_OnPointerPressed" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

View File

@@ -184,4 +184,26 @@ public partial class MainWindow : Window, IUiAccessor
public async Task InvokeOnUIThread(Func<Task> func) => await Dispatcher.UIThread.InvokeAsync(func);
public async Task<T> InvokeOnUIThread<T>(Func<Task<T>> 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
);
}
}
}
}