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

@@ -30,7 +30,8 @@ public static class Startup
.AddSingleton<IKeyInputHandlerService, KeyInputHandlerService>()
.AddSingleton<IDefaultModeKeyInputHandler, DefaultModeKeyInputHandler>()
.AddSingleton<IKeyboardConfigurationService, KeyboardConfigurationService>()
.AddSingleton<IRapidTravelModeKeyInputHandler, RapidTravelModeKeyInputHandler>();
.AddSingleton<IRapidTravelModeKeyInputHandler, RapidTravelModeKeyInputHandler>()
.AddSingleton<IModalService, ModalService>();
}
internal static IServiceCollection RegisterLogging(this IServiceCollection serviceCollection)

View File

@@ -11,6 +11,7 @@ public class KeyInputHandlerService : IKeyInputHandlerService
private readonly IGuiAppState _appState;
private readonly IDefaultModeKeyInputHandler _defaultModeKeyInputHandler;
private readonly IRapidTravelModeKeyInputHandler _rapidTravelModeKeyInputHandler;
private ViewMode _viewMode;
public KeyInputHandlerService(
IGuiAppState appState,
@@ -21,16 +22,18 @@ public class KeyInputHandlerService : IKeyInputHandlerService
_appState = appState;
_defaultModeKeyInputHandler = defaultModeKeyInputHandler;
_rapidTravelModeKeyInputHandler = rapidTravelModeKeyInputHandler;
appState.ViewMode.Subscribe(v => _viewMode = v);
}
public async Task ProcessKeyDown(Key key, KeyModifiers keyModifiers, Action<bool> setHandled)
{
if (key == Key.LeftAlt
|| key == Key.RightAlt
|| key == Key.LeftShift
|| key == Key.RightShift
|| key == Key.LeftCtrl
|| key == Key.RightCtrl)
if (key is Key.LeftAlt
or Key.RightAlt
or Key.LeftShift
or Key.RightShift
or Key.LeftCtrl
or Key.RightCtrl)
{
return;
}
@@ -43,7 +46,7 @@ public class KeyInputHandlerService : IKeyInputHandlerService
var specialKeyStatus = new SpecialKeysStatus(isAltPressed, isShiftPressed, isCtrlPressed);
if (_appState.ViewMode == ViewMode.Default)
if (_viewMode == ViewMode.Default)
{
await _defaultModeKeyInputHandler.HandleInputKey(key, specialKeyStatus, setHandled);
}

View File

@@ -49,12 +49,6 @@ public class KeyboardConfigurationService : IKeyboardConfigurationService
private static bool IsUniversal(CommandBindingConfiguration keyMapping)
{
return keyMapping.Command == Commands.GoUp
|| keyMapping.Command == Commands.Open
|| keyMapping.Command == Commands.OpenOrRun
|| keyMapping.Command == Commands.MoveCursorUp
|| keyMapping.Command == Commands.MoveCursorDown
|| keyMapping.Command == Commands.MoveCursorUpPage
|| keyMapping.Command == Commands.MoveCursorDownPage;
return keyMapping.Command is Commands.GoUp or Commands.Open or Commands.OpenOrRun or Commands.MoveCursorUp or Commands.MoveCursorDown or Commands.MoveCursorUpPage or Commands.MoveCursorDownPage;
}
}

View File

@@ -0,0 +1,20 @@
using DynamicData;
using FileTime.App.Core.Services;
using FileTime.App.Core.ViewModels;
namespace FileTime.GuiApp.Services;
public class ModalService : IModalService
{
private readonly SourceList<IModalViewModelBase> _openModals = new();
public IObservable<IChangeSet<IModalViewModelBase>> OpenModals { get; }
public ModalService()
{
OpenModals = _openModals.Connect();
}
public void OpenModal(IModalViewModelBase modalToOpen) => _openModals.Add(modalToOpen);
public void CloseModal(IModalViewModelBase modalToClose) => _openModals.Remove(modalToClose);
}

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);
}
}
}

View File

@@ -236,6 +236,35 @@
</Grid>
<Grid Grid.Row="3">
<Grid
IsVisible="{Binding AppState.ViewMode^, Converter={StaticResource EqualityConverter},ConverterParameter=RapidTravel}">
<Grid.RowDefinitions>
<RowDefinition Height="1" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Rectangle
Height="1"
Margin="10,0"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
Fill="{DynamicResource ContentSeparatorBrush}" />
<StackPanel
Grid.Row="1"
Margin="30,10,10,10"
Orientation="Horizontal">
<TextBlock
Margin="0,0,30,0"
Text="Rapid travel mode" />
<TextBlock Text="Filter " />
<TextBlock Text="{Binding AppState.RapidTravelText}" />
</StackPanel>
</Grid>
<Grid
IsVisible="{Binding AppState.PossibleCommands.Count, Converter={StaticResource NotEqualsConverter}, ConverterParameter=0}">
<Grid.RowDefinitions>