Command refactor

This commit is contained in:
2022-05-15 21:42:01 +02:00
parent 9a99aad030
commit f99f90783f
42 changed files with 544 additions and 217 deletions

View File

@@ -0,0 +1,8 @@
namespace FileTime.App.Core.Models.Enums;
public enum PasteMode
{
Merge,
Overwrite,
Skip
}

View File

@@ -1,9 +0,0 @@
using FileTime.App.Core.Command;
namespace FileTime.App.Core.Services;
public interface ICommandHandler
{
bool CanHandleCommand(Command.Command command);
Task HandleCommandAsync(Command.Command command);
}

View File

@@ -1,8 +0,0 @@
using FileTime.App.Core.Command;
namespace FileTime.App.Core.Services;
public interface ICommandHandlerService
{
Task HandleCommandAsync(Command.Command command);
}

View File

@@ -0,0 +1,9 @@
using FileTime.App.Core.UserCommand;
namespace FileTime.App.Core.Services;
public interface IIdentifiableUserCommandService
{
void AddIdentifiableUserCommandFactory(string identifier, Func<IIdentifiableUserCommand> commandFactory);
IIdentifiableUserCommand GetCommand(string identifier);
}

View File

@@ -0,0 +1,9 @@
using FileTime.App.Core.UserCommand;
namespace FileTime.App.Core.Services;
public interface IUserCommandHandler
{
bool CanHandleCommand(IUserCommand command);
Task HandleCommandAsync(IUserCommand command);
}

View File

@@ -0,0 +1,7 @@
namespace FileTime.App.Core.Services;
public interface IUserCommandHandlerService
{
Task HandleCommandAsync(UserCommand.IUserCommand command);
Task HandleCommandAsync<TCommand>() where TCommand : UserCommand.IUserCommand, new();
}

View File

@@ -0,0 +1,13 @@
namespace FileTime.App.Core.UserCommand;
public class CloseTabCommand : IIdentifiableUserCommand
{
public const string CommandName = "close_tab";
public static CloseTabCommand Instance { get; } = new CloseTabCommand();
private CloseTabCommand()
{
}
public string UserCommandID => CommandName;
}

View File

@@ -0,0 +1,13 @@
namespace FileTime.App.Core.UserCommand;
public class CopyCommand : IIdentifiableUserCommand
{
public const string CommandName = "copy";
public static CopyCommand Instance { get; } = new CopyCommand();
private CopyCommand()
{
}
public string UserCommandID => CommandName;
}

View File

@@ -0,0 +1,13 @@
namespace FileTime.App.Core.UserCommand;
public class EnterRapidTravelCommand : IIdentifiableUserCommand
{
public const string CommandName = "exter_rapid_travel_mode";
public static EnterRapidTravelCommand Instance { get; } = new EnterRapidTravelCommand();
private EnterRapidTravelCommand()
{
}
public string UserCommandID => CommandName;
}

View File

@@ -0,0 +1,13 @@
namespace FileTime.App.Core.UserCommand;
public class ExitRapidTravelCommand : IIdentifiableUserCommand
{
public const string CommandName = "exit_rapid_travel_mode";
public static ExitRapidTravelCommand Instance { get; } = new ExitRapidTravelCommand();
private ExitRapidTravelCommand()
{
}
public string UserCommandID => CommandName;
}

View File

@@ -0,0 +1,13 @@
namespace FileTime.App.Core.UserCommand;
public class GoUpCommand : IIdentifiableUserCommand
{
public const string CommandName = "go_up";
public static GoUpCommand Instance { get; } = new GoUpCommand();
private GoUpCommand()
{
}
public string UserCommandID => CommandName;
}

View File

@@ -0,0 +1,6 @@
namespace FileTime.App.Core.UserCommand;
public interface IIdentifiableUserCommand : IUserCommand
{
string UserCommandID { get; }
}

View File

@@ -1,6 +1,11 @@
namespace FileTime.App.Core.Command;
namespace FileTime.App.Core.UserCommand;
public enum Command
public interface IUserCommand
{
}
/*public enum Command
{
None,
@@ -63,4 +68,4 @@ public enum Command
TimelineStart,
ToggleAdvancedIcons,
ToggleHidden,
}
}*/

View File

@@ -0,0 +1,13 @@
namespace FileTime.App.Core.UserCommand;
public class MarkCommand : IIdentifiableUserCommand
{
public const string CommandName = "mark_selected";
public static MarkCommand Instance { get; } = new MarkCommand();
private MarkCommand()
{
}
public string UserCommandID => CommandName;
}

