This commit is contained in:
2022-06-09 17:49:34 +02:00
parent 9d48caaa58
commit 0b3fe30fec
24 changed files with 254 additions and 34 deletions

View File

@@ -1,5 +1,6 @@
using System.Reactive.Linq;
using Avalonia.Input;
using FileTime.App.Core.Models;
using FileTime.App.Core.Services;
using FileTime.App.Core.UserCommand;
using FileTime.App.Core.ViewModels;
@@ -15,6 +16,7 @@ namespace FileTime.GuiApp.Services;
public class DefaultModeKeyInputHandler : IDefaultModeKeyInputHandler
{
private readonly IGuiAppState _appState;
private readonly IModalService _modalService;
private readonly IKeyboardConfigurationService _keyboardConfigurationService;
private readonly List<KeyConfig[]> _keysToSkip = new();
private ITabViewModel? _selectedTab;
@@ -22,22 +24,27 @@ public class DefaultModeKeyInputHandler : IDefaultModeKeyInputHandler
private readonly ILogger<DefaultModeKeyInputHandler> _logger;
private readonly IUserCommandHandlerService _userCommandHandlerService;
private readonly IIdentifiableUserCommandService _identifiableUserCommandService;
private readonly BindedCollection<IModalViewModel> _openModals;
public DefaultModeKeyInputHandler(
IGuiAppState appState,
IModalService modalService,
IKeyboardConfigurationService keyboardConfigurationService,
ILogger<DefaultModeKeyInputHandler> logger,
IUserCommandHandlerService userCommandHandlerService,
IIdentifiableUserCommandService identifiableUserCommandService)
{
_appState = appState;
_identifiableUserCommandService = identifiableUserCommandService;
_keyboardConfigurationService = keyboardConfigurationService;
_logger = logger;
_modalService = modalService;
_userCommandHandlerService = userCommandHandlerService;
_identifiableUserCommandService = identifiableUserCommandService;
_appState.SelectedTab.Subscribe(t => _selectedTab = t);
_appState.SelectedTab.Select(t => t == null ? Observable.Return<IContainer?>(null) : t.CurrentLocation!).Switch().Subscribe(l => _currentLocation = l);
_openModals = new BindedCollection<IModalViewModel>(modalService.OpenModals);
_keysToSkip.Add(new KeyConfig[] { new KeyConfig(Key.Up) });
_keysToSkip.Add(new KeyConfig[] { new KeyConfig(Key.Down) });
@@ -59,10 +66,11 @@ public class DefaultModeKeyInputHandler : IDefaultModeKeyInputHandler
if (key == Key.Escape)
{
var doGeneralReset = false;
if (_appState.PreviousKeys.Count > 1 || _appState.IsAllShortcutVisible || _appState.MessageBoxText != null)
bool doGeneralReset = _appState.PreviousKeys.Count > 1 || _appState.IsAllShortcutVisible;
if ((_openModals.Collection?.Count ?? 0) > 0)
{
doGeneralReset = true;
_modalService.CloseModal(_openModals.Collection!.Last());
}
/*else if (_currentLocation.Container.CanHandleEscape)
{
@@ -90,18 +98,17 @@ public class DefaultModeKeyInputHandler : IDefaultModeKeyInputHandler
{
setHandled(true);
_appState.IsAllShortcutVisible = false;
_appState.MessageBoxText = null;
_appState.PreviousKeys.Clear();
_appState.PossibleCommands = new();
}
}
else if (key == Key.Enter
/*else if (key == Key.Enter
&& _appState.MessageBoxText != null)
{
_appState.PreviousKeys.Clear();
//_dialogService.ProcessMessageBox();
setHandled(true);
}
}*/
else if (selectedCommandBinding != null)
{
setHandled(true);

View File

@@ -1,6 +1,8 @@
using System.Collections.ObjectModel;
using System.Reactive.Linq;
using Avalonia.Threading;
using DynamicData;
using FileTime.App.Core.Models;
using FileTime.App.Core.Services;
using FileTime.Core.Interactions;
using FileTime.GuiApp.ViewModels;
@@ -13,6 +15,7 @@ public class DialogService : IDialogService
private readonly IGuiAppState _guiAppState;
public IObservable<ReadInputsViewModel?> ReadInput { get; }
public IObservable<MessageBoxViewModel?> LastMessageBox { get; }
public DialogService(IModalService modalService, IGuiAppState guiAppState)
{
@@ -22,10 +25,18 @@ public class DialogService : IDialogService
.OpenModals
.ToCollection()
.Select(modals =>
(ReadInputsViewModel?)modals.FirstOrDefault(m => m is ReadInputsViewModel)
(ReadInputsViewModel?) modals.FirstOrDefault(m => m is ReadInputsViewModel)
)
.Publish(null)
.RefCount();
LastMessageBox =
modalService
.OpenModals
.Filter(m => m is MessageBoxViewModel)
.Transform(m => (MessageBoxViewModel) m)
.ToCollection()
.Select(m => m.LastOrDefault());
}
public void ReadInputs(IEnumerable<IInputElement> inputs, Action inputHandler, Action? cancelHandler = null)
@@ -50,6 +61,18 @@ public class DialogService : IDialogService
});
}
public Task<MessageBoxResult> ShowMessageBox(string text)
{
var taskCompletionSource = new TaskCompletionSource<MessageBoxResult>();
_modalService.OpenModal(new MessageBoxViewModel(text, (vm, result) =>
{
_modalService.CloseModal(vm);
taskCompletionSource.SetResult(result);
}));
return taskCompletionSource.Task;
}
private void HandleReadInputsSuccess(ReadInputsViewModel readInputsViewModel)
{
_modalService.CloseModal(readInputsViewModel);
@@ -66,7 +89,7 @@ public class DialogService : IDialogService
{
var taskCompletionSource = new TaskCompletionSource<bool>();
ReadInputs(fields, () => taskCompletionSource.SetResult(true), () => taskCompletionSource.SetResult(false));
return taskCompletionSource.Task;
}
}

View File

@@ -6,15 +6,15 @@ namespace FileTime.GuiApp.Services;
public class ModalService : IModalService
{
private readonly SourceList<IModalViewModelBase> _openModals = new();
public IObservable<IChangeSet<IModalViewModelBase>> OpenModals { get; }
private readonly SourceList<IModalViewModel> _openModals = new();
public IObservable<IChangeSet<IModalViewModel>> OpenModals { get; }
public ModalService()
{
OpenModals = _openModals.Connect().StartWithEmpty();
}
public void OpenModal(IModalViewModelBase modalToOpen) => _openModals.Add(modalToOpen);
public void OpenModal(IModalViewModel modalToOpen) => _openModals.Add(modalToOpen);
public void CloseModal(IModalViewModelBase modalToClose) => _openModals.Remove(modalToClose);
public void CloseModal(IModalViewModel modalToClose) => _openModals.Remove(modalToClose);
}

View File

@@ -22,7 +22,7 @@ public class RapidTravelModeKeyInputHandler : IRapidTravelModeKeyInputHandler
private readonly IUserCommandHandlerService _userCommandHandlerService;
private readonly ILogger<RapidTravelModeKeyInputHandler> _logger;
private readonly IIdentifiableUserCommandService _identifiableUserCommandService;
private readonly BindedCollection<IModalViewModelBase> _openModals;
private readonly BindedCollection<IModalViewModel> _openModals;
private ITabViewModel? _selectedTab;
public RapidTravelModeKeyInputHandler(
@@ -42,7 +42,7 @@ public class RapidTravelModeKeyInputHandler : IRapidTravelModeKeyInputHandler
_appState.SelectedTab.Subscribe(t => _selectedTab = t);
_openModals = new BindedCollection<IModalViewModelBase>(modalService.OpenModals);
_openModals = new BindedCollection<IModalViewModel>(modalService.OpenModals);
}
public async Task HandleInputKey(Key key, SpecialKeysStatus specialKeysStatus, Action<bool> setHandled)

View File

@@ -326,7 +326,8 @@
<Grid
Grid.Column="2"
RowDefinitions="Auto,*">
<Grid IsVisible="{Binding AppState.SelectedTab^.CurrentLocation^.IsLoading^, FallbackValue=False}">
<Grid
IsVisible="{Binding AppState.SelectedTab^.CurrentLocation^.IsLoading^, FallbackValue=False}">
<Image
Width="40"
Height="40"
@@ -443,17 +444,19 @@
</Grid>
</Grid>
</Grid>
<ItemsRepeater Items="{Binding AppState.PopupTexts}" Margin="0,0,0,20" HorizontalAlignment="Center" VerticalAlignment="Top" IsVisible="{Binding AppState.PopupTexts.Count,Converter={StaticResource NotEqualsConverter}, ConverterParameter=0}">
<ItemsRepeater Items="{Binding AppState.PopupTexts}" Margin="0,0,0,20"
HorizontalAlignment="Center" VerticalAlignment="Top"
IsVisible="{Binding AppState.PopupTexts.Count,Converter={StaticResource NotEqualsConverter}, ConverterParameter=0}">
<ItemsRepeater.Styles>
<Style Selector="TextBlock">
<Style.Animations>
<Animation Duration="0:0:1">
<KeyFrame Cue="0%">
<Setter Property="Opacity" Value="0.0"/>
<Setter Property="Opacity" Value="0.0" />
</KeyFrame>
<KeyFrame Cue="100%">
<Setter Property="Opacity" Value="1.0"/>
<Setter Property="Opacity" Value="1.0" />
</KeyFrame>
</Animation>
</Style.Animations>
@@ -461,8 +464,11 @@
</ItemsRepeater.Styles>
<ItemsRepeater.ItemTemplate>
<DataTemplate x:DataType="x:String">
<Border Background="{DynamicResource ContainerGradientBackgroundBrush}" Margin="5" Padding="5">
<TextBlock Text="{Binding}" Foreground="{DynamicResource AccentComplementBrush}" HorizontalAlignment="Center"/>
<Border Background="{DynamicResource ContainerGradientBackgroundBrush}" Margin="5"
Padding="5">
<TextBlock Text="{Binding}"
Foreground="{DynamicResource AccentComplementBrush}"
HorizontalAlignment="Center" />
</Border>
</DataTemplate>
</ItemsRepeater.ItemTemplate>
@@ -599,6 +605,38 @@
</Border>
</Border>
<Border
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
IsVisible="{Binding DialogService.LastMessageBox^, Converter={x:Static ObjectConverters.IsNotNull}, FallbackValue=False}">
<Border
Background="{DynamicResource ContainerBackgroundBrush}"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Padding="20">
<Grid RowDefinitions="Auto,Auto">
<TextBlock Text="{Binding DialogService.LastMessageBox^.Text}"/>
<StackPanel
Grid.Row="1"
Orientation="Horizontal"
Margin="0,10,0,0">
<Button
HorizontalContentAlignment="Center"
Width="80"
Command="{Binding DialogService.LastMessageBox^.OkCommand}"
Content="Yes" />
<Button
HorizontalContentAlignment="Center"
Width="80"
Margin="10,0,0,0"
Command="{Binding DialogService.LastMessageBox^.CancelCommand}"
Content="No" />
</StackPanel>
</Grid>
</Border>
</Border>
</Grid>
<Grid IsVisible="{Binding Loading}">

View File

@@ -16,7 +16,7 @@ public partial class MainWindow : Window
{
private readonly ILogger<MainWindow>? _logger;
private readonly IModalService _modalService;
private IReadOnlyCollection<IModalViewModelBase>? _openModals;
private IReadOnlyCollection<IModalViewModel>? _openModals;
public MainWindowViewModel? ViewModel
{