added keyboard navigation for selected images -> TOOD: allow visual keyboardnavigation when photo is not maximized
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Xaml.Interactions.DragAndDrop;
|
||||
@@ -9,6 +10,7 @@ namespace Photos.Views;
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
private IFolderPickerService _folderPickerService;
|
||||
private int _currentImageIndex = 0;
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
@@ -21,4 +23,60 @@ public partial class MainWindow : Window
|
||||
{
|
||||
(DataContext as MainWindowViewModel)?.WindowDropHandler(e);
|
||||
}
|
||||
|
||||
private void OnKeyDownHandler(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (DataContext is not MainWindowViewModel vm) return;
|
||||
|
||||
async Task HandleEnter()
|
||||
{
|
||||
if (vm.IsPhotoFocused()) vm.UnfocusPhoto();
|
||||
else await vm.TryFocusImage(_currentImageIndex);
|
||||
}
|
||||
|
||||
void HandleEscape()
|
||||
{
|
||||
vm.UnfocusPhoto();
|
||||
}
|
||||
|
||||
async Task HandleArrowKey()
|
||||
{
|
||||
if(vm.IsPhotoFocused()) await vm.TryFocusImage(_currentImageIndex);
|
||||
// TODO: move basic selection
|
||||
}
|
||||
|
||||
switch (e.Key)
|
||||
{
|
||||
case Key.Enter:
|
||||
HandleEnter().GetAwaiter();
|
||||
break;
|
||||
case Key.Escape:
|
||||
HandleEscape();
|
||||
break;
|
||||
case Key.Down:
|
||||
break;
|
||||
case Key.Left:
|
||||
if (_currentImageIndex > 0)
|
||||
{
|
||||
_currentImageIndex--;
|
||||
HandleArrowKey().GetAwaiter();
|
||||
}
|
||||
break;
|
||||
case Key.Right:
|
||||
if (_currentImageIndex < vm.Photos.Count - 1)
|
||||
{
|
||||
_currentImageIndex++;
|
||||
HandleArrowKey().GetAwaiter();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void PointerEnteredPhotoHandler(object sender, PointerEventArgs e)
|
||||
{
|
||||
if (sender is not Image i || DataContext is not MainWindowViewModel vm) return;
|
||||
var idx = vm.GetImageIndex(i);
|
||||
if (idx == -1) return;
|
||||
_currentImageIndex = idx;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user