InputHandler, CreateContainer user command
This commit is contained in:
@@ -54,8 +54,8 @@ public class DefaultModeKeyInputHandler : IDefaultModeKeyInputHandler
|
||||
var keyWithModifiers = new KeyConfig(key, shift: specialKeysStatus.IsShiftPressed, alt: specialKeysStatus.IsAltPressed, ctrl: specialKeysStatus.IsCtrlPressed);
|
||||
_appState.PreviousKeys.Add(keyWithModifiers);
|
||||
|
||||
var selectedCommandBinding = _keyboardConfigurationService.UniversalCommandBindings.Values.FirstOrDefault(c => c.Keys.AreKeysEqual(_appState.PreviousKeys));
|
||||
selectedCommandBinding ??= _keyboardConfigurationService.CommandBindings.Values.FirstOrDefault(c => c.Keys.AreKeysEqual(_appState.PreviousKeys));
|
||||
var selectedCommandBinding = _keyboardConfigurationService.UniversalCommandBindings.FirstOrDefault(c => c.Keys.AreKeysEqual(_appState.PreviousKeys));
|
||||
selectedCommandBinding ??= _keyboardConfigurationService.CommandBindings.FirstOrDefault(c => c.Keys.AreKeysEqual(_appState.PreviousKeys));
|
||||
|
||||
if (key == Key.Escape)
|
||||
{
|
||||
@@ -125,7 +125,7 @@ public class DefaultModeKeyInputHandler : IDefaultModeKeyInputHandler
|
||||
else
|
||||
{
|
||||
setHandled(true);
|
||||
var possibleCommands = _keyboardConfigurationService.AllShortcut.Values.Where(c => c.Keys[0].AreEquals(keyWithModifiers)).ToList();
|
||||
var possibleCommands = _keyboardConfigurationService.AllShortcut.Where(c => c.Keys[0].AreEquals(keyWithModifiers)).ToList();
|
||||
|
||||
if (possibleCommands.Count == 0)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
using System.Reactive.Linq;
|
||||
using DynamicData;
|
||||
using FileTime.App.Core.Services;
|
||||
using FileTime.Core.Interactions;
|
||||
using FileTime.GuiApp.ViewModels;
|
||||
|
||||
namespace FileTime.GuiApp.Services;
|
||||
|
||||
public class DialogService : IDialogService
|
||||
{
|
||||
private readonly IModalService _modalService;
|
||||
|
||||
public IObservable<ReadInputsViewModel?> ReadInput { get; }
|
||||
|
||||
public DialogService(IModalService modalService)
|
||||
{
|
||||
_modalService = modalService;
|
||||
ReadInput = modalService
|
||||
.OpenModals
|
||||
.ToCollection()
|
||||
.Select(modals =>
|
||||
(ReadInputsViewModel?)modals.FirstOrDefault(m => m is ReadInputsViewModel)
|
||||
)
|
||||
.Publish(null)
|
||||
.RefCount();
|
||||
}
|
||||
|
||||
public void ReadInputs(IEnumerable<IInputElement> inputs, Action inputHandler, Action? cancelHandler = null)
|
||||
{
|
||||
var modalViewModel = new ReadInputsViewModel(HandleReadInputsSuccess, HandleReadInputsCancel)
|
||||
{
|
||||
Inputs = inputs.ToList(),
|
||||
SuccessHandler = inputHandler,
|
||||
CancelHandler = cancelHandler
|
||||
};
|
||||
|
||||
_modalService.OpenModal(modalViewModel);
|
||||
}
|
||||
|
||||
private void HandleReadInputsSuccess(ReadInputsViewModel readInputsViewModel)
|
||||
{
|
||||
_modalService.CloseModal(readInputsViewModel);
|
||||
readInputsViewModel.SuccessHandler.Invoke();
|
||||
}
|
||||
|
||||
private void HandleReadInputsCancel(ReadInputsViewModel readInputsViewModel)
|
||||
{
|
||||
_modalService.CloseModal(readInputsViewModel);
|
||||
readInputsViewModel.CancelHandler?.Invoke();
|
||||
}
|
||||
|
||||
public Task<bool> ReadInputs(IEnumerable<IInputElement> fields)
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
ReadInputs(fields, () => taskCompletionSource.SetResult(true), () => taskCompletionSource.SetResult(false));
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
}
|
||||
@@ -6,14 +6,12 @@ namespace FileTime.GuiApp.Services;
|
||||
|
||||
public class KeyboardConfigurationService : IKeyboardConfigurationService
|
||||
{
|
||||
public IReadOnlyDictionary<string, CommandBindingConfiguration> CommandBindings { get; }
|
||||
public IReadOnlyDictionary<string, CommandBindingConfiguration> UniversalCommandBindings { get; }
|
||||
public IReadOnlyDictionary<string, CommandBindingConfiguration> AllShortcut { get; }
|
||||
public IReadOnlyList<CommandBindingConfiguration> CommandBindings { get; }
|
||||
public IReadOnlyList<CommandBindingConfiguration> UniversalCommandBindings { get; }
|
||||
public IReadOnlyList<CommandBindingConfiguration> AllShortcut { get; }
|
||||
|
||||
public KeyboardConfigurationService(IOptions<KeyBindingConfiguration> keyBindingConfiguration)
|
||||
{
|
||||
var commandBindings = new Dictionary<string, CommandBindingConfiguration>();
|
||||
var universalCommandBindings = new Dictionary<string, CommandBindingConfiguration>();
|
||||
IEnumerable<CommandBindingConfiguration> keyBindings = keyBindingConfiguration.Value.KeyBindings;
|
||||
|
||||
if (keyBindingConfiguration.Value.UseDefaultBindings)
|
||||
@@ -21,6 +19,8 @@ public class KeyboardConfigurationService : IKeyboardConfigurationService
|
||||
keyBindings = keyBindings.Concat(keyBindingConfiguration.Value.DefaultKeyBindings);
|
||||
}
|
||||
|
||||
var commandBindings = new List<CommandBindingConfiguration>();
|
||||
var universalCommandBindings = new List<CommandBindingConfiguration>();
|
||||
foreach (var keyBinding in keyBindings)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(keyBinding.Command))
|
||||
@@ -34,17 +34,17 @@ public class KeyboardConfigurationService : IKeyboardConfigurationService
|
||||
|
||||
if (IsUniversal(keyBinding))
|
||||
{
|
||||
universalCommandBindings.Add(keyBinding.Command, keyBinding);
|
||||
universalCommandBindings.Add(keyBinding);
|
||||
}
|
||||
else
|
||||
{
|
||||
commandBindings.Add(keyBinding.Command, keyBinding);
|
||||
commandBindings.Add(keyBinding);
|
||||
}
|
||||
}
|
||||
|
||||
CommandBindings = new ReadOnlyDictionary<string, CommandBindingConfiguration>(commandBindings);
|
||||
UniversalCommandBindings = new ReadOnlyDictionary<string, CommandBindingConfiguration>(universalCommandBindings);
|
||||
AllShortcut = new ReadOnlyDictionary<string, CommandBindingConfiguration>(new Dictionary<string, CommandBindingConfiguration>(CommandBindings.Concat(UniversalCommandBindings)));
|
||||
CommandBindings = commandBindings.AsReadOnly();
|
||||
UniversalCommandBindings = universalCommandBindings.AsReadOnly();
|
||||
AllShortcut = new List<CommandBindingConfiguration>(UniversalCommandBindings.Concat(CommandBindings)).AsReadOnly();
|
||||
}
|
||||
|
||||
private static bool IsUniversal(CommandBindingConfiguration keyMapping)
|
||||
|
||||
@@ -80,7 +80,7 @@ public class RapidTravelModeKeyInputHandler : IRapidTravelModeKeyInputHandler
|
||||
else
|
||||
{
|
||||
var currentKeyAsList = new List<KeyConfig>() {new KeyConfig(key)};
|
||||
var selectedCommandBinding = _keyboardConfigurationService.UniversalCommandBindings.Values.FirstOrDefault(c => c.Keys.AreKeysEqual(currentKeyAsList));
|
||||
var selectedCommandBinding = _keyboardConfigurationService.UniversalCommandBindings.FirstOrDefault(c => c.Keys.AreKeysEqual(currentKeyAsList));
|
||||
if (selectedCommandBinding != null)
|
||||
{
|
||||
setHandled(true);
|
||||
|
||||
Reference in New Issue
Block a user