Console upgrades, PossibleCommands VM

This commit is contained in:
2023-08-10 22:54:52 +02:00
parent 96d4eb926d
commit e989a65e81
48 changed files with 983 additions and 400 deletions

View File

@@ -0,0 +1,52 @@
using System.Text;
using FileTime.App.Core.Configuration;
namespace FileTime.App.Core.Services;
public class CommandKeysHelperService : ICommandKeysHelperService
{
private readonly IKeyboardConfigurationService _keyboardConfigurationService;
public CommandKeysHelperService(IKeyboardConfigurationService keyboardConfigurationService)
{
_keyboardConfigurationService = keyboardConfigurationService;
}
public List<List<KeyConfig>> GetKeysForCommand(string commandName)
=> _keyboardConfigurationService
.AllShortcut
.Where(s => s.Command == commandName)
.Select(k => k.Keys)
.ToList();
public string GetKeyConfigsString(string commandIdentifier)
{
var keyConfigs = GetKeysForCommand(commandIdentifier);
if (keyConfigs.Count == 0) return string.Empty;
return string.Join(
" ; ",
keyConfigs
.Select(ks =>
string.Join(
", ",
ks.Select(FormatKeyConfig)
)
)
);
}
public 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();
}
}

View File

@@ -21,6 +21,7 @@ public class DefaultModeKeyInputHandler : IDefaultModeKeyInputHandler
private readonly ILogger<DefaultModeKeyInputHandler> _logger;
private readonly IUserCommandHandlerService _userCommandHandlerService;
private readonly IIdentifiableUserCommandService _identifiableUserCommandService;
private readonly IPossibleCommandsService _possibleCommandsService;
private readonly BindedCollection<IModalViewModel> _openModals;
public DefaultModeKeyInputHandler(
@@ -29,10 +30,12 @@ public class DefaultModeKeyInputHandler : IDefaultModeKeyInputHandler
IKeyboardConfigurationService keyboardConfigurationService,
ILogger<DefaultModeKeyInputHandler> logger,
IUserCommandHandlerService userCommandHandlerService,
IIdentifiableUserCommandService identifiableUserCommandService)
IIdentifiableUserCommandService identifiableUserCommandService,
IPossibleCommandsService possibleCommandsService)
{
_appState = appState;
_identifiableUserCommandService = identifiableUserCommandService;
_possibleCommandsService = possibleCommandsService;
_keyboardConfigurationService = keyboardConfigurationService;
_logger = logger;
_modalService = modalService;
@@ -99,7 +102,7 @@ public class DefaultModeKeyInputHandler : IDefaultModeKeyInputHandler
{
args.Handled = true;
_appState.PreviousKeys.Clear();
_appState.PossibleCommands = new();
_possibleCommandsService.Clear();
}
}
/*else if (key == Key.Enter
@@ -113,7 +116,7 @@ public class DefaultModeKeyInputHandler : IDefaultModeKeyInputHandler
{
args.Handled = true;
_appState.PreviousKeys.Clear();
_appState.PossibleCommands = new();
_possibleCommandsService.Clear();
var command = _identifiableUserCommandService.GetCommand(selectedCommandBinding.Command);
if (command is not null)
{
@@ -123,7 +126,7 @@ public class DefaultModeKeyInputHandler : IDefaultModeKeyInputHandler
else if (_keysToSkip.Any(k => k.AreKeysEqual(_appState.PreviousKeys)))
{
_appState.PreviousKeys.Clear();
_appState.PossibleCommands = new();
_possibleCommandsService.Clear();
return;
}
else if (_appState.PreviousKeys.Count == 2)
@@ -131,7 +134,7 @@ public class DefaultModeKeyInputHandler : IDefaultModeKeyInputHandler
args.Handled = true;
_appState.NoCommandFound = true;
_appState.PreviousKeys.Clear();
_appState.PossibleCommands = new();
_possibleCommandsService.Clear();
}
else
{
@@ -145,7 +148,8 @@ public class DefaultModeKeyInputHandler : IDefaultModeKeyInputHandler
}
else
{
_appState.PossibleCommands = possibleCommands;
_possibleCommandsService.Clear();
_possibleCommandsService.AddRange(possibleCommands);
}
}
}

View File

@@ -0,0 +1,31 @@
using System.Collections.ObjectModel;
using FileTime.App.Core.Configuration;
namespace FileTime.App.Core.Services;
public class PossibleCommandsService : IPossibleCommandsService
{
private readonly ObservableCollection<CommandBindingConfiguration> _possibleCommands = new();
public ReadOnlyObservableCollection<CommandBindingConfiguration> PossibleCommands { get; set; }
public PossibleCommandsService()
{
PossibleCommands = new ReadOnlyObservableCollection<CommandBindingConfiguration>(_possibleCommands);
}
public void Clear() => _possibleCommands.Clear();
public void Add(CommandBindingConfiguration commandBindingConfiguration)
=> _possibleCommands.Add(commandBindingConfiguration);
public void AddRange(IEnumerable<CommandBindingConfiguration> commandBindingConfigurations)
{
foreach (var commandBindingConfiguration in commandBindingConfigurations)
{
_possibleCommands.Add(commandBindingConfiguration);
}
}
public void Remove(CommandBindingConfiguration commandBindingConfiguration)
=> _possibleCommands.Remove(commandBindingConfiguration);
}