Rename Commands enum to Command

This commit is contained in:
2022-05-11 11:49:26 +02:00
parent ae66ff92ee
commit 0ee4025e00
13 changed files with 94 additions and 94 deletions

View File

@@ -1,6 +1,6 @@
namespace FileTime.App.Core.Command;
public enum Commands
public enum Command
{
None,

View File

@@ -4,6 +4,6 @@ namespace FileTime.App.Core.Services;
public interface ICommandHandler
{
bool CanHandleCommand(Commands command);
Task HandleCommandAsync(Commands command);
bool CanHandleCommand(Command.Command command);
Task HandleCommandAsync(Command.Command command);
}

View File

@@ -4,5 +4,5 @@ namespace FileTime.App.Core.Services;
public interface ICommandHandlerService
{
Task HandleCommandAsync(Commands command);
Task HandleCommandAsync(Command.Command command);
}

View File

@@ -8,7 +8,7 @@ namespace FileTime.App.Core.Services.CommandHandler;
public abstract class CommandHandlerBase : ICommandHandler
{
private readonly Dictionary<Commands, Func<Task>> _commandHandlers = new();
private readonly Dictionary<Command.Command, Func<Task>> _commandHandlers = new();
private readonly IAppState? _appState;
protected CommandHandlerBase(IAppState? appState = null)
@@ -16,12 +16,12 @@ public abstract class CommandHandlerBase : ICommandHandler
_appState = appState;
}
public bool CanHandleCommand(Commands command) => _commandHandlers.ContainsKey(command);
public bool CanHandleCommand(Command.Command command) => _commandHandlers.ContainsKey(command);
public async Task HandleCommandAsync(Commands command) => await _commandHandlers[command].Invoke();
public async Task HandleCommandAsync(Command.Command command) => await _commandHandlers[command].Invoke();
protected void AddCommandHandler(Commands command, Func<Task> handler) => _commandHandlers.Add(command, handler);
protected void AddCommandHandlers(IEnumerable<(Commands command, Func<Task> handler)> commandHandlers)
protected void AddCommandHandler(Command.Command command, Func<Task> handler) => _commandHandlers.Add(command, handler);
protected void AddCommandHandlers(IEnumerable<(Command.Command command, Func<Task> handler)> commandHandlers)
{
foreach (var (command, handler) in commandHandlers)
{
@@ -29,7 +29,7 @@ public abstract class CommandHandlerBase : ICommandHandler
}
}
protected void RemoveCommandHandler(Commands command) => _commandHandlers.Remove(command);
protected void RemoveCommandHandler(Command.Command command) => _commandHandlers.Remove(command);
protected IDisposable SaveSelectedTab(Action<ITabViewModel?> handler) => RunWithAppState(appState => appState.SelectedTab.Subscribe(handler));
protected IDisposable SaveCurrentSelectedItem(Action<IItemViewModel?> handler)

View File

@@ -29,13 +29,13 @@ public class ItemManipulationCommandHandler : CommandHandlerBase
_markedItems = new BindedCollection<IAbsolutePath>(appState.SelectedTab.Select(t => t?.MarkedItems));
AddCommandHandlers(new (Commands, Func<Task>)[]
AddCommandHandlers(new (Command.Command, Func<Task>)[]
{
(Commands.Copy, Copy),
(Commands.Mark, MarkItem),
(Commands.PasteMerge, PasteMerge),
(Commands.PasteOverwrite, PasteOverwrite),
(Commands.PasteSkip, PasteSkip),
(Command.Command.Copy, Copy),
(Command.Command.Mark, MarkItem),
(Command.Command.PasteMerge, PasteMerge),
(Command.Command.PasteOverwrite, PasteOverwrite),
(Command.Command.PasteSkip, PasteSkip),
});
}
@@ -44,7 +44,7 @@ public class ItemManipulationCommandHandler : CommandHandlerBase
if (_selectedTab == null || _currentSelectedItem?.BaseItem?.FullName == null) return;
_selectedTab.ToggleMarkedItem(new AbsolutePath(_currentSelectedItem.BaseItem));
await _commandHandlerService.HandleCommandAsync(Commands.MoveCursorDown);
await _commandHandlerService.HandleCommandAsync(Command.Command.MoveCursorDown);
}
private Task Copy()

View File

@@ -24,13 +24,13 @@ public class NavigationCommandHandler : CommandHandlerBase
SaveCurrentLocation(l => _currentLocation = l);
SaveCurrentItems(i => _currentItems = i);
AddCommandHandlers(new (Commands, Func<Task>)[]
AddCommandHandlers(new (Command.Command, Func<Task>)[]
{
(Commands.EnterRapidTravel, EnterRapidTravel),
(Commands.GoUp, GoUp),
(Commands.MoveCursorDown, MoveCursorDown),
(Commands.MoveCursorUp, MoveCursorUp),
(Commands.Open, OpenContainer),
(Command.Command.EnterRapidTravel, EnterRapidTravel),
(Command.Command.GoUp, GoUp),
(Command.Command.MoveCursorDown, MoveCursorDown),
(Command.Command.MoveCursorUp, MoveCursorUp),
(Command.Command.Open, OpenContainer),
});
}

