From 18cb7690018f79fd06e93b9150cc367e6a7621c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81d=C3=A1m=20Kov=C3=A1cs?= Date: Wed, 15 Feb 2023 21:38:05 +0100 Subject: [PATCH] Keyboard panel handling WIP --- .../Models/GuiPanel.cs | 9 ++++ .../ViewModels/IGuiAppState.cs | 8 +++- .../ViewModels/GuiAppState.cs | 20 ++++++++- .../Services/KeyInputHandlerService.cs | 41 ++++++++++++++++--- 4 files changed, 69 insertions(+), 9 deletions(-) create mode 100644 src/GuiApp/Avalonia/FileTime.GuiApp.Abstractions/Models/GuiPanel.cs diff --git a/src/GuiApp/Avalonia/FileTime.GuiApp.Abstractions/Models/GuiPanel.cs b/src/GuiApp/Avalonia/FileTime.GuiApp.Abstractions/Models/GuiPanel.cs new file mode 100644 index 0000000..04e5bc0 --- /dev/null +++ b/src/GuiApp/Avalonia/FileTime.GuiApp.Abstractions/Models/GuiPanel.cs @@ -0,0 +1,9 @@ +namespace FileTime.GuiApp.Models; + +public enum GuiPanel +{ + FileBrowser, + Timeline, + Drives, + Favorites, +} diff --git a/src/GuiApp/Avalonia/FileTime.GuiApp.Abstractions/ViewModels/IGuiAppState.cs b/src/GuiApp/Avalonia/FileTime.GuiApp.Abstractions/ViewModels/IGuiAppState.cs index 7643ea5..7a644c6 100644 --- a/src/GuiApp/Avalonia/FileTime.GuiApp.Abstractions/ViewModels/IGuiAppState.cs +++ b/src/GuiApp/Avalonia/FileTime.GuiApp.Abstractions/ViewModels/IGuiAppState.cs @@ -3,6 +3,7 @@ using FileTime.App.Core.Models; using FileTime.App.Core.ViewModels; using FileTime.Core.Models; using FileTime.GuiApp.Configuration; +using FileTime.GuiApp.Models; namespace FileTime.GuiApp.ViewModels; @@ -14,5 +15,8 @@ public interface IGuiAppState : IAppState List PossibleCommands { get; set; } BindedCollection RootDriveInfos { get; set; } IReadOnlyList Places { get; set; } - ObservableCollection PopupTexts { get; } -} \ No newline at end of file + ObservableCollection PopupTexts { get; } + IObservable ActivePanel { get; } + + void SetActivePanel(GuiPanel newPanel); +} diff --git a/src/GuiApp/Avalonia/FileTime.GuiApp.CustomImpl/ViewModels/GuiAppState.cs b/src/GuiApp/Avalonia/FileTime.GuiApp.CustomImpl/ViewModels/GuiAppState.cs index 0263a66..09c3df2 100644 --- a/src/GuiApp/Avalonia/FileTime.GuiApp.CustomImpl/ViewModels/GuiAppState.cs +++ b/src/GuiApp/Avalonia/FileTime.GuiApp.CustomImpl/ViewModels/GuiAppState.cs @@ -1,18 +1,24 @@ using System.Collections.ObjectModel; +using System.Reactive.Linq; +using System.Reactive.Subjects; using FileTime.App.Core.ViewModels; using FileTime.App.Core.ViewModels.Timeline; using FileTime.Core.Models; using FileTime.GuiApp.Configuration; +using FileTime.GuiApp.Models; using FileTime.GuiApp.ViewModels; using MvvmGen; namespace FileTime.GuiApp.CustomImpl.ViewModels; [ViewModel(GenerateConstructor = false)] -public partial class GuiAppState : AppStateBase, IGuiAppState +public partial class GuiAppState : AppStateBase, IGuiAppState, IDisposable { + private readonly BehaviorSubject _activePanel = new(GuiPanel.FileBrowser); + public GuiAppState(ITimelineViewModel timelineViewModel) : base(timelineViewModel) { + ActivePanel = _activePanel.AsObservable(); } [Property] private bool _isAllShortcutVisible; @@ -27,4 +33,14 @@ public partial class GuiAppState : AppStateBase, IGuiAppState public List PreviousKeys { get; } = new(); public ObservableCollection PopupTexts { get; } = new(); -} \ No newline at end of file + + public IObservable ActivePanel { get; } + + public void SetActivePanel(GuiPanel newPanel) + => _activePanel.OnNext(newPanel); + + public void Dispose() + { + _activePanel.Dispose(); + } +} diff --git a/src/GuiApp/Avalonia/FileTime.GuiApp/Services/KeyInputHandlerService.cs b/src/GuiApp/Avalonia/FileTime.GuiApp/Services/KeyInputHandlerService.cs index dcb4a8d..95f1d96 100644 --- a/src/GuiApp/Avalonia/FileTime.GuiApp/Services/KeyInputHandlerService.cs +++ b/src/GuiApp/Avalonia/FileTime.GuiApp/Services/KeyInputHandlerService.cs @@ -11,6 +11,12 @@ public class KeyInputHandlerService : IKeyInputHandlerService private readonly IDefaultModeKeyInputHandler _defaultModeKeyInputHandler; private readonly IRapidTravelModeKeyInputHandler _rapidTravelModeKeyInputHandler; private ViewMode _viewMode; + private GuiPanel _activePanel; + private readonly Dictionary<(GuiPanel, Key), GuiPanel> _panelMovements = new() + { + [(GuiPanel.FileBrowser, Key.Up)] = GuiPanel.Timeline, + [(GuiPanel.Timeline, Key.Down)] = GuiPanel.FileBrowser, + }; public KeyInputHandlerService( IGuiAppState appState, @@ -23,6 +29,7 @@ public class KeyInputHandlerService : IKeyInputHandlerService _rapidTravelModeKeyInputHandler = rapidTravelModeKeyInputHandler; appState.ViewMode.Subscribe(v => _viewMode = v); + appState.ActivePanel.Subscribe(p => _activePanel = p); } public async Task ProcessKeyDown(Key key, KeyModifiers keyModifiers, Action setHandled) @@ -43,15 +50,39 @@ public class KeyInputHandlerService : IKeyInputHandlerService var isShiftPressed = (keyModifiers & KeyModifiers.Shift) == KeyModifiers.Shift; var isCtrlPressed = (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)) + { + _appState.SetActivePanel(newPanel); + setHandled(true); + return; + } + var specialKeyStatus = new SpecialKeysStatus(isAltPressed, isShiftPressed, isCtrlPressed); - if (_viewMode == ViewMode.Default) + if (_activePanel == GuiPanel.FileBrowser) { - await _defaultModeKeyInputHandler.HandleInputKey(key, specialKeyStatus, setHandled); + if (_viewMode == ViewMode.Default) + { + await _defaultModeKeyInputHandler.HandleInputKey(key, specialKeyStatus, setHandled); + } + else + { + await _rapidTravelModeKeyInputHandler.HandleInputKey(key, specialKeyStatus, setHandled); + } } - else + else if (_activePanel == GuiPanel.Timeline) { - await _rapidTravelModeKeyInputHandler.HandleInputKey(key, specialKeyStatus, setHandled); + // await HandleTimelineKey(key, specialKeyStatus, setHandled); + } + else if (_activePanel == GuiPanel.Drives) + { + // await HandleDrivesKey(key, specialKeyStatus, setHandled); + } + else if (_activePanel == GuiPanel.Favorites) + { + // await HandleFavoritesKey(key, specialKeyStatus, setHandled); } } -} \ No newline at end of file +}