Handle input Enter/Esc
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user