Rapid travel filter + ESC improvements

This commit is contained in:
2024-02-27 21:17:12 +01:00
parent 9ee819cee3
commit 4302b23ceb
7 changed files with 22 additions and 8 deletions

View File

@@ -79,6 +79,10 @@ public class DefaultModeKeyInputHandler : IDefaultModeKeyInputHandler
{ {
_modalService.CloseModal(_openModals.Last()); _modalService.CloseModal(_openModals.Last());
} }
else if (_appState.RapidTravelText.Value != "")
{
await _appState.SetRapidTravelTextAsync("");
}
else if (_currentLocation.Value?.GetExtension<EscHandlerContainerExtension>() is { } escHandler) else if (_currentLocation.Value?.GetExtension<EscHandlerContainerExtension>() is { } escHandler)
{ {
var escapeResult = await escHandler.HandleEsc(); var escapeResult = await escHandler.HandleEsc();

View File

@@ -5,6 +5,7 @@ using DeclarativeProperty;
using FileTime.App.Core.Configuration; using FileTime.App.Core.Configuration;
using FileTime.App.Core.Models.Enums; using FileTime.App.Core.Models.Enums;
using FileTime.Core.Models.Extensions; using FileTime.Core.Models.Extensions;
using FileTime.Core.Services;
using MoreLinq; using MoreLinq;
using PropertyChanged.SourceGenerator; using PropertyChanged.SourceGenerator;
@@ -31,7 +32,7 @@ public abstract partial class AppStateBase : IAppState
[Notify] public List<KeyConfig> PreviousKeys { get; } = new(); [Notify] public List<KeyConfig> PreviousKeys { get; } = new();
[Notify] public bool NoCommandFound { get; set; } [Notify] public bool NoCommandFound { get; set; }
protected AppStateBase() protected AppStateBase(ITabEvents tabEvents)
{ {
_rapidTravelText = new(""); _rapidTravelText = new("");
RapidTravelText = _rapidTravelText.DistinctUntilChanged(); RapidTravelText = _rapidTravelText.DistinctUntilChanged();
@@ -59,6 +60,8 @@ public abstract partial class AppStateBase : IAppState
.Switch() .Switch()
.Map(c => c?.GetExtension<StatusProviderContainerExtension>()?.GetStatusProperty()) .Map(c => c?.GetExtension<StatusProviderContainerExtension>()?.GetStatusProperty())
.Switch()!; .Switch()!;
tabEvents.LocationChanged += (_, _) => Task.Run(async () => await SetRapidTravelTextAsync("")).Wait();
} }
public void AddTab(ITabViewModel tabViewModel) public void AddTab(ITabViewModel tabViewModel)
@@ -79,11 +82,8 @@ public abstract partial class AppStateBase : IAppState
public void SetSearchText(string? searchText) => _searchText.OnNext(searchText); public void SetSearchText(string? searchText) => _searchText.OnNext(searchText);
public async Task SwitchViewModeAsync(ViewMode newViewMode) public Task SwitchViewModeAsync(ViewMode newViewMode)
{ => _viewMode.SetValue(newViewMode);
if (newViewMode != Models.Enums.ViewMode.RapidTravel) await SetRapidTravelTextAsync(null);
await _viewMode.SetValue(newViewMode);
}
public async Task SetSelectedTabAsync(ITabViewModel tabToSelect) => await _selectedTab.SetValue(tabToSelect); public async Task SetSelectedTabAsync(ITabViewModel tabToSelect) => await _selectedTab.SetValue(tabToSelect);
public async Task SetRapidTravelTextAsync(string? text) => await _rapidTravelText.SetValue(text); public async Task SetRapidTravelTextAsync(string? text) => await _rapidTravelText.SetValue(text);

View File

@@ -5,4 +5,5 @@ namespace FileTime.GuiApp.App.Services;
public interface IKeyInputHandlerService public interface IKeyInputHandlerService
{ {
Task ProcessKeyDown(KeyEventArgs e); Task ProcessKeyDown(KeyEventArgs e);
event EventHandler? UnhandledEsc;
} }

View File

@@ -16,6 +16,8 @@ public class KeyInputHandlerService : IKeyInputHandlerService
private readonly IAppKeyService<Key> _appKeyService; private readonly IAppKeyService<Key> _appKeyService;
private GuiPanel _activePanel; private GuiPanel _activePanel;
public event EventHandler? UnhandledEsc;
private readonly Dictionary<(GuiPanel, Key), GuiPanel> _panelMovements = new() private readonly Dictionary<(GuiPanel, Key), GuiPanel> _panelMovements = new()
{ {
[(GuiPanel.FileBrowser, Key.Up)] = GuiPanel.Timeline, [(GuiPanel.FileBrowser, Key.Up)] = GuiPanel.Timeline,
@@ -72,6 +74,11 @@ public class KeyInputHandlerService : IKeyInputHandlerService
if (e.ToGeneralKeyEventArgs(_appKeyService, specialKeyStatus) is { } args) if (e.ToGeneralKeyEventArgs(_appKeyService, specialKeyStatus) is { } args)
{ {
await _defaultModeKeyInputHandler.HandleInputKey(args); await _defaultModeKeyInputHandler.HandleInputKey(args);
if (!args.Handled && args.Key == Keys.Escape)
{
UnhandledEsc?.Invoke(this, EventArgs.Empty);
}
} }
} }
else else

View File

@@ -102,6 +102,7 @@ public partial class MainWindowViewModel : IMainWindowViewModel
_modalService.AllModalClosed += (_, _) => FocusDefaultElement?.Invoke(); _modalService.AllModalClosed += (_, _) => FocusDefaultElement?.Invoke();
_instanceMessageHandler.ShowWindow += () => ShowWindow?.Invoke(); _instanceMessageHandler.ShowWindow += () => ShowWindow?.Invoke();
_keyInputHandlerService.UnhandledEsc += (_,_) => FocusDefaultElement?.Invoke();
Task.Run(async () => Task.Run(async () =>
{ {

View File

@@ -74,7 +74,7 @@ public partial class MainWindow : Window, IUiAccessor
try try
{ {
var viewModel = DI.ServiceProvider.GetRequiredService<MainWindowViewModel>(); var viewModel = DI.ServiceProvider.GetRequiredService<MainWindowViewModel>();
viewModel.FocusDefaultElement = () => Focus(); viewModel.FocusDefaultElement = () => Dispatcher.UIThread.Invoke(() => Focus());
viewModel.ShowWindow = Activate; viewModel.ShowWindow = Activate;
ViewModel = viewModel; ViewModel = viewModel;
} }

View File

@@ -2,6 +2,7 @@ using System.Collections.ObjectModel;
using System.Reactive.Linq; using System.Reactive.Linq;
using System.Reactive.Subjects; using System.Reactive.Subjects;
using FileTime.App.Core.ViewModels; using FileTime.App.Core.ViewModels;
using FileTime.Core.Services;
using FileTime.GuiApp.App.Models; using FileTime.GuiApp.App.Models;
using FileTime.GuiApp.App.ViewModels; using FileTime.GuiApp.App.ViewModels;
using FileTime.Providers.Local; using FileTime.Providers.Local;
@@ -18,7 +19,7 @@ public partial class GuiAppState : AppStateBase, IGuiAppState, IDisposable
public IObservable<GuiPanel> ActivePanel { get; } public IObservable<GuiPanel> ActivePanel { get; }
public GuiAppState() public GuiAppState(ITabEvents tabEvents):base(tabEvents)
{ {
ActivePanel = _activePanel.AsObservable(); ActivePanel = _activePanel.AsObservable();
} }