Files
LehrerApp/LehrerApp.Desktop/Views/Groups/ParticipationQuickInputDialog.axaml.cs
T

55 lines
2.0 KiB
C#

using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
using LehrerApp.Desktop.ViewModels.Groups;
namespace LehrerApp.Desktop.Views.Groups;
public partial class ParticipationQuickInputDialog : Window
{
public ParticipationQuickInputDialog() => InitializeComponent();
protected override void OnOpened(EventArgs e)
{
base.OnOpened(e);
Focus();
}
protected override void OnKeyDown(KeyEventArgs e)
{
if (DataContext is not QuickInputViewModel vm) { base.OnKeyDown(e); return; }
switch (e.Key)
{
case Key.D1 or Key.NumPad1: vm.SetRatingByNumber(1); e.Handled = true; break;
case Key.D2 or Key.NumPad2: vm.SetRatingByNumber(2); e.Handled = true; break;
case Key.D3 or Key.NumPad3: vm.SetRatingByNumber(3); e.Handled = true; break;
case Key.D4 or Key.NumPad4: vm.SetRatingByNumber(4); e.Handled = true; break;
case Key.D5 or Key.NumPad5: vm.SetRatingByNumber(5); e.Handled = true; break;
case Key.Q: vm.SelectAspect(0); e.Handled = true; break;
case Key.W: vm.SelectAspect(1); e.Handled = true; break;
case Key.E: vm.SelectAspect(2); e.Handled = true; break;
case Key.R: vm.SelectAspect(3); e.Handled = true; break;
case Key.T: vm.SelectAspect(4); e.Handled = true; break;
case Key.Space: vm.NextAspect(); e.Handled = true; break;
case Key.Enter:
if (vm.IsLastStudent) Close();
else vm.NextStudent();
e.Handled = true;
break;
case Key.Back: vm.PreviousStudent(); e.Handled = true; break;
case Key.OemPlus or Key.Add: vm.IncrementRating(); e.Handled = true; break;
case Key.OemMinus or Key.Subtract: vm.DecrementRating(); e.Handled = true; break;
case Key.Escape: Close(); e.Handled = true; break;
default: base.OnKeyDown(e); break;
}
}
private void OnClose(object? s, RoutedEventArgs e) => Close();
}