Keyboard panel handling WIP
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
namespace FileTime.GuiApp.Models;
|
||||
|
||||
public enum GuiPanel
|
||||
{
|
||||
FileBrowser,
|
||||
Timeline,
|
||||
Drives,
|
||||
Favorites,
|
||||
}
|
||||
@@ -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<CommandBindingConfiguration> PossibleCommands { get; set; }
|
||||
BindedCollection<RootDriveInfo, string> RootDriveInfos { get; set; }
|
||||
IReadOnlyList<PlaceInfo> Places { get; set; }
|
||||
ObservableCollection<string> PopupTexts { get; }
|
||||
}
|
||||
ObservableCollection<string> PopupTexts { get; }
|
||||
IObservable<GuiPanel> ActivePanel { get; }
|
||||
|
||||
void SetActivePanel(GuiPanel newPanel);
|
||||
}
|
||||
|
||||
@@ -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<GuiPanel> _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<KeyConfig> PreviousKeys { 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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<bool> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user