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;
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
using FileTime.App.Core.Configuration;
|
||||
|
||||
namespace FileTime.App.Core.Services;
|
||||
|
||||
public interface ICommandKeysHelperService
|
||||
{
|
||||
List<List<KeyConfig>> GetKeysForCommand(string commandName);
|
||||
string GetKeyConfigsString(string commandIdentifier);
|
||||
string FormatKeyConfig(KeyConfig keyConfig);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using FileTime.App.Core.Configuration;
|
||||
|
||||
namespace FileTime.App.Core.Services;
|
||||
|
||||
public interface IPossibleCommandsService
|
||||
{
|
||||
ReadOnlyObservableCollection<CommandBindingConfiguration> PossibleCommands { get; set; }
|
||||
void Clear();
|
||||
void Add(CommandBindingConfiguration commandBindingConfiguration);
|
||||
void Remove(CommandBindingConfiguration commandBindingConfiguration);
|
||||
void AddRange(IEnumerable<CommandBindingConfiguration> commandBindingConfigurations);
|
||||
}
|
||||
@@ -16,7 +16,6 @@ public interface IAppState
|
||||
IDeclarativeProperty<string?> RapidTravelTextDebounced { get; }
|
||||
IDeclarativeProperty<string?> ContainerStatus { get; }
|
||||
List<KeyConfig> PreviousKeys { get; }
|
||||
List<CommandBindingConfiguration> PossibleCommands { get; set; }
|
||||
bool NoCommandFound { get; set; }
|
||||
|
||||
void AddTab(ITabViewModel tabViewModel);
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace FileTime.App.Core.ViewModels;
|
||||
|
||||
public interface IPossibleCommandEntryViewModel
|
||||
{
|
||||
public string CommandName { get; }
|
||||
public string Title { get; }
|
||||
public string KeysText { get; }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace FileTime.App.Core.ViewModels;
|
||||
|
||||
public interface IPossibleCommandsViewModel
|
||||
{
|
||||
ObservableCollection<IPossibleCommandEntryViewModel> PossibleCommands { get; }
|
||||
}
|
||||
@@ -30,6 +30,7 @@
|
||||
<ProjectReference Include="..\..\Core\FileTime.Core.Abstraction\FileTime.Core.Abstraction.csproj" />
|
||||
<ProjectReference Include="..\..\Core\FileTime.Core.Models\FileTime.Core.Models.csproj" />
|
||||
<ProjectReference Include="..\..\Library\Defer\Defer.csproj" />
|
||||
<ProjectReference Include="..\..\Library\ObservableComputations.Extensions\ObservableComputations.Extensions.csproj" />
|
||||
<ProjectReference Include="..\..\Providers\FileTime.Providers.Local.Abstractions\FileTime.Providers.Local.Abstractions.csproj" />
|
||||
<ProjectReference Include="..\..\Providers\FileTime.Providers.LocalAdmin.Abstractions\FileTime.Providers.LocalAdmin.Abstractions.csproj" />
|
||||
<ProjectReference Include="..\..\Tools\FileTime.Tools\FileTime.Tools.csproj" />
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -33,6 +33,9 @@ public static class Startup
|
||||
serviceCollection.TryAddSingleton<IDefaultModeKeyInputHandler, DefaultModeKeyInputHandler>();
|
||||
serviceCollection.TryAddSingleton<IRapidTravelModeKeyInputHandler, RapidTravelModeKeyInputHandler>();
|
||||
serviceCollection.TryAddSingleton<IKeyboardConfigurationService, KeyboardConfigurationService>();
|
||||
serviceCollection.TryAddSingleton<ICommandKeysHelperService, CommandKeysHelperService>();
|
||||
serviceCollection.TryAddSingleton<IPossibleCommandsService, PossibleCommandsService>();
|
||||
serviceCollection.TryAddSingleton<IPossibleCommandsViewModel, PossibleCommandsViewModel>();
|
||||
|
||||
return serviceCollection
|
||||
.AddCommandHandlers()
|
||||
|
||||
@@ -4,9 +4,7 @@ using System.Reactive.Subjects;
|
||||
using DeclarativeProperty;
|
||||
using FileTime.App.Core.Configuration;
|
||||
using FileTime.App.Core.Models.Enums;
|
||||
using FileTime.App.Core.ViewModels.Timeline;
|
||||
using FileTime.Core.Models.Extensions;
|
||||
using MvvmGen;
|
||||
using MoreLinq;
|
||||
using PropertyChanged.SourceGenerator;
|
||||
|
||||
@@ -31,7 +29,6 @@ public abstract partial class AppStateBase : IAppState
|
||||
|
||||
public IDeclarativeProperty<string?> ContainerStatus { get; }
|
||||
[Notify] public List<KeyConfig> PreviousKeys { get; } = new();
|
||||
[Notify] public List<CommandBindingConfiguration> PossibleCommands { get; set; } = new();
|
||||
[Notify] public bool NoCommandFound { get; set; }
|
||||
|
||||
protected AppStateBase()
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace FileTime.App.Core.ViewModels;
|
||||
|
||||
public record PossibleCommandEntryViewModel(
|
||||
string CommandName,
|
||||
string Title,
|
||||
string KeysText) : IPossibleCommandEntryViewModel;
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using FileTime.App.Core.Configuration;
|
||||
using FileTime.App.Core.Services;
|
||||
using ObservableComputations;
|
||||
|
||||
namespace FileTime.App.Core.ViewModels;
|
||||
|
||||
public class PossibleCommandsViewModel : IPossibleCommandsViewModel, IDisposable
|
||||
{
|
||||
private readonly IIdentifiableUserCommandService _identifiableUserCommandService;
|
||||
private readonly OcConsumer _ocConsumer = new();
|
||||
public ObservableCollection<IPossibleCommandEntryViewModel> PossibleCommands { get; }
|
||||
|
||||
public PossibleCommandsViewModel(
|
||||
IPossibleCommandsService possibleCommandsService,
|
||||
IIdentifiableUserCommandService identifiableUserCommandService)
|
||||
{
|
||||
_identifiableUserCommandService = identifiableUserCommandService;
|
||||
PossibleCommands = possibleCommandsService
|
||||
.PossibleCommands
|
||||
.Selecting(c => CreatePossibleCommandViewModel(c))
|
||||
.For(_ocConsumer);
|
||||
}
|
||||
|
||||
private IPossibleCommandEntryViewModel CreatePossibleCommandViewModel(CommandBindingConfiguration commandBindingConfiguration)
|
||||
{
|
||||
var commandName = commandBindingConfiguration.Command;
|
||||
var title = _identifiableUserCommandService.GetCommand(commandName)?.Title ?? commandName;
|
||||
return new PossibleCommandEntryViewModel(
|
||||
CommandName: commandName,
|
||||
Title: title,
|
||||
KeysText: commandBindingConfiguration.GetKeysDisplayText());
|
||||
}
|
||||
|
||||
public void Dispose() => _ocConsumer.Dispose();
|
||||
}
|
||||
Reference in New Issue
Block a user