WIP: RapidTravel, ModalService

This commit is contained in:
2022-05-10 21:36:39 +02:00
parent 5b9d0667cc
commit 0ac9209676
19 changed files with 247 additions and 88 deletions

View File

@@ -1,29 +1,62 @@
using Avalonia.Input;
using FileTime.App.Core.Command;
using FileTime.App.Core.Models;
using FileTime.App.Core.Models.Enums;
using FileTime.App.Core.Services;
using FileTime.App.Core.ViewModels;
using FileTime.Core.Models;
using FileTime.Core.Services;
using FileTime.GuiApp.Configuration;
using FileTime.GuiApp.Extensions;
using FileTime.GuiApp.Models;
using Microsoft.Extensions.Logging;
namespace FileTime.GuiApp.Services;
public class RapidTravelModeKeyInputHandler : IRapidTravelModeKeyInputHandler
{
private const string RAPIDTRAVELFILTERNAME = "rapid_travel_filter";
private readonly IAppState _appState;
private readonly IModalService _modalService;
private readonly IKeyboardConfigurationService _keyboardConfigurationService;
private readonly ICommandHandlerService _commandHandlerService;
private readonly ILogger<RapidTravelModeKeyInputHandler> _logger;
private readonly BindedCollection<IModalViewModelBase> _openModals;
private ITabViewModel? _selectedTab;
public RapidTravelModeKeyInputHandler(
IAppState appState,
IModalService modalService,
IKeyboardConfigurationService keyboardConfigurationService,
ICommandHandlerService commandHandlerService,
ILogger<RapidTravelModeKeyInputHandler> logger)
{
_appState = appState;
_modalService = modalService;
_keyboardConfigurationService = keyboardConfigurationService;
_commandHandlerService = commandHandlerService;
_logger = logger;
_appState.SelectedTab.Subscribe(t => _selectedTab = t);
_openModals = new BindedCollection<IModalViewModelBase>(modalService.OpenModals);
}
public async Task HandleInputKey(Key key, SpecialKeysStatus specialKeysStatus, Action<bool> setHandled)
{
/*var keyString = key.ToString();
var keyString = key.ToString();
var updateRapidTravelFilter = false;
if (key == Key.Escape)
{
setHandled(true);
if (_appState.IsAllShortcutVisible)
if ((_openModals.Collection?.Count ?? 0) > 0)
{
_appState.IsAllShortcutVisible = false;
}
else if (_appState.MessageBoxText != null)
{
_appState.MessageBoxText = null;
_modalService.CloseModal(_openModals.Collection!.Last());
}
else
{
await _appState.ExitRapidTravelMode();
_appState.SwitchViewMode(ViewMode.Default);
}
}
else if (key == Key.Back)
@@ -43,8 +76,8 @@ public class RapidTravelModeKeyInputHandler : IRapidTravelModeKeyInputHandler
}
else
{
var currentKeyAsList = new List<KeyConfig>() { new KeyConfig(key) };
var selectedCommandBinding = _keyboardConfigurationService.UniversalCommandBindings.FirstOrDefault(c => AreKeysEqual(c.Keys, currentKeyAsList));
var currentKeyAsList = new List<KeyConfig>() {new KeyConfig(key)};
var selectedCommandBinding = _keyboardConfigurationService.UniversalCommandBindings.FirstOrDefault(c => c.Keys.AreKeysEqual(currentKeyAsList));
if (selectedCommandBinding != null)
{
setHandled(true);
@@ -54,16 +87,20 @@ public class RapidTravelModeKeyInputHandler : IRapidTravelModeKeyInputHandler
if (updateRapidTravelFilter)
{
var currentLocation = await _appState.SelectedTab.CurrentLocation.Container.WithoutVirtualContainer(MainPageViewModel.RAPIDTRAVEL);
if (_selectedTab?.Tab is not ITab tab) return;
tab.RemoveItemFilter(RAPIDTRAVELFILTERNAME);
tab.AddItemFilter(new ItemFilter(RAPIDTRAVELFILTERNAME, i => i.Name.ToLower().Contains(_appState.RapidTravelText)));
/*var currentLocation = await _appState.SelectedTab.CurrentLocation.Container.WithoutVirtualContainer(MainPageViewModel.RAPIDTRAVEL);
var newLocation = new VirtualContainer(
currentLocation,
new List<Func<IEnumerable<IContainer>, IEnumerable<IContainer>>>()
{
container => container.Where(c => c.Name.ToLower().Contains(_appState.RapidTravelText))
container => container.Where(c => c.Name.ToLower().Contains(_appState.RapidTravelText))
},
new List<Func<IEnumerable<IElement>, IEnumerable<IElement>>>()
{
element => element.Where(e => e.Name.ToLower().Contains(_appState.RapidTravelText))
element => element.Where(e => e.Name.ToLower().Contains(_appState.RapidTravelText))
},
virtualContainerName: MainPageViewModel.RAPIDTRAVEL
);
@@ -81,7 +118,19 @@ public class RapidTravelModeKeyInputHandler : IRapidTravelModeKeyInputHandler
else if (!currentLocationItems.Select(i => i.Item.Name).Any(n => n == selectedItemName))
{
await _appState.SelectedTab.MoveCursorToFirst();
}
}*/
}*/
}
}
private async Task CallCommandAsync(Commands command)
{
try
{
await _commandHandlerService.HandleCommandAsync(command);
}
catch (Exception e)
{
_logger.LogError(e, "Unknown error while running command. {Command} {Error}", command, e);
}
}
}