UX-Update 2.0, Neues Dashboard
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Threading;
|
||||
using LehrerApp.Desktop.Services;
|
||||
using LehrerApp.Desktop.ViewModels;
|
||||
using LehrerApp.Sync;
|
||||
@@ -19,6 +20,62 @@ public partial class MainWindow : Window
|
||||
PointerMoved += (_, _) => NotifyActivity();
|
||||
PointerPressed += (_, _) => NotifyActivity();
|
||||
KeyDown += (_, _) => NotifyActivity();
|
||||
KeyDown += OnWindowKeyDown;
|
||||
}
|
||||
|
||||
private void OnWindowKeyDown(object? sender, KeyEventArgs e)
|
||||
{
|
||||
if (DataContext is not MainWindowViewModel vm) return;
|
||||
|
||||
var commandModifier = (e.KeyModifiers & (KeyModifiers.Control | KeyModifiers.Meta)) != 0;
|
||||
if (commandModifier && e.Key == Key.K)
|
||||
{
|
||||
vm.OpenCommandPaletteCommand.Execute(null);
|
||||
FocusCommandPalette();
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!vm.IsCommandPaletteOpen) return;
|
||||
if (e.Key == Key.Escape)
|
||||
{
|
||||
vm.CloseCommandPaletteCommand.Execute(null);
|
||||
e.Handled = true;
|
||||
}
|
||||
else if (e.Key == Key.Enter)
|
||||
{
|
||||
vm.CommandPalette.ExecuteCommand.Execute(vm.CommandPalette.SelectedResult);
|
||||
e.Handled = true;
|
||||
}
|
||||
else if (e.Key is Key.Down or Key.Up)
|
||||
{
|
||||
MoveCommandPaletteSelection(vm, e.Key == Key.Down ? 1 : -1);
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnOpenCommandPaletteClick(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||
{
|
||||
if (DataContext is MainWindowViewModel vm)
|
||||
vm.OpenCommandPaletteCommand.Execute(null);
|
||||
FocusCommandPalette();
|
||||
}
|
||||
|
||||
private void FocusCommandPalette() => Dispatcher.UIThread.Post(() =>
|
||||
{
|
||||
if (this.FindControl<TextBox>("CommandPaletteSearchBox") is { } search)
|
||||
{
|
||||
search.Focus();
|
||||
search.SelectAll();
|
||||
}
|
||||
});
|
||||
|
||||
private static void MoveCommandPaletteSelection(MainWindowViewModel vm, int delta)
|
||||
{
|
||||
var results = vm.CommandPalette.Results;
|
||||
if (results.Count == 0) return;
|
||||
var current = vm.CommandPalette.SelectedResult is { } selected ? results.IndexOf(selected) : -1;
|
||||
vm.CommandPalette.SelectedResult = results[Math.Clamp(current + delta, 0, results.Count - 1)];
|
||||
}
|
||||
|
||||
public void EnableFinalSync(SyncEngine syncEngine)
|
||||
|
||||
Reference in New Issue
Block a user