Command refactor
This commit is contained in:
@@ -1,37 +1,40 @@
|
||||
using Avalonia.Input;
|
||||
using FileTime.App.Core.Command;
|
||||
|
||||
namespace FileTime.GuiApp.Configuration;
|
||||
|
||||
public class CommandBindingConfiguration
|
||||
{
|
||||
public List<KeyConfig> Keys { get; set; } = new List<KeyConfig>();
|
||||
public List<KeyConfig> Keys { get; set; }
|
||||
|
||||
public Command Command { get; set; } = Command.None;
|
||||
public string Command { get; set; }
|
||||
|
||||
public string KeysDisplayText => GetKeysDisplayText();
|
||||
|
||||
public CommandBindingConfiguration() { }
|
||||
public CommandBindingConfiguration()
|
||||
{
|
||||
Command = null!;
|
||||
Keys = null!;
|
||||
}
|
||||
|
||||
public CommandBindingConfiguration(Command command, IEnumerable<KeyConfig> keys)
|
||||
public CommandBindingConfiguration(string command, IEnumerable<KeyConfig> keys)
|
||||
{
|
||||
Keys = new List<KeyConfig>(keys);
|
||||
Command = command;
|
||||
}
|
||||
|
||||
public CommandBindingConfiguration(Command command, KeyConfig key)
|
||||
public CommandBindingConfiguration(string command, KeyConfig key)
|
||||
{
|
||||
Keys = new List<KeyConfig>() { key };
|
||||
Command = command;
|
||||
}
|
||||
|
||||
public CommandBindingConfiguration(Command command, IEnumerable<Key> keys)
|
||||
public CommandBindingConfiguration(string command, IEnumerable<Key> keys)
|
||||
{
|
||||
Keys = keys.Select(k => new KeyConfig(k)).ToList();
|
||||
Command = command;
|
||||
}
|
||||
|
||||
public CommandBindingConfiguration(Command command, Key key)
|
||||
public CommandBindingConfiguration(string command, Key key)
|
||||
{
|
||||
Keys = new List<KeyConfig>() { new KeyConfig(key) };
|
||||
Command = command;
|
||||
@@ -62,7 +65,7 @@ public class CommandBindingConfiguration
|
||||
{
|
||||
var s = "";
|
||||
|
||||
bool ctrlOrAlt = key.Ctrl || key.Alt;
|
||||
var ctrlOrAlt = key.Ctrl || key.Alt;
|
||||
|
||||
if (ctrlOrAlt && currentText.Length > 0 && currentText.Last() != ' ') s += " ";
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
using Avalonia.Input;
|
||||
using FileTime.App.Core.Command;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using FileTime.App.Core.UserCommand;
|
||||
|
||||
namespace FileTime.GuiApp.Configuration;
|
||||
|
||||
@@ -42,66 +40,66 @@ public static class MainConfiguration
|
||||
{
|
||||
return new List<CommandBindingConfiguration>()
|
||||
{
|
||||
new CommandBindingConfiguration(Command.AutoRefresh, new KeyConfig(Key.R, shift: true)),
|
||||
new CommandBindingConfiguration(Command.ChangeTimelineMode, new[] { Key.T, Key.M }),
|
||||
new CommandBindingConfiguration(Command.CloseTab, Key.Q),
|
||||
new CommandBindingConfiguration(Command.Compress, new[] { Key.Y, Key.C }),
|
||||
new CommandBindingConfiguration(Command.Copy, new[] { Key.Y, Key.Y }),
|
||||
new CommandBindingConfiguration(Command.CopyHash, new[] { Key.C, Key.H }),
|
||||
new CommandBindingConfiguration(Command.CopyPath, new[] { Key.C, Key.P }),
|
||||
new CommandBindingConfiguration(Command.CreateContainer, Key.F7),
|
||||
new CommandBindingConfiguration(Command.CreateContainer, new[] { Key.C, Key.C }),
|
||||
new CommandBindingConfiguration(Command.CreateElement, new[] { Key.C, Key.E }),
|
||||
new CommandBindingConfiguration(Command.Cut, new[] { Key.D, Key.D }),
|
||||
new CommandBindingConfiguration(Command.Edit, new KeyConfig(Key.F4)),
|
||||
new CommandBindingConfiguration(Command.EnterRapidTravel, new KeyConfig(Key.OemComma, shift: true)),
|
||||
new CommandBindingConfiguration(Command.FindByName, new[] { Key.F, Key.N }),
|
||||
new CommandBindingConfiguration(Command.FindByNameRegex, new[] { Key.F, Key.R }),
|
||||
new CommandBindingConfiguration(Command.GoToHome, new[] { Key.G, Key.H }),
|
||||
new CommandBindingConfiguration(Command.GoToPath, new KeyConfig(Key.L, ctrl: true)),
|
||||
new CommandBindingConfiguration(Command.GoToPath, new[] { Key.G, Key.P }),
|
||||
new CommandBindingConfiguration(Command.GoToProvider, new[] { Key.G, Key.T }),
|
||||
new CommandBindingConfiguration(Command.GoToRoot, new[] { Key.G, Key.R }),
|
||||
new CommandBindingConfiguration(Command.HardDelete, new[] { new KeyConfig(Key.D,shift: true), new KeyConfig(Key.D, shift: true) }),
|
||||
new CommandBindingConfiguration(Command.Mark, Key.Space),
|
||||
new CommandBindingConfiguration(Command.MoveToLast, new KeyConfig(Key.G, shift: true)),
|
||||
new CommandBindingConfiguration(Command.MoveToFirst, new[] { Key.G, Key.G }),
|
||||
new CommandBindingConfiguration(Command.NextTimelineBlock, Key.L ),
|
||||
new CommandBindingConfiguration(Command.NextTimelineCommand, Key.J ),
|
||||
new CommandBindingConfiguration(Command.OpenInFileBrowser, new[] { Key.O, Key.E }),
|
||||
new CommandBindingConfiguration(Command.PasteMerge, new[] { Key.P, Key.P }),
|
||||
new CommandBindingConfiguration(Command.PasteOverwrite, new[] { Key.P, Key.O }),
|
||||
new CommandBindingConfiguration(Command.PasteSkip, new[] { Key.P, Key.S }),
|
||||
new CommandBindingConfiguration(Command.PinFavorite, new[] { Key.F, Key.P }),
|
||||
new CommandBindingConfiguration(Command.PreviousTimelineBlock, Key.H ),
|
||||
new CommandBindingConfiguration(Command.PreviousTimelineCommand, Key.K ),
|
||||
new CommandBindingConfiguration(Command.Refresh, Key.R),
|
||||
new CommandBindingConfiguration(Command.Rename, Key.F2),
|
||||
new CommandBindingConfiguration(Command.Rename, new[] { Key.C, Key.W }),
|
||||
new CommandBindingConfiguration(Command.RunCommand, new KeyConfig(Key.D4, shift: true)),
|
||||
new CommandBindingConfiguration(Command.ScanContainerSize, new[] { Key.C, Key.S }),
|
||||
new CommandBindingConfiguration(Command.ShowAllShortcut, Key.F1),
|
||||
new CommandBindingConfiguration(Command.SoftDelete, new[] { new KeyConfig(Key.D), new KeyConfig(Key.D, shift: true) }),
|
||||
new CommandBindingConfiguration(Command.SwitchToLastTab, Key.D9),
|
||||
new CommandBindingConfiguration(Command.SwitchToTab1, Key.D1),
|
||||
new CommandBindingConfiguration(Command.SwitchToTab2, Key.D2),
|
||||
new CommandBindingConfiguration(Command.SwitchToTab3, Key.D3),
|
||||
new CommandBindingConfiguration(Command.SwitchToTab4, Key.D4),
|
||||
new CommandBindingConfiguration(Command.SwitchToTab5, Key.D5),
|
||||
new CommandBindingConfiguration(Command.SwitchToTab6, Key.D6),
|
||||
new CommandBindingConfiguration(Command.SwitchToTab7, Key.D7),
|
||||
new CommandBindingConfiguration(Command.SwitchToTab8, Key.D8),
|
||||
new CommandBindingConfiguration(Command.TimelinePause, new[] { Key.T, Key.P }),
|
||||
new CommandBindingConfiguration(Command.TimelineRefresh, new[] { Key.T, Key.R }),
|
||||
new CommandBindingConfiguration(Command.TimelineStart, new[] { Key.T, Key.S }),
|
||||
new CommandBindingConfiguration(Command.ToggleAdvancedIcons, new[] { Key.Z, Key.I }),
|
||||
new CommandBindingConfiguration(Command.GoUp, Key.Left),
|
||||
new CommandBindingConfiguration(Command.Open, Key.Right),
|
||||
new CommandBindingConfiguration(Command.OpenOrRun, Key.Enter),
|
||||
new CommandBindingConfiguration(Command.MoveCursorUp, Key.Up),
|
||||
new CommandBindingConfiguration(Command.MoveCursorDown, Key.Down),
|
||||
new CommandBindingConfiguration(Command.MoveCursorUpPage, Key.PageUp),
|
||||
new CommandBindingConfiguration(Command.MoveCursorDownPage, Key.PageDown),
|
||||
//new CommandBindingConfiguration(ConfigCommand.AutoRefresh, new KeyConfig(Key.R, shift: true)),
|
||||
//new CommandBindingConfiguration(ConfigCommand.ChangeTimelineMode, new[] { Key.T, Key.M }),
|
||||
new CommandBindingConfiguration(CloseTabCommand.CommandName, Key.Q),
|
||||
//new CommandBindingConfiguration(ConfigCommand.Compress, new[] { Key.Y, Key.C }),
|
||||
new CommandBindingConfiguration(CopyCommand.CommandName, new[] { Key.Y, Key.Y }),
|
||||
//new CommandBindingConfiguration(ConfigCommand.CopyHash, new[] { Key.C, Key.H }),
|
||||
//new CommandBindingConfiguration(ConfigCommand.CopyPath, new[] { Key.C, Key.P }),
|
||||
//new CommandBindingConfiguration(ConfigCommand.CreateContainer, Key.F7),
|
||||
//new CommandBindingConfiguration(ConfigCommand.CreateContainer, new[] { Key.C, Key.C }),
|
||||
//new CommandBindingConfiguration(ConfigCommand.CreateElement, new[] { Key.C, Key.E }),
|
||||
//new CommandBindingConfiguration(ConfigCommand.Cut, new[] { Key.D, Key.D }),
|
||||
//new CommandBindingConfiguration(ConfigCommand.Edit, new KeyConfig(Key.F4)),
|
||||
new CommandBindingConfiguration(EnterRapidTravelCommand.CommandName, new KeyConfig(Key.OemComma, shift: true)),
|
||||
//new CommandBindingConfiguration(ConfigCommand.FindByName, new[] { Key.F, Key.N }),
|
||||
//new CommandBindingConfiguration(ConfigCommand.FindByNameRegex, new[] { Key.F, Key.R }),
|
||||
//new CommandBindingConfiguration(ConfigCommand.GoToHome, new[] { Key.G, Key.H }),
|
||||
//new CommandBindingConfiguration(ConfigCommand.GoToPath, new KeyConfig(Key.L, ctrl: true)),
|
||||
//new CommandBindingConfiguration(ConfigCommand.GoToPath, new[] { Key.G, Key.P }),
|
||||
//new CommandBindingConfiguration(ConfigCommand.GoToProvider, new[] { Key.G, Key.T }),
|
||||
//new CommandBindingConfiguration(ConfigCommand.GoToRoot, new[] { Key.G, Key.R }),
|
||||
//new CommandBindingConfiguration(ConfigCommand.HardDelete, new[] { new KeyConfig(Key.D,shift: true), new KeyConfig(Key.D, shift: true) }),
|
||||
new CommandBindingConfiguration(MarkCommand.CommandName, Key.Space),
|
||||
//new CommandBindingConfiguration(ConfigCommand.MoveToLast, new KeyConfig(Key.G, shift: true)),
|
||||
//new CommandBindingConfiguration(ConfigCommand.MoveToFirst, new[] { Key.G, Key.G }),
|
||||
//new CommandBindingConfiguration(ConfigCommand.NextTimelineBlock, Key.L ),
|
||||
//new CommandBindingConfiguration(ConfigCommand.NextTimelineCommand, Key.J ),
|
||||
//new CommandBindingConfiguration(ConfigCommand.OpenInFileBrowser, new[] { Key.O, Key.E }),
|
||||
new CommandBindingConfiguration(PasteCommand.PasteMergeCommandName, new[] { Key.P, Key.P }),
|
||||
new CommandBindingConfiguration(PasteCommand.PasteOverwriteCommandName, new[] { Key.P, Key.O }),
|
||||
new CommandBindingConfiguration(PasteCommand.PasteSkipCommandName, new[] { Key.P, Key.S }),
|
||||
//new CommandBindingConfiguration(ConfigCommand.PinFavorite, new[] { Key.F, Key.P }),
|
||||
//new CommandBindingConfiguration(ConfigCommand.PreviousTimelineBlock, Key.H ),
|
||||
//new CommandBindingConfiguration(ConfigCommand.PreviousTimelineCommand, Key.K ),
|
||||
//new CommandBindingConfiguration(ConfigCommand.Refresh, Key.R),
|
||||
//new CommandBindingConfiguration(ConfigCommand.Rename, Key.F2),
|
||||
//new CommandBindingConfiguration(ConfigCommand.Rename, new[] { Key.C, Key.W }),
|
||||
//new CommandBindingConfiguration(ConfigCommand.RunCommand, new KeyConfig(Key.D4, shift: true)),
|
||||
//new CommandBindingConfiguration(ConfigCommand.ScanContainerSize, new[] { Key.C, Key.S }),
|
||||
//new CommandBindingConfiguration(ConfigCommand.ShowAllShortcut, Key.F1),
|
||||
//new CommandBindingConfiguration(ConfigCommand.SoftDelete, new[] { new KeyConfig(Key.D), new KeyConfig(Key.D, shift: true) }),
|
||||
new CommandBindingConfiguration(SwitchToTabCommand.SwitchToLastTabCommandName, Key.D9),
|
||||
new CommandBindingConfiguration(SwitchToTabCommand.SwitchToTab1CommandName, Key.D1),
|
||||
new CommandBindingConfiguration(SwitchToTabCommand.SwitchToTab2CommandName, Key.D2),
|
||||
new CommandBindingConfiguration(SwitchToTabCommand.SwitchToTab3CommandName, Key.D3),
|
||||
new CommandBindingConfiguration(SwitchToTabCommand.SwitchToTab4CommandName, Key.D4),
|
||||
new CommandBindingConfiguration(SwitchToTabCommand.SwitchToTab5CommandName, Key.D5),
|
||||
new CommandBindingConfiguration(SwitchToTabCommand.SwitchToTab6CommandName, Key.D6),
|
||||
new CommandBindingConfiguration(SwitchToTabCommand.SwitchToTab7CommandName, Key.D7),
|
||||
new CommandBindingConfiguration(SwitchToTabCommand.SwitchToTab8CommandName, Key.D8),
|
||||
//new CommandBindingConfiguration(ConfigCommand.TimelinePause, new[] { Key.T, Key.P }),
|
||||
//new CommandBindingConfiguration(ConfigCommand.TimelineRefresh, new[] { Key.T, Key.R }),
|
||||
//new CommandBindingConfiguration(ConfigCommand.TimelineStart, new[] { Key.T, Key.S }),
|
||||
//new CommandBindingConfiguration(ConfigCommand.ToggleAdvancedIcons, new[] { Key.Z, Key.I }),
|
||||
new CommandBindingConfiguration(GoUpCommand.CommandName, Key.Left),
|
||||
new CommandBindingConfiguration(OpenSelectedCommand.CommandName, Key.Right),
|
||||
//new CommandBindingConfiguration(ConfigCommand.OpenOrRun, Key.Enter),
|
||||
new CommandBindingConfiguration(MoveCursorUpCommand.CommandName, Key.Up),
|
||||
new CommandBindingConfiguration(MoveCursorDownCommand.CommandName, Key.Down),
|
||||
//new CommandBindingConfiguration(ConfigCommand.MoveCursorUpPage, Key.PageUp),
|
||||
//new CommandBindingConfiguration(ConfigCommand.MoveCursorDownPage, Key.PageDown),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace FileTime.GuiApp.Configuration;
|
||||
|
||||
public class ProgramsConfiguration
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace FileTime.GuiApp.Services;
|
||||
|
||||
public interface IKeyboardConfigurationService
|
||||
{
|
||||
IReadOnlyList<CommandBindingConfiguration> CommandBindings { get; }
|
||||
IReadOnlyList<CommandBindingConfiguration> UniversalCommandBindings { get; }
|
||||
IReadOnlyList<CommandBindingConfiguration> AllShortcut { get; }
|
||||
IReadOnlyDictionary<string, CommandBindingConfiguration> CommandBindings { get; }
|
||||
IReadOnlyDictionary<string, CommandBindingConfiguration> UniversalCommandBindings { get; }
|
||||
IReadOnlyDictionary<string, CommandBindingConfiguration> AllShortcut { get; }
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using FileTime.App.Core.Models;
|
||||
using FileTime.App.Core.ViewModels;
|
||||
using FileTime.GuiApp.Configuration;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using FileTime.App.Core.Models;
|
||||
using FileTime.App.Core.ViewModels;
|
||||
using FileTime.GuiApp.Configuration;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.Globalization;
|
||||
using Avalonia.Data.Converters;
|
||||
using FileTime.App.Core.Command;
|
||||
using FileTime.App.Core.UserCommand;
|
||||
|
||||
namespace FileTime.GuiApp.Converters;
|
||||
|
||||
@@ -8,7 +8,7 @@ public class CommandToCommandNameConverter : IValueConverter
|
||||
{
|
||||
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
if(value is not Command command) return value;
|
||||
if(value is not IUserCommand command) return value;
|
||||
|
||||
//TODO: implement
|
||||
return command.ToString();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Reactive.Linq;
|
||||
using Avalonia.Input;
|
||||
using FileTime.App.Core.Command;
|
||||
using FileTime.App.Core.Services;
|
||||
using FileTime.App.Core.UserCommand;
|
||||
using FileTime.App.Core.ViewModels;
|
||||
using FileTime.Core.Models;
|
||||
using FileTime.GuiApp.Configuration;
|
||||
@@ -20,18 +20,21 @@ public class DefaultModeKeyInputHandler : IDefaultModeKeyInputHandler
|
||||
private ITabViewModel? _selectedTab;
|
||||
private IContainer? _currentLocation;
|
||||
private readonly ILogger<DefaultModeKeyInputHandler> _logger;
|
||||
private readonly ICommandHandlerService _commandHandlerService;
|
||||
private readonly IUserCommandHandlerService _userCommandHandlerService;
|
||||
private readonly IIdentifiableUserCommandService _identifiableUserCommandService;
|
||||
|
||||
public DefaultModeKeyInputHandler(
|
||||
IGuiAppState appState,
|
||||
IKeyboardConfigurationService keyboardConfigurationService,
|
||||
ILogger<DefaultModeKeyInputHandler> logger,
|
||||
ICommandHandlerService commandHandlerService)
|
||||
IUserCommandHandlerService userCommandHandlerService,
|
||||
IIdentifiableUserCommandService identifiableUserCommandService)
|
||||
{
|
||||
_appState = appState;
|
||||
_keyboardConfigurationService = keyboardConfigurationService;
|
||||
_logger = logger;
|
||||
_commandHandlerService = commandHandlerService;
|
||||
_userCommandHandlerService = userCommandHandlerService;
|
||||
_identifiableUserCommandService = identifiableUserCommandService;
|
||||
|
||||
_appState.SelectedTab.Subscribe(t => _selectedTab = t);
|
||||
_appState.SelectedTab.Select(t => t == null ? Observable.Return<IContainer?>(null) : t.CurrentLocation!).Switch().Subscribe(l => _currentLocation = l);
|
||||
@@ -51,8 +54,8 @@ public class DefaultModeKeyInputHandler : IDefaultModeKeyInputHandler
|
||||
var keyWithModifiers = new KeyConfig(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));
|
||||
var selectedCommandBinding = _keyboardConfigurationService.UniversalCommandBindings.Values.FirstOrDefault(c => c.Keys.AreKeysEqual(_appState.PreviousKeys));
|
||||
selectedCommandBinding ??= _keyboardConfigurationService.CommandBindings.Values.FirstOrDefault(c => c.Keys.AreKeysEqual(_appState.PreviousKeys));
|
||||
|
||||
if (key == Key.Escape)
|
||||
{
|
||||
@@ -104,7 +107,7 @@ public class DefaultModeKeyInputHandler : IDefaultModeKeyInputHandler
|
||||
setHandled(true);
|
||||
_appState.PreviousKeys.Clear();
|
||||
_appState.PossibleCommands = new();
|
||||
await CallCommandAsync(selectedCommandBinding.Command);
|
||||
await CallCommandAsync(_identifiableUserCommandService.GetCommand(selectedCommandBinding.Command));
|
||||
}
|
||||
else if (_keysToSkip.Any(k => k.AreKeysEqual(_appState.PreviousKeys)))
|
||||
{
|
||||
@@ -122,7 +125,7 @@ public class DefaultModeKeyInputHandler : IDefaultModeKeyInputHandler
|
||||
else
|
||||
{
|
||||
setHandled(true);
|
||||
var possibleCommands = _keyboardConfigurationService.AllShortcut.Where(c => c.Keys[0].AreEquals(keyWithModifiers)).ToList();
|
||||
var possibleCommands = _keyboardConfigurationService.AllShortcut.Values.Where(c => c.Keys[0].AreEquals(keyWithModifiers)).ToList();
|
||||
|
||||
if (possibleCommands.Count == 0)
|
||||
{
|
||||
@@ -136,15 +139,15 @@ public class DefaultModeKeyInputHandler : IDefaultModeKeyInputHandler
|
||||
}
|
||||
}
|
||||
|
||||
private async Task CallCommandAsync(Command command)
|
||||
private async Task CallCommandAsync(IUserCommand command)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _commandHandlerService.HandleCommandAsync(command);
|
||||
await _userCommandHandlerService.HandleCommandAsync(command);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError(e, "Unknown error while running command. {Command} {Error}", command, e);
|
||||
_logger.LogError(e, "Unknown error while running command. {Command} {Error}", command.GetType().Name, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
using Avalonia.Input;
|
||||
using FileTime.App.Core.Models.Enums;
|
||||
using FileTime.GuiApp.Configuration;
|
||||
using FileTime.GuiApp.Models;
|
||||
using FileTime.GuiApp.ViewModels;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using FileTime.App.Core.Command;
|
||||
using System.Collections.ObjectModel;
|
||||
using FileTime.GuiApp.Configuration;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
@@ -6,14 +6,14 @@ namespace FileTime.GuiApp.Services;
|
||||
|
||||
public class KeyboardConfigurationService : IKeyboardConfigurationService
|
||||
{
|
||||
public IReadOnlyList<CommandBindingConfiguration> CommandBindings { get; }
|
||||
public IReadOnlyList<CommandBindingConfiguration> UniversalCommandBindings { get; }
|
||||
public IReadOnlyList<CommandBindingConfiguration> AllShortcut { get; }
|
||||
public IReadOnlyDictionary<string, CommandBindingConfiguration> CommandBindings { get; }
|
||||
public IReadOnlyDictionary<string, CommandBindingConfiguration> UniversalCommandBindings { get; }
|
||||
public IReadOnlyDictionary<string, CommandBindingConfiguration> AllShortcut { get; }
|
||||
|
||||
public KeyboardConfigurationService(IOptions<KeyBindingConfiguration> keyBindingConfiguration)
|
||||
{
|
||||
var commandBindings = new List<CommandBindingConfiguration>();
|
||||
var universalCommandBindings = new List<CommandBindingConfiguration>();
|
||||
var commandBindings = new Dictionary<string, CommandBindingConfiguration>();
|
||||
var universalCommandBindings = new Dictionary<string, CommandBindingConfiguration>();
|
||||
IEnumerable<CommandBindingConfiguration> keyBindings = keyBindingConfiguration.Value.KeyBindings;
|
||||
|
||||
if (keyBindingConfiguration.Value.UseDefaultBindings)
|
||||
@@ -23,7 +23,7 @@ public class KeyboardConfigurationService : IKeyboardConfigurationService
|
||||
|
||||
foreach (var keyBinding in keyBindings)
|
||||
{
|
||||
if (keyBinding.Command == Command.None)
|
||||
if (string.IsNullOrWhiteSpace(keyBinding.Command))
|
||||
{
|
||||
throw new FormatException($"No command is set in keybinding for keys '{keyBinding.KeysDisplayText}'");
|
||||
}
|
||||
@@ -34,21 +34,22 @@ public class KeyboardConfigurationService : IKeyboardConfigurationService
|
||||
|
||||
if (IsUniversal(keyBinding))
|
||||
{
|
||||
universalCommandBindings.Add(keyBinding);
|
||||
universalCommandBindings.Add(keyBinding.Command, keyBinding);
|
||||
}
|
||||
else
|
||||
{
|
||||
commandBindings.Add(keyBinding);
|
||||
commandBindings.Add(keyBinding.Command, keyBinding);
|
||||
}
|
||||
}
|
||||
|
||||
CommandBindings = commandBindings.AsReadOnly();
|
||||
UniversalCommandBindings = universalCommandBindings.AsReadOnly();
|
||||
AllShortcut = new List<CommandBindingConfiguration>(CommandBindings.Concat(UniversalCommandBindings)).AsReadOnly();
|
||||
CommandBindings = new ReadOnlyDictionary<string, CommandBindingConfiguration>(commandBindings);
|
||||
UniversalCommandBindings = new ReadOnlyDictionary<string, CommandBindingConfiguration>(universalCommandBindings);
|
||||
AllShortcut = new ReadOnlyDictionary<string, CommandBindingConfiguration>(new Dictionary<string, CommandBindingConfiguration>(CommandBindings.Concat(UniversalCommandBindings)));
|
||||
}
|
||||
|
||||
private static bool IsUniversal(CommandBindingConfiguration keyMapping)
|
||||
{
|
||||
return keyMapping.Command is Command.GoUp or Command.Open or Command.OpenOrRun or Command.MoveCursorUp or Command.MoveCursorDown or Command.MoveCursorUpPage or Command.MoveCursorDownPage;
|
||||
return false;
|
||||
//return keyMapping.Command is ConfigCommand.GoUp or ConfigCommand.Open or ConfigCommand.OpenOrRun or ConfigCommand.MoveCursorUp or ConfigCommand.MoveCursorDown or ConfigCommand.MoveCursorUpPage or ConfigCommand.MoveCursorDownPage;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
using Avalonia.Input;
|
||||
using FileTime.App.Core.Command;
|
||||
using FileTime.App.Core.Models;
|
||||
using FileTime.App.Core.Models.Enums;
|
||||
using FileTime.App.Core.Services;
|
||||
using FileTime.App.Core.UserCommand;
|
||||
using FileTime.App.Core.ViewModels;
|
||||
using FileTime.Core.Models;
|
||||
using FileTime.Core.Services;
|
||||
@@ -15,12 +14,14 @@ namespace FileTime.GuiApp.Services;
|
||||
|
||||
public class RapidTravelModeKeyInputHandler : IRapidTravelModeKeyInputHandler
|
||||
{
|
||||
private const string RAPIDTRAVELFILTERNAME = "rapid_travel_filter";
|
||||
private const string RapidTravelFilterName = "rapid_travel_filter";
|
||||
|
||||
private readonly IAppState _appState;
|
||||
private readonly IModalService _modalService;
|
||||
private readonly IKeyboardConfigurationService _keyboardConfigurationService;
|
||||
private readonly ICommandHandlerService _commandHandlerService;
|
||||
private readonly IUserCommandHandlerService _userCommandHandlerService;
|
||||
private readonly ILogger<RapidTravelModeKeyInputHandler> _logger;
|
||||
private readonly IIdentifiableUserCommandService _identifiableUserCommandService;
|
||||
private readonly BindedCollection<IModalViewModelBase> _openModals;
|
||||
private ITabViewModel? _selectedTab;
|
||||
|
||||
@@ -28,15 +29,17 @@ public class RapidTravelModeKeyInputHandler : IRapidTravelModeKeyInputHandler
|
||||
IAppState appState,
|
||||
IModalService modalService,
|
||||
IKeyboardConfigurationService keyboardConfigurationService,
|
||||
ICommandHandlerService commandHandlerService,
|
||||
ILogger<RapidTravelModeKeyInputHandler> logger)
|
||||
IUserCommandHandlerService userCommandHandlerService,
|
||||
ILogger<RapidTravelModeKeyInputHandler> logger,
|
||||
IIdentifiableUserCommandService identifiableUserCommandService)
|
||||
{
|
||||
_appState = appState;
|
||||
_modalService = modalService;
|
||||
_keyboardConfigurationService = keyboardConfigurationService;
|
||||
_commandHandlerService = commandHandlerService;
|
||||
_userCommandHandlerService = userCommandHandlerService;
|
||||
_logger = logger;
|
||||
|
||||
_identifiableUserCommandService = identifiableUserCommandService;
|
||||
|
||||
_appState.SelectedTab.Subscribe(t => _selectedTab = t);
|
||||
|
||||
_openModals = new BindedCollection<IModalViewModelBase>(modalService.OpenModals);
|
||||
@@ -56,7 +59,7 @@ public class RapidTravelModeKeyInputHandler : IRapidTravelModeKeyInputHandler
|
||||
}
|
||||
else
|
||||
{
|
||||
await CallCommandAsync(Command.ExitRapidTravel);
|
||||
await CallCommandAsync(ExitRapidTravelCommand.Instance);
|
||||
}
|
||||
}
|
||||
else if (key == Key.Back)
|
||||
@@ -77,11 +80,11 @@ public class RapidTravelModeKeyInputHandler : IRapidTravelModeKeyInputHandler
|
||||
else
|
||||
{
|
||||
var currentKeyAsList = new List<KeyConfig>() {new KeyConfig(key)};
|
||||
var selectedCommandBinding = _keyboardConfigurationService.UniversalCommandBindings.FirstOrDefault(c => c.Keys.AreKeysEqual(currentKeyAsList));
|
||||
var selectedCommandBinding = _keyboardConfigurationService.UniversalCommandBindings.Values.FirstOrDefault(c => c.Keys.AreKeysEqual(currentKeyAsList));
|
||||
if (selectedCommandBinding != null)
|
||||
{
|
||||
setHandled(true);
|
||||
await CallCommandAsync(selectedCommandBinding.Command);
|
||||
await CallCommandAsync(_identifiableUserCommandService.GetCommand(selectedCommandBinding.Command));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,8 +92,8 @@ public class RapidTravelModeKeyInputHandler : IRapidTravelModeKeyInputHandler
|
||||
{
|
||||
if (_selectedTab?.Tab is not ITab tab) return;
|
||||
|
||||
tab.RemoveItemFilter(RAPIDTRAVELFILTERNAME);
|
||||
tab.AddItemFilter(new ItemFilter(RAPIDTRAVELFILTERNAME, i => i.Name.ToLower().Contains(_appState.RapidTravelText)));
|
||||
tab.RemoveItemFilter(RapidTravelFilterName);
|
||||
tab.AddItemFilter(new ItemFilter(RapidTravelFilterName, i => i.Name.ToLower().Contains(_appState.RapidTravelText)));
|
||||
/*var currentLocation = await _appState.SelectedTab.CurrentLocation.Container.WithoutVirtualContainer(MainPageViewModel.RAPIDTRAVEL);
|
||||
var newLocation = new VirtualContainer(
|
||||
currentLocation,
|
||||
@@ -122,15 +125,15 @@ public class RapidTravelModeKeyInputHandler : IRapidTravelModeKeyInputHandler
|
||||
}
|
||||
}
|
||||
|
||||
private async Task CallCommandAsync(Command command)
|
||||
private async Task CallCommandAsync(IUserCommand command)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _commandHandlerService.HandleCommandAsync(command);
|
||||
await _userCommandHandlerService.HandleCommandAsync(command);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError(e, "Unknown error while running command. {Command} {Error}", command, e);
|
||||
_logger.LogError(e, "Unknown error while running command. {Command} {Error}", command.GetType().Name, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Reflection;
|
||||
using Avalonia.Input;
|
||||
using FileTime.App.Core;
|
||||
using FileTime.App.Core.Services;
|
||||
using FileTime.App.Core.ViewModels;
|
||||
using FileTime.Core.Models;
|
||||
@@ -20,7 +18,7 @@ namespace FileTime.GuiApp.ViewModels;
|
||||
[Inject(typeof(IServiceProvider), PropertyName = "_serviceProvider")]
|
||||
[Inject(typeof(ILogger<MainWindowViewModel>), PropertyName = "_logger")]
|
||||
[Inject(typeof(IKeyInputHandlerService), PropertyName = "_keyInputHandlerService")]
|
||||
[Inject(typeof(ICommandHandlerService), PropertyAccessModifier = AccessModifier.Public)]
|
||||
[Inject(typeof(IUserCommandHandlerService), PropertyAccessModifier = AccessModifier.Public)]
|
||||
[Inject(typeof(LifecycleService), PropertyName = "_lifecycleService")]
|
||||
public partial class MainWindowViewModel : IMainWindowViewModelBase
|
||||
{
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
using System;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.Threading;
|
||||
using FileTime.Core.Models;
|
||||
using FileTime.GuiApp.Models;
|
||||
using FileTime.GuiApp.ViewModels;
|
||||
|
||||
Reference in New Issue
Block a user