Command palette with Title, style

This commit is contained in:
2023-07-29 16:01:25 +02:00
parent 604294fd2a
commit 05301f09c8
7 changed files with 77 additions and 39 deletions

View File

@@ -4,9 +4,15 @@ namespace FileTime.App.Core.Services.UserCommandHandler;
public class IdentifiableUserCommandService : IIdentifiableUserCommandService
{
private readonly Dictionary<string, Func<IIdentifiableUserCommand>> _identifiableUserCommands = new();
private readonly Dictionary<string, IIdentifiableUserCommand> _identifiableUserCommands = new();
public IReadOnlyDictionary<string, IIdentifiableUserCommand> IdentifiableUserCommands { get; }
public void AddIdentifiableUserCommandFactory(string identifier, Func<IIdentifiableUserCommand> commandFactory)
public IdentifiableUserCommandService()
{
IdentifiableUserCommands = _identifiableUserCommands.AsReadOnly();
}
public void AddIdentifiableUserCommandFactory(string identifier, IIdentifiableUserCommand commandFactory)
=> _identifiableUserCommands.Add(identifier, commandFactory);
public IIdentifiableUserCommand? GetCommand(string identifier)
@@ -15,7 +21,7 @@ public class IdentifiableUserCommandService : IIdentifiableUserCommandService
if (!_identifiableUserCommands.ContainsKey(identifier))
throw new IndexOutOfRangeException($"No command factory is registered for command {identifier}");
return _identifiableUserCommands[identifier].Invoke();
return _identifiableUserCommands[identifier];
}
public IReadOnlyCollection<string> GetCommandIdentifiers() => _identifiableUserCommands.Keys.ToList();

View File

@@ -68,5 +68,5 @@ public class DefaultIdentifiableCommandHandlerRegister : IStartupHandler
public Task InitAsync() => Task.CompletedTask;
private void AddUserCommand(IIdentifiableUserCommand command)
=> _userCommandHandlerService.AddIdentifiableUserCommandFactory(command.UserCommandID, () => command);
=> _userCommandHandlerService.AddIdentifiableUserCommandFactory(command.UserCommandID, command);
}