Move common things to AppCore from GuiApp 3
This commit is contained in:
@@ -4,5 +4,5 @@ namespace FileTime.GuiApp.App.Services;
|
||||
|
||||
public interface IKeyInputHandlerService
|
||||
{
|
||||
Task ProcessKeyDown(Key key, KeyModifiers keyModifiers, Action<bool> setHandled);
|
||||
Task ProcessKeyDown(KeyEventArgs e);
|
||||
}
|
||||
@@ -5,7 +5,7 @@ using FileTime.App.Core.Services;
|
||||
|
||||
namespace FileTime.GuiApp.App.Services;
|
||||
|
||||
public class GuiAppKeyService : IAppKeyService<Key>
|
||||
public sealed class GuiAppKeyService : IAppKeyService<Key>
|
||||
{
|
||||
private static readonly Dictionary<Key, Keys> KeyMapping;
|
||||
|
||||
@@ -70,7 +70,7 @@ public class GuiAppKeyService : IAppKeyService<Key>
|
||||
{Key.Right, Keys.Right},
|
||||
{Key.Enter, Keys.Enter},
|
||||
{Key.Escape, Keys.Escape},
|
||||
{Key.Back, Keys.Back},
|
||||
{Key.Back, Keys.Backspace},
|
||||
{Key.Space, Keys.Space},
|
||||
{Key.PageUp, Keys.PageUp},
|
||||
{Key.PageDown, Keys.PageDown},
|
||||
|
||||
@@ -2,6 +2,7 @@ using Avalonia.Input;
|
||||
using FileTime.App.Core.Models;
|
||||
using FileTime.App.Core.Models.Enums;
|
||||
using FileTime.App.Core.Services;
|
||||
using FileTime.GuiApp.App.Extensions;
|
||||
using FileTime.GuiApp.App.Models;
|
||||
using FileTime.GuiApp.App.ViewModels;
|
||||
|
||||
@@ -13,7 +14,6 @@ public class KeyInputHandlerService : IKeyInputHandlerService
|
||||
private readonly IDefaultModeKeyInputHandler _defaultModeKeyInputHandler;
|
||||
private readonly IRapidTravelModeKeyInputHandler _rapidTravelModeKeyInputHandler;
|
||||
private readonly IAppKeyService<Key> _appKeyService;
|
||||
private ViewMode _viewMode;
|
||||
private GuiPanel _activePanel;
|
||||
|
||||
private readonly Dictionary<(GuiPanel, Key), GuiPanel> _panelMovements = new()
|
||||
@@ -33,13 +33,12 @@ public class KeyInputHandlerService : IKeyInputHandlerService
|
||||
_rapidTravelModeKeyInputHandler = rapidTravelModeKeyInputHandler;
|
||||
_appKeyService = appKeyService;
|
||||
|
||||
appState.ViewMode.Subscribe(v => _viewMode = v);
|
||||
appState.ActivePanel.Subscribe(p => _activePanel = p);
|
||||
}
|
||||
|
||||
public async Task ProcessKeyDown(Key key, KeyModifiers keyModifiers, Action<bool> setHandled)
|
||||
public async Task ProcessKeyDown(KeyEventArgs e)
|
||||
{
|
||||
if (key is Key.LeftAlt
|
||||
if (e.Key is Key.LeftAlt
|
||||
or Key.RightAlt
|
||||
or Key.LeftShift
|
||||
or Key.RightShift
|
||||
@@ -51,16 +50,16 @@ public class KeyInputHandlerService : IKeyInputHandlerService
|
||||
|
||||
//_appState.NoCommandFound = false;
|
||||
|
||||
var isAltPressed = (keyModifiers & KeyModifiers.Alt) == KeyModifiers.Alt;
|
||||
var isShiftPressed = (keyModifiers & KeyModifiers.Shift) == KeyModifiers.Shift;
|
||||
var isCtrlPressed = (keyModifiers & KeyModifiers.Control) == KeyModifiers.Control;
|
||||
var isAltPressed = (e.KeyModifiers & KeyModifiers.Alt) == KeyModifiers.Alt;
|
||||
var isShiftPressed = (e.KeyModifiers & KeyModifiers.Shift) == KeyModifiers.Shift;
|
||||
var isCtrlPressed = (e.KeyModifiers & KeyModifiers.Control) == KeyModifiers.Control;
|
||||
|
||||
if (isCtrlPressed
|
||||
&& key is Key.Left or Key.Right or Key.Up or Key.Down
|
||||
&& _panelMovements.TryGetValue((_activePanel, key), out var newPanel))
|
||||
&& e.Key is Key.Left or Key.Right or Key.Up or Key.Down
|
||||
&& _panelMovements.TryGetValue((_activePanel, e.Key), out var newPanel))
|
||||
{
|
||||
_appState.SetActivePanel(newPanel);
|
||||
setHandled(true);
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -68,18 +67,18 @@ public class KeyInputHandlerService : IKeyInputHandlerService
|
||||
|
||||
if (_activePanel == GuiPanel.FileBrowser)
|
||||
{
|
||||
if (_viewMode == ViewMode.Default)
|
||||
if (_appState.ViewMode.Value == ViewMode.Default)
|
||||
{
|
||||
if (_appKeyService.MapKey(key) is { } mappedKey)
|
||||
if (e.ToGeneralKeyEventArgs(_appKeyService) is { } args)
|
||||
{
|
||||
await _defaultModeKeyInputHandler.HandleInputKey(mappedKey, specialKeyStatus, setHandled);
|
||||
await _defaultModeKeyInputHandler.HandleInputKey(args, specialKeyStatus);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_appKeyService.MapKey(key) is { } mappedKey)
|
||||
if (e.ToGeneralKeyEventArgs(_appKeyService) is { } args)
|
||||
{
|
||||
await _rapidTravelModeKeyInputHandler.HandleInputKey(mappedKey, specialKeyStatus, setHandled);
|
||||
await _rapidTravelModeKeyInputHandler.HandleInputKey(args, specialKeyStatus);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,8 +73,8 @@ public partial class MainWindowViewModel : IMainWindowViewModel
|
||||
Task.Run(async () => await _lifecycleService.InitStartupHandlersAsync()).Wait();
|
||||
}
|
||||
|
||||
public void ProcessKeyDown(Key key, KeyModifiers keyModifiers, Action<bool> setHandled)
|
||||
=> _keyInputHandlerService.ProcessKeyDown(key, keyModifiers, setHandled);
|
||||
public void ProcessKeyDown(KeyEventArgs e)
|
||||
=> _keyInputHandlerService.ProcessKeyDown(e);
|
||||
|
||||
public async Task OpenContainerByFullName(FullName fullName)
|
||||
{
|
||||
|
||||
@@ -100,7 +100,7 @@ public partial class MainWindow : Window, IUiAccessor
|
||||
private void OnKeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if ((_openModals?.Count ?? 0) > 0) return;
|
||||
ViewModel?.ProcessKeyDown(e.Key, e.KeyModifiers, h => e.Handled = h);
|
||||
ViewModel?.ProcessKeyDown(e);
|
||||
}
|
||||
|
||||
private void HeaderPointerPressed(object sender, PointerPressedEventArgs e)
|
||||
|
||||
@@ -21,10 +21,6 @@ public partial class GuiAppState : AppStateBase, IGuiAppState, IDisposable
|
||||
ActivePanel = _activePanel.AsObservable();
|
||||
}
|
||||
|
||||
[Notify] private bool _noCommandFound;
|
||||
|
||||
[Notify] private List<CommandBindingConfiguration> _possibleCommands = new();
|
||||
|
||||
[Notify] private ObservableCollection<RootDriveInfo> _rootDriveInfos = new();
|
||||
|
||||
[Notify] private IReadOnlyList<PlaceInfo> _places = new List<PlaceInfo>();
|
||||
@@ -35,8 +31,5 @@ public partial class GuiAppState : AppStateBase, IGuiAppState, IDisposable
|
||||
public void SetActivePanel(GuiPanel newPanel)
|
||||
=> _activePanel.OnNext(newPanel);
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_activePanel.Dispose();
|
||||
}
|
||||
public void Dispose() => _activePanel.Dispose();
|
||||
}
|
||||
|
||||
@@ -53,9 +53,6 @@ public static class Startup
|
||||
{
|
||||
serviceCollection.TryAddSingleton<IRxSchedulerService, AvaloniaRxSchedulerService>();
|
||||
serviceCollection.TryAddSingleton<IKeyInputHandlerService, KeyInputHandlerService>();
|
||||
serviceCollection.TryAddSingleton<IDefaultModeKeyInputHandler, DefaultModeKeyInputHandler>();
|
||||
serviceCollection.TryAddSingleton<IKeyboardConfigurationService, KeyboardConfigurationService>();
|
||||
serviceCollection.TryAddSingleton<IRapidTravelModeKeyInputHandler, RapidTravelModeKeyInputHandler>();
|
||||
serviceCollection.TryAddSingleton<IIconProvider, MaterialIconProvider>();
|
||||
serviceCollection.TryAddSingleton<IDialogService, DialogService>();
|
||||
serviceCollection.TryAddSingleton<SystemClipboardService>();
|
||||
|
||||
Reference in New Issue
Block a user