View File

@@ -0,0 +1,13 @@
namespace FileTime.App.Core.UserCommand;
public class MoveCursorDownCommand : IIdentifiableUserCommand
{
public const string CommandName = "move_cursor_down";
public static MoveCursorDownCommand Instance { get; } = new MoveCursorDownCommand();
private MoveCursorDownCommand()
{
}
public string UserCommandID => CommandName;
}

View File

@@ -0,0 +1,13 @@
namespace FileTime.App.Core.UserCommand;
public class MoveCursorUpCommand : IIdentifiableUserCommand
{
public const string CommandName = "move_cursor_up";
public static MoveCursorUpCommand Instance { get; } = new MoveCursorUpCommand();
private MoveCursorUpCommand()
{
}
public string UserCommandID => CommandName;
}

View File

@@ -0,0 +1,13 @@
using FileTime.Core.Models;
namespace FileTime.App.Core.UserCommand;
public class OpenContainerCommand : IUserCommand
{
public IAbsolutePath Path { get; }
private OpenContainerCommand(IAbsolutePath path)
{
Path = path;
}
}

View File

@@ -0,0 +1,13 @@
namespace FileTime.App.Core.UserCommand;
public class OpenSelectedCommand : IIdentifiableUserCommand
{
public const string CommandName = "open_selected";
public static OpenSelectedCommand Instance { get; } = new OpenSelectedCommand();
private OpenSelectedCommand()
{
}
public string UserCommandID => CommandName;
}

View File

@@ -0,0 +1,24 @@
using FileTime.App.Core.Models.Enums;
namespace FileTime.App.Core.UserCommand;
public class PasteCommand : IIdentifiableUserCommand
{
public const string PasteMergeCommandName = "paste_merge";
public const string PasteOverwriteCommandName = "paste_overwrite";
public const string PasteSkipCommandName = "paste_skip";
public static PasteCommand Merge { get; } = new PasteCommand(PasteMode.Merge, PasteMergeCommandName);
public static PasteCommand Overwrite { get; } = new PasteCommand(PasteMode.Overwrite, PasteOverwriteCommandName);
public static PasteCommand Skip { get; } = new PasteCommand(PasteMode.Skip, PasteSkipCommandName);
public PasteMode PasteMode { get; }
private PasteCommand(PasteMode pasteMode, string commandName)
{
PasteMode = pasteMode;
UserCommandID = commandName;
}
public string UserCommandID { get; }
}

View File

@@ -0,0 +1,34 @@
namespace FileTime.App.Core.UserCommand;
public class SwitchToTabCommand : IIdentifiableUserCommand
{
private const string SwitchToTabBase = "switch_to_tab";
public const string SwitchToTab1CommandName = SwitchToTabBase + "1";
public const string SwitchToTab2CommandName = SwitchToTabBase + "2";
public const string SwitchToTab3CommandName = SwitchToTabBase + "3";
public const string SwitchToTab4CommandName = SwitchToTabBase + "4";
public const string SwitchToTab5CommandName = SwitchToTabBase + "5";
public const string SwitchToTab6CommandName = SwitchToTabBase + "6";
public const string SwitchToTab7CommandName = SwitchToTabBase + "7";
public const string SwitchToTab8CommandName = SwitchToTabBase + "8";
public const string SwitchToLastTabCommandName = "switch_to_last_tab";
public static SwitchToTabCommand SwitchToTab1 { get; } = new(1, SwitchToTab1CommandName);
public static SwitchToTabCommand SwitchToTab2 { get; } = new(2, SwitchToTab2CommandName);
public static SwitchToTabCommand SwitchToTab3 { get; } = new(3, SwitchToTab3CommandName);
public static SwitchToTabCommand SwitchToTab4 { get; } = new(4, SwitchToTab4CommandName);
public static SwitchToTabCommand SwitchToTab5 { get; } = new(5, SwitchToTab5CommandName);
public static SwitchToTabCommand SwitchToTab6 { get; } = new(6, SwitchToTab6CommandName);
public static SwitchToTabCommand SwitchToTab7 { get; } = new(7, SwitchToTab7CommandName);
public static SwitchToTabCommand SwitchToTab8 { get; } = new(8, SwitchToTab8CommandName);
public static SwitchToTabCommand SwitchToLastTab { get; } = new(-1, SwitchToLastTabCommandName);
private SwitchToTabCommand(int tabNumber, string commandName)
{
TabNumber = tabNumber;
UserCommandID = commandName;
}
public string UserCommandID { get; }
public int TabNumber { get; }
}