Handle input Enter/Esc

This commit is contained in:
2023-06-30 22:09:16 +02:00
parent 2dee906caa
commit bcd47fc640
2 changed files with 29 additions and 1 deletions

View File

@@ -576,7 +576,10 @@
VerticalAlignment="Center"> VerticalAlignment="Center">
<Grid RowDefinitions="Auto,Auto"> <Grid RowDefinitions="Auto,Auto">
<ItemsControl ItemsSource="{Binding DialogService.ReadInput^.Inputs}" x:Name="InputList"> <ItemsControl
ItemsSource="{Binding DialogService.ReadInput^.Inputs}"
KeyUp="InputList_OnKeyUp"
x:Name="InputList">
<ItemsControl.ItemTemplate> <ItemsControl.ItemTemplate>
<DataTemplate> <DataTemplate>
<Grid <Grid

View File

@@ -18,6 +18,8 @@ public partial class MainWindow : Window
private readonly ILogger<MainWindow>? _logger; private readonly ILogger<MainWindow>? _logger;
private readonly IModalService _modalService; private readonly IModalService _modalService;
private IReadOnlyCollection<IModalViewModel>? _openModals; private IReadOnlyCollection<IModalViewModel>? _openModals;
private ReadInputsViewModel? _inputViewModel;
private IDisposable? _inputViewModelSubscription;
public MainWindowViewModel? ViewModel public MainWindowViewModel? ViewModel
{ {
@@ -41,6 +43,15 @@ public partial class MainWindow : Window
InitializeComponent(); InitializeComponent();
ReadInputContainer.PropertyChanged += ReadInputContainerOnPropertyChanged; ReadInputContainer.PropertyChanged += ReadInputContainerOnPropertyChanged;
DataContextChanged += (sender, args) =>
{
if (DataContext is not MainWindowViewModel mainWindowViewModel) return;
_inputViewModelSubscription?.Dispose();
_inputViewModelSubscription = mainWindowViewModel.DialogService.ReadInput.Subscribe(
inputViewModel => _inputViewModel = inputViewModel
);
};
} }
private void OnWindowOpened(object sender, EventArgs e) private void OnWindowOpened(object sender, EventArgs e)
@@ -131,4 +142,18 @@ public partial class MainWindow : Window
var vm = ViewModel; var vm = ViewModel;
Task.Run(() => vm?.OnExit()).Wait(); Task.Run(() => vm?.OnExit()).Wait();
} }
private void InputList_OnKeyUp(object? sender, KeyEventArgs e)
{
if (e.Key == Key.Escape)
{
_inputViewModel?.Cancel();
_inputViewModel = null;
}
else if (e.Key == Key.Enter)
{
_inputViewModel?.Process();
_inputViewModel = null;
}
}
} }