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)