Console upgrades, PossibleCommands VM
This commit is contained in:
@@ -14,7 +14,7 @@ public class CommandPaletteViewModel : FuzzyPanelViewModel<ICommandPaletteEntryV
|
||||
private readonly ICommandPaletteService _commandPaletteService;
|
||||
private readonly IIdentifiableUserCommandService _identifiableUserCommandService;
|
||||
private readonly IUserCommandHandlerService _userCommandHandlerService;
|
||||
private readonly IKeyboardConfigurationService _keyboardConfigurationService;
|
||||
private readonly ICommandKeysHelperService _commandKeysHelperService;
|
||||
private readonly ILogger<CommandPaletteViewModel> _logger;
|
||||
string IModalViewModel.Name => "CommandPalette";
|
||||
|
||||
@@ -22,14 +22,14 @@ public class CommandPaletteViewModel : FuzzyPanelViewModel<ICommandPaletteEntryV
|
||||
ICommandPaletteService commandPaletteService,
|
||||
IIdentifiableUserCommandService identifiableUserCommandService,
|
||||
IUserCommandHandlerService userCommandHandlerService,
|
||||
IKeyboardConfigurationService keyboardConfigurationService,
|
||||
ICommandKeysHelperService commandKeysHelperService,
|
||||
ILogger<CommandPaletteViewModel> logger)
|
||||
: base((a, b) => a.Identifier == b.Identifier)
|
||||
{
|
||||
_commandPaletteService = commandPaletteService;
|
||||
_identifiableUserCommandService = identifiableUserCommandService;
|
||||
_userCommandHandlerService = userCommandHandlerService;
|
||||
_keyboardConfigurationService = keyboardConfigurationService;
|
||||
_commandKeysHelperService = commandKeysHelperService;
|
||||
_logger = logger;
|
||||
ShowWindow = _commandPaletteService.ShowWindow;
|
||||
UpdateFilteredMatchesInternal();
|
||||
@@ -47,47 +47,10 @@ public class CommandPaletteViewModel : FuzzyPanelViewModel<ICommandPaletteEntryV
|
||||
|| c.Identifier.Contains(SearchText, StringComparison.OrdinalIgnoreCase)
|
||||
)
|
||||
.Select(c =>
|
||||
(ICommandPaletteEntryViewModel) new CommandPaletteEntryViewModel(c.Identifier, c.Title, GetKeyConfigsString(c.Identifier))
|
||||
(ICommandPaletteEntryViewModel) new CommandPaletteEntryViewModel(c.Identifier, c.Title, _commandKeysHelperService.GetKeyConfigsString(c.Identifier))
|
||||
)
|
||||
.ToList();
|
||||
|
||||
private string GetKeyConfigsString(string commandIdentifier)
|
||||
{
|
||||
var keyConfigs = GetKeyConfigsForCommand(commandIdentifier);
|
||||
if (keyConfigs.Count == 0) return string.Empty;
|
||||
|
||||
return string.Join(
|
||||
" ; ",
|
||||
keyConfigs
|
||||
.Select(ks =>
|
||||
string.Join(
|
||||
", ",
|
||||
ks.Select(FormatKeyConfig)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private string FormatKeyConfig(KeyConfig keyConfig)
|
||||
{
|
||||
var stringBuilder = new StringBuilder();
|
||||
|
||||
if (keyConfig.Ctrl) stringBuilder.Append("Ctrl + ");
|
||||
if (keyConfig.Shift) stringBuilder.Append("Shift + ");
|
||||
if (keyConfig.Alt) stringBuilder.Append("Alt + ");
|
||||
|
||||
stringBuilder.Append(keyConfig.Key.ToString());
|
||||
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
private List<List<KeyConfig>> GetKeyConfigsForCommand(string commandIdentifier)
|
||||
=> _keyboardConfigurationService
|
||||
.AllShortcut
|
||||
.Where(s => s.Command == commandIdentifier)
|
||||
.Select(k => k.Keys)
|
||||
.ToList();
|
||||
|
||||
public override async Task<bool> HandleKeyDown(GeneralKeyEventArgs keyEventArgs)
|
||||
{
|
||||
if (keyEventArgs.Handled) return false;
|
||||
|
||||
Reference in New Issue
Block a user