Move common things to AppCore from GuiApp 3
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
public class GeneralKeyEventArgs
|
||||
{
|
||||
private readonly Action<bool> _handledChanged;
|
||||
private readonly Action<bool>? _handledChanged;
|
||||
private bool _handled;
|
||||
public required Keys Key { get; init; }
|
||||
|
||||
@@ -14,12 +14,12 @@ public class GeneralKeyEventArgs
|
||||
if (_handled != value)
|
||||
{
|
||||
_handled = value;
|
||||
_handledChanged(value);
|
||||
_handledChanged?.Invoke(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public GeneralKeyEventArgs(Action<bool> handledChanged)
|
||||
public GeneralKeyEventArgs(Action<bool>? handledChanged = null)
|
||||
{
|
||||
_handledChanged = handledChanged;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace FileTime.App.Core.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace FileTime.App.Core.Models;
|
||||
|
||||
public enum Keys
|
||||
{
|
||||
@@ -46,7 +48,7 @@ public enum Keys
|
||||
Right,
|
||||
Enter,
|
||||
Escape,
|
||||
Back,
|
||||
Backspace,
|
||||
Space,
|
||||
PageUp,
|
||||
PageDown,
|
||||
@@ -55,14 +57,24 @@ public enum Keys
|
||||
Tab,
|
||||
LWin,
|
||||
RWin,
|
||||
[Description("0")]
|
||||
Num0,
|
||||
[Description("1")]
|
||||
Num1,
|
||||
[Description("2")]
|
||||
Num2,
|
||||
[Description("3")]
|
||||
Num3,
|
||||
[Description("4")]
|
||||
Num4,
|
||||
[Description("5")]
|
||||
Num5,
|
||||
[Description("6")]
|
||||
Num6,
|
||||
[Description("7")]
|
||||
Num7,
|
||||
[Description("8")]
|
||||
Num8,
|
||||
[Description("9")]
|
||||
Num9,
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
namespace FileTime.App.Core.Models;
|
||||
|
||||
public record SpecialKeysStatus(bool IsAltPressed, bool IsShiftPressed, bool IsCtrlPressed);
|
||||
public record struct SpecialKeysStatus(bool IsAltPressed, bool IsShiftPressed, bool IsCtrlPressed);
|
||||
@@ -4,5 +4,5 @@ namespace FileTime.App.Core.Services;
|
||||
|
||||
public interface IKeyInputHandler
|
||||
{
|
||||
Task HandleInputKey(Keys key, SpecialKeysStatus specialKeysStatus, Action<bool> setHandled);
|
||||
Task HandleInputKey(GeneralKeyEventArgs e, SpecialKeysStatus specialKeysStatus);
|
||||
}
|
||||
@@ -11,6 +11,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.0" />
|
||||
<PackageReference Include="morelinq" Version="3.4.2" />
|
||||
|
||||
@@ -54,15 +54,15 @@ public class DefaultModeKeyInputHandler : IDefaultModeKeyInputHandler
|
||||
_keysToSkip.Add(new[] {new KeyConfig(Keys.RWin)});
|
||||
}
|
||||
|
||||
public async Task HandleInputKey(Keys key, SpecialKeysStatus specialKeysStatus, Action<bool> setHandled)
|
||||
public async Task HandleInputKey(GeneralKeyEventArgs args, SpecialKeysStatus specialKeysStatus)
|
||||
{
|
||||
var keyWithModifiers = new KeyConfig(key, shift: specialKeysStatus.IsShiftPressed, alt: specialKeysStatus.IsAltPressed, ctrl: specialKeysStatus.IsCtrlPressed);
|
||||
var keyWithModifiers = new KeyConfig(args.Key, shift: specialKeysStatus.IsShiftPressed, alt: specialKeysStatus.IsAltPressed, ctrl: specialKeysStatus.IsCtrlPressed);
|
||||
_appState.PreviousKeys.Add(keyWithModifiers);
|
||||
|
||||
var selectedCommandBinding = _keyboardConfigurationService.UniversalCommandBindings.FirstOrDefault(c => c.Keys.AreKeysEqual(_appState.PreviousKeys));
|
||||
selectedCommandBinding ??= _keyboardConfigurationService.CommandBindings.FirstOrDefault(c => c.Keys.AreKeysEqual(_appState.PreviousKeys));
|
||||
|
||||
if (key == Keys.Escape)
|
||||
if (args.Key == Keys.Escape)
|
||||
{
|
||||
var doGeneralReset = _appState.PreviousKeys.Count > 1;
|
||||
|
||||
@@ -75,7 +75,7 @@ public class DefaultModeKeyInputHandler : IDefaultModeKeyInputHandler
|
||||
var escapeResult = await escHandler.HandleEsc();
|
||||
if (escapeResult.NavigateTo != null)
|
||||
{
|
||||
setHandled(true);
|
||||
args.Handled = true;
|
||||
_appState.PreviousKeys.Clear();
|
||||
if (_appState.SelectedTab.Value?.Tab is { } selectedTab)
|
||||
{
|
||||
@@ -97,7 +97,7 @@ public class DefaultModeKeyInputHandler : IDefaultModeKeyInputHandler
|
||||
|
||||
if (doGeneralReset)
|
||||
{
|
||||
setHandled(true);
|
||||
args.Handled = true;
|
||||
_appState.PreviousKeys.Clear();
|
||||
_appState.PossibleCommands = new();
|
||||
}
|
||||
@@ -107,11 +107,11 @@ public class DefaultModeKeyInputHandler : IDefaultModeKeyInputHandler
|
||||
{
|
||||
_appState.PreviousKeys.Clear();
|
||||
//_dialogService.ProcessMessageBox();
|
||||
setHandled(true);
|
||||
args.Handled = true;
|
||||
}*/
|
||||
else if (selectedCommandBinding != null)
|
||||
{
|
||||
setHandled(true);
|
||||
args.Handled = true;
|
||||
_appState.PreviousKeys.Clear();
|
||||
_appState.PossibleCommands = new();
|
||||
var command = _identifiableUserCommandService.GetCommand(selectedCommandBinding.Command);
|
||||
@@ -128,14 +128,14 @@ public class DefaultModeKeyInputHandler : IDefaultModeKeyInputHandler
|
||||
}
|
||||
else if (_appState.PreviousKeys.Count == 2)
|
||||
{
|
||||
setHandled(true);
|
||||
args.Handled = true;
|
||||
_appState.NoCommandFound = true;
|
||||
_appState.PreviousKeys.Clear();
|
||||
_appState.PossibleCommands = new();
|
||||
}
|
||||
else
|
||||
{
|
||||
setHandled(true);
|
||||
args.Handled = true;
|
||||
var possibleCommands = _keyboardConfigurationService.AllShortcut.Where(c => c.Keys[0].AreEquals(keyWithModifiers)).ToList();
|
||||
|
||||
if (possibleCommands.Count == 0)
|
||||
|
||||
@@ -5,6 +5,7 @@ using FileTime.App.Core.UserCommand;
|
||||
using FileTime.App.Core.ViewModels;
|
||||
using FileTime.Core.Extensions;
|
||||
using FileTime.Core.Models;
|
||||
using Humanizer;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace FileTime.App.Core.Services;
|
||||
@@ -53,13 +54,13 @@ public class RapidTravelModeKeyInputHandler : IRapidTravelModeKeyInputHandler
|
||||
});
|
||||
}
|
||||
|
||||
public async Task HandleInputKey(Keys key, SpecialKeysStatus specialKeysStatus, Action<bool> setHandled)
|
||||
public async Task HandleInputKey(GeneralKeyEventArgs args, SpecialKeysStatus specialKeysStatus)
|
||||
{
|
||||
var keyString = key.ToString();
|
||||
var keyString = args.Key.Humanize();
|
||||
|
||||
if (key == Keys.Escape)
|
||||
if (args.Key == Keys.Escape)
|
||||
{
|
||||
setHandled(true);
|
||||
args.Handled = true;
|
||||
if ((_openModals.Collection?.Count ?? 0) > 0)
|
||||
{
|
||||
_modalService.CloseModal(_openModals.Collection!.Last());
|
||||
@@ -69,11 +70,11 @@ public class RapidTravelModeKeyInputHandler : IRapidTravelModeKeyInputHandler
|
||||
await CallCommandAsync(ExitRapidTravelCommand.Instance);
|
||||
}
|
||||
}
|
||||
else if (key == Keys.Back)
|
||||
else if (args.Key == Keys.Backspace)
|
||||
{
|
||||
if (_appState.RapidTravelText.Value!.Length > 0)
|
||||
{
|
||||
setHandled(true);
|
||||
args.Handled = true;
|
||||
await _appState.RapidTravelText.SetValue(
|
||||
_appState.RapidTravelText.Value![..^1]
|
||||
);
|
||||
@@ -81,18 +82,18 @@ public class RapidTravelModeKeyInputHandler : IRapidTravelModeKeyInputHandler
|
||||
}
|
||||
else if (keyString.Length == 1)
|
||||
{
|
||||
setHandled(true);
|
||||
args.Handled = true;
|
||||
await _appState.RapidTravelText.SetValue(
|
||||
_appState.RapidTravelText.Value + keyString.ToLower()
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
var currentKeyAsList = new List<KeyConfig> {new(key)};
|
||||
var currentKeyAsList = new List<KeyConfig> {new(args.Key)};
|
||||
var selectedCommandBinding = _keyboardConfigurationService.UniversalCommandBindings.FirstOrDefault(c => c.Keys.AreKeysEqual(currentKeyAsList));
|
||||
if (selectedCommandBinding != null)
|
||||
{
|
||||
setHandled(true);
|
||||
args.Handled = true;
|
||||
await CallCommandAsync(_identifiableUserCommandService.GetCommand(selectedCommandBinding.Command));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,9 @@ public static class Startup
|
||||
serviceCollection.TryAddSingleton<IItemPreviewProvider, ElementPreviewProvider>();
|
||||
serviceCollection.TryAddSingleton<ILifecycleService, LifecycleService>();
|
||||
serviceCollection.TryAddSingleton<IModalService, ModalService>();
|
||||
serviceCollection.TryAddSingleton<IDefaultModeKeyInputHandler, DefaultModeKeyInputHandler>();
|
||||
serviceCollection.TryAddSingleton<IRapidTravelModeKeyInputHandler, RapidTravelModeKeyInputHandler>();
|
||||
serviceCollection.TryAddSingleton<IKeyboardConfigurationService, KeyboardConfigurationService>();
|
||||
|
||||
return serviceCollection
|
||||
.AddCommandHandlers()
|
||||
|
||||
@@ -19,16 +19,16 @@ public abstract partial class AppStateBase : IAppState
|
||||
private readonly DeclarativeProperty<ViewMode> _viewMode = new(Models.Enums.ViewMode.Default);
|
||||
private readonly ObservableCollection<ITabViewModel> _tabs = new();
|
||||
|
||||
public IDeclarativeProperty<ViewMode> ViewMode { get; private set; }
|
||||
public IDeclarativeProperty<ViewMode> ViewMode { get; }
|
||||
|
||||
public ReadOnlyObservableCollection<ITabViewModel> Tabs { get; private set; }
|
||||
public IObservable<string?> SearchText { get; private set; }
|
||||
public ReadOnlyObservableCollection<ITabViewModel> Tabs { get; }
|
||||
public IObservable<string?> SearchText { get; }
|
||||
|
||||
public IDeclarativeProperty<ITabViewModel?> SelectedTab { get; private set; }
|
||||
public DeclarativeProperty<string?> RapidTravelText { get; private set; }
|
||||
public IDeclarativeProperty<string?> RapidTravelTextDebounced { get; private set; }
|
||||
public IDeclarativeProperty<ITabViewModel?> SelectedTab { get; }
|
||||
public DeclarativeProperty<string?> RapidTravelText { get; }
|
||||
public IDeclarativeProperty<string?> RapidTravelTextDebounced { get; }
|
||||
|
||||
public IDeclarativeProperty<string?> ContainerStatus { get; private set; }
|
||||
public IDeclarativeProperty<string?> ContainerStatus { get; }
|
||||
[Notify] public List<KeyConfig> PreviousKeys { get; } = new();
|
||||
[Notify] public List<CommandBindingConfiguration> PossibleCommands { get; set; } = new();
|
||||
[Notify] public bool NoCommandFound { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user