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

@@ -40,8 +40,9 @@ public partial class CommandPaletteService : ICommandPaletteService
public IReadOnlyList<ICommandPaletteEntry> GetCommands() =>
_identifiableUserCommandService
.GetCommandIdentifiers()
.Select(c => new CommandPaletteEntry(c, c))
.IdentifiableUserCommands
.Select(c => new CommandPaletteEntry(c.Key, c.Value.Title))
.OrderBy(c => c.Title)
.ToList()
.AsReadOnly();
}

View File

@@ -41,9 +41,8 @@ public class CommandPaletteViewModel : FuzzyPanelViewModel<ICommandPaletteEntryV
|| c.Identifier.Contains(SearchText, StringComparison.OrdinalIgnoreCase)
)
.Select(c =>
(ICommandPaletteEntryViewModel) new CommandPaletteEntryViewModel(c.Identifier, c.Title))
.Take(30) // TODO remove magic number
.OrderBy(c => c.Title)
(ICommandPaletteEntryViewModel) new CommandPaletteEntryViewModel(c.Identifier, c.Title)
)
.ToList();
public override async Task<bool> HandleKeyDown(KeyEventArgs keyEventArgs)

View File

@@ -4,7 +4,8 @@ namespace FileTime.App.Core.Services;
public interface IIdentifiableUserCommandService
{
void AddIdentifiableUserCommandFactory(string identifier, Func<IIdentifiableUserCommand> commandFactory);
void AddIdentifiableUserCommandFactory(string identifier, IIdentifiableUserCommand commandFactory);
IIdentifiableUserCommand? GetCommand(string identifier);
IReadOnlyCollection<string> GetCommandIdentifiers();
IReadOnlyDictionary<string, IIdentifiableUserCommand> IdentifiableUserCommands { get; }
}

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);
}