Keyboard panel handling WIP

This commit is contained in:
2023-02-15 21:38:05 +01:00
parent 97f5108ba8
commit 18cb769001
4 changed files with 69 additions and 9 deletions

View File

@@ -0,0 +1,9 @@
namespace FileTime.GuiApp.Models;
public enum GuiPanel
{
FileBrowser,
Timeline,
Drives,
Favorites,
}

View File

@@ -3,6 +3,7 @@ using FileTime.App.Core.Models;
using FileTime.App.Core.ViewModels; using FileTime.App.Core.ViewModels;
using FileTime.Core.Models; using FileTime.Core.Models;
using FileTime.GuiApp.Configuration; using FileTime.GuiApp.Configuration;
using FileTime.GuiApp.Models;
namespace FileTime.GuiApp.ViewModels; namespace FileTime.GuiApp.ViewModels;
@@ -15,4 +16,7 @@ public interface IGuiAppState : IAppState
BindedCollection<RootDriveInfo, string> RootDriveInfos { get; set; } BindedCollection<RootDriveInfo, string> RootDriveInfos { get; set; }
IReadOnlyList<PlaceInfo> Places { get; set; } IReadOnlyList<PlaceInfo> Places { get; set; }
ObservableCollection<string> PopupTexts { get; } ObservableCollection<string> PopupTexts { get; }
IObservable<GuiPanel> ActivePanel { get; }
void SetActivePanel(GuiPanel newPanel);
} }

View File

@@ -1,18 +1,24 @@
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using FileTime.App.Core.ViewModels; using FileTime.App.Core.ViewModels;
using FileTime.App.Core.ViewModels.Timeline; using FileTime.App.Core.ViewModels.Timeline;
using FileTime.Core.Models; using FileTime.Core.Models;
using FileTime.GuiApp.Configuration; using FileTime.GuiApp.Configuration;
using FileTime.GuiApp.Models;
using FileTime.GuiApp.ViewModels; using FileTime.GuiApp.ViewModels;
using MvvmGen; using MvvmGen;
namespace FileTime.GuiApp.CustomImpl.ViewModels; namespace FileTime.GuiApp.CustomImpl.ViewModels;
[ViewModel(GenerateConstructor = false)] [ViewModel(GenerateConstructor = false)]
public partial class GuiAppState : AppStateBase, IGuiAppState public partial class GuiAppState : AppStateBase, IGuiAppState, IDisposable
{ {
private readonly BehaviorSubject<GuiPanel> _activePanel = new(GuiPanel.FileBrowser);
public GuiAppState(ITimelineViewModel timelineViewModel) : base(timelineViewModel) public GuiAppState(ITimelineViewModel timelineViewModel) : base(timelineViewModel)
{ {
ActivePanel = _activePanel.AsObservable();
} }
[Property] private bool _isAllShortcutVisible; [Property] private bool _isAllShortcutVisible;
@@ -27,4 +33,14 @@ public partial class GuiAppState : AppStateBase, IGuiAppState
public List<KeyConfig> PreviousKeys { get; } = new(); public List<KeyConfig> PreviousKeys { get; } = new();
public ObservableCollection<string> PopupTexts { get; } = new(); public ObservableCollection<string> PopupTexts { get; } = new();
public IObservable<GuiPanel> ActivePanel { get; }
public void SetActivePanel(GuiPanel newPanel)
=> _activePanel.OnNext(newPanel);
public void Dispose()
{
_activePanel.Dispose();
}
} }

View File

@@ -11,6 +11,12 @@ public class KeyInputHandlerService : IKeyInputHandlerService
private readonly IDefaultModeKeyInputHandler _defaultModeKeyInputHandler; private readonly IDefaultModeKeyInputHandler _defaultModeKeyInputHandler;
private readonly IRapidTravelModeKeyInputHandler _rapidTravelModeKeyInputHandler; private readonly IRapidTravelModeKeyInputHandler _rapidTravelModeKeyInputHandler;
private ViewMode _viewMode; 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( public KeyInputHandlerService(
IGuiAppState appState, IGuiAppState appState,
@@ -23,6 +29,7 @@ public class KeyInputHandlerService : IKeyInputHandlerService
_rapidTravelModeKeyInputHandler = rapidTravelModeKeyInputHandler; _rapidTravelModeKeyInputHandler = rapidTravelModeKeyInputHandler;
appState.ViewMode.Subscribe(v => _viewMode = v); 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(Key key, KeyModifiers keyModifiers, Action<bool> setHandled)
@@ -43,8 +50,19 @@ public class KeyInputHandlerService : IKeyInputHandlerService
var isShiftPressed = (keyModifiers & KeyModifiers.Shift) == KeyModifiers.Shift; var isShiftPressed = (keyModifiers & KeyModifiers.Shift) == KeyModifiers.Shift;
var isCtrlPressed = (keyModifiers & KeyModifiers.Control) == KeyModifiers.Control; 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); var specialKeyStatus = new SpecialKeysStatus(isAltPressed, isShiftPressed, isCtrlPressed);
if (_activePanel == GuiPanel.FileBrowser)
{
if (_viewMode == ViewMode.Default) if (_viewMode == ViewMode.Default)
{ {
await _defaultModeKeyInputHandler.HandleInputKey(key, specialKeyStatus, setHandled); await _defaultModeKeyInputHandler.HandleInputKey(key, specialKeyStatus, setHandled);
@@ -54,4 +72,17 @@ public class KeyInputHandlerService : IKeyInputHandlerService
await _rapidTravelModeKeyInputHandler.HandleInputKey(key, specialKeyStatus, setHandled); await _rapidTravelModeKeyInputHandler.HandleInputKey(key, specialKeyStatus, setHandled);
} }
} }
else if (_activePanel == GuiPanel.Timeline)
{
// 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);
}
}
} }