View File

@@ -67,7 +67,7 @@ public class CommandHandlerService : ICommandHandlerService
//(Commands.ToggleHidden, ToggleHidden),
}
public async Task HandleCommandAsync(Commands command)
public async Task HandleCommandAsync(Command.Command command)
{
var handler = _commandHandlers.Value.FirstOrDefault(h => h.CanHandleCommand(command));

View File

@@ -7,31 +7,31 @@ public class CommandBindingConfiguration
{
public List<KeyConfig> Keys { get; set; } = new List<KeyConfig>();
public Commands Command { get; set; } = Commands.None;
public Command Command { get; set; } = Command.None;
public string KeysDisplayText => GetKeysDisplayText();
public CommandBindingConfiguration() { }
public CommandBindingConfiguration(Commands command, IEnumerable<KeyConfig> keys)
public CommandBindingConfiguration(Command command, IEnumerable<KeyConfig> keys)
{
Keys = new List<KeyConfig>(keys);
Command = command;
}
public CommandBindingConfiguration(Commands command, KeyConfig key)
public CommandBindingConfiguration(Command command, KeyConfig key)
{
Keys = new List<KeyConfig>() { key };
Command = command;
}
public CommandBindingConfiguration(Commands command, IEnumerable<Key> keys)
public CommandBindingConfiguration(Command command, IEnumerable<Key> keys)
{
Keys = keys.Select(k => new KeyConfig(k)).ToList();
Command = command;
}
public CommandBindingConfiguration(Commands command, Key key)
public CommandBindingConfiguration(Command command, Key key)
{
Keys = new List<KeyConfig>() { new KeyConfig(key) };
Command = command;

View File

@@ -42,66 +42,66 @@ public static class MainConfiguration
{
return new List<CommandBindingConfiguration>()
{
new CommandBindingConfiguration(Commands.AutoRefresh, new KeyConfig(Key.R, shift: true)),
new CommandBindingConfiguration(Commands.ChangeTimelineMode, new[] { Key.T, Key.M }),
new CommandBindingConfiguration(Commands.CloseTab, Key.Q),
new CommandBindingConfiguration(Commands.Compress, new[] { Key.Y, Key.C }),
new CommandBindingConfiguration(Commands.Copy, new[] { Key.Y, Key.Y }),
new CommandBindingConfiguration(Commands.CopyHash, new[] { Key.C, Key.H }),
new CommandBindingConfiguration(Commands.CopyPath, new[] { Key.C, Key.P }),
new CommandBindingConfiguration(Commands.CreateContainer, Key.F7),
new CommandBindingConfiguration(Commands.CreateContainer, new[] { Key.C, Key.C }),
new CommandBindingConfiguration(Commands.CreateElement, new[] { Key.C, Key.E }),
new CommandBindingConfiguration(Commands.Cut, new[] { Key.D, Key.D }),
new CommandBindingConfiguration(Commands.Edit, new KeyConfig(Key.F4)),
new CommandBindingConfiguration(Commands.EnterRapidTravel, new KeyConfig(Key.OemComma, shift: true)),
new CommandBindingConfiguration(Commands.FindByName, new[] { Key.F, Key.N }),
new CommandBindingConfiguration(Commands.FindByNameRegex, new[] { Key.F, Key.R }),
new CommandBindingConfiguration(Commands.GoToHome, new[] { Key.G, Key.H }),
new CommandBindingConfiguration(Commands.GoToPath, new KeyConfig(Key.L, ctrl: true)),
new CommandBindingConfiguration(Commands.GoToPath, new[] { Key.G, Key.P }),
new CommandBindingConfiguration(Commands.GoToProvider, new[] { Key.G, Key.T }),
new CommandBindingConfiguration(Commands.GoToRoot, new[] { Key.G, Key.R }),
new CommandBindingConfiguration(Commands.HardDelete, new[] { new KeyConfig(Key.D,shift: true), new KeyConfig(Key.D, shift: true) }),
new CommandBindingConfiguration(Commands.Mark, Key.Space),
new CommandBindingConfiguration(Commands.MoveToLast, new KeyConfig(Key.G, shift: true)),
new CommandBindingConfiguration(Commands.MoveToFirst, new[] { Key.G, Key.G }),
new CommandBindingConfiguration(Commands.NextTimelineBlock, Key.L ),
new CommandBindingConfiguration(Commands.NextTimelineCommand, Key.J ),
new CommandBindingConfiguration(Commands.OpenInFileBrowser, new[] { Key.O, Key.E }),
new CommandBindingConfiguration(Commands.PasteMerge, new[] { Key.P, Key.P }),
new CommandBindingConfiguration(Commands.PasteOverwrite, new[] { Key.P, Key.O }),
new CommandBindingConfiguration(Commands.PasteSkip, new[] { Key.P, Key.S }),
new CommandBindingConfiguration(Commands.PinFavorite, new[] { Key.F, Key.P }),
new CommandBindingConfiguration(Commands.PreviousTimelineBlock, Key.H ),
new CommandBindingConfiguration(Commands.PreviousTimelineCommand, Key.K ),
new CommandBindingConfiguration(Commands.Refresh, Key.R),
new CommandBindingConfiguration(Commands.Rename, Key.F2),
new CommandBindingConfiguration(Commands.Rename, new[] { Key.C, Key.W }),
new CommandBindingConfiguration(Commands.RunCommand, new KeyConfig(Key.D4, shift: true)),
new CommandBindingConfiguration(Commands.ScanContainerSize, new[] { Key.C, Key.S }),
new CommandBindingConfiguration(Commands.ShowAllShotcut, Key.F1),
new CommandBindingConfiguration(Commands.SoftDelete, new[] { new KeyConfig(Key.D), new KeyConfig(Key.D, shift: true) }),
new CommandBindingConfiguration(Commands.SwitchToLastTab, Key.D9),
new CommandBindingConfiguration(Commands.SwitchToTab1, Key.D1),
new CommandBindingConfiguration(Commands.SwitchToTab2, Key.D2),
new CommandBindingConfiguration(Commands.SwitchToTab3, Key.D3),
new CommandBindingConfiguration(Commands.SwitchToTab4, Key.D4),
new CommandBindingConfiguration(Commands.SwitchToTab5, Key.D5),
new CommandBindingConfiguration(Commands.SwitchToTab6, Key.D6),
new CommandBindingConfiguration(Commands.SwitchToTab7, Key.D7),
new CommandBindingConfiguration(Commands.SwitchToTab8, Key.D8),
new CommandBindingConfiguration(Commands.TimelinePause, new[] { Key.T, Key.P }),
new CommandBindingConfiguration(Commands.TimelineRefresh, new[] { Key.T, Key.R }),
new CommandBindingConfiguration(Commands.TimelineStart, new[] { Key.T, Key.S }),
new CommandBindingConfiguration(Commands.ToggleAdvancedIcons, new[] { Key.Z, Key.I }),
new CommandBindingConfiguration(Commands.GoUp, Key.Left),
new CommandBindingConfiguration(Commands.Open, Key.Right),
new CommandBindingConfiguration(Commands.OpenOrRun, Key.Enter),
new CommandBindingConfiguration(Commands.MoveCursorUp, Key.Up),
new CommandBindingConfiguration(Commands.MoveCursorDown, Key.Down),
new CommandBindingConfiguration(Commands.MoveCursorUpPage, Key.PageUp),
new CommandBindingConfiguration(Commands.MoveCursorDownPage, Key.PageDown),
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.ShowAllShotcut, 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),
};
}

View File

@@ -8,7 +8,7 @@ public class CommandToCommandNameConverter : IValueConverter
{
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if(value is not Commands command) return value;
if(value is not Command command) return value;
//TODO: implement
return command.ToString();

View File

@@ -136,7 +136,7 @@ public class DefaultModeKeyInputHandler : IDefaultModeKeyInputHandler
}
}
private async Task CallCommandAsync(Commands command)
private async Task CallCommandAsync(Command command)
{
try
{

View File

@@ -23,7 +23,7 @@ public class KeyboardConfigurationService : IKeyboardConfigurationService
foreach (var keyBinding in keyBindings)
{
if (keyBinding.Command == Commands.None)
if (keyBinding.Command == Command.None)
{
throw new FormatException($"No command is set in keybinding for keys '{keyBinding.KeysDisplayText}'");
}
@@ -49,6 +49,6 @@ public class KeyboardConfigurationService : IKeyboardConfigurationService
private static bool IsUniversal(CommandBindingConfiguration keyMapping)
{
return keyMapping.Command is Commands.GoUp or Commands.Open or Commands.OpenOrRun or Commands.MoveCursorUp or Commands.MoveCursorDown or Commands.MoveCursorUpPage or Commands.MoveCursorDownPage;
return keyMapping.Command is Command.GoUp or Command.Open or Command.OpenOrRun or Command.MoveCursorUp or Command.MoveCursorDown or Command.MoveCursorUpPage or Command.MoveCursorDownPage;
}
}

View File

@@ -122,7 +122,7 @@ public class RapidTravelModeKeyInputHandler : IRapidTravelModeKeyInputHandler
}
}
private async Task CallCommandAsync(Commands command)
private async Task CallCommandAsync(Command command)
{
try
{