TextBox, PropertyChangeHandler

This commit is contained in:
2023-08-11 21:51:44 +02:00
parent e989a65e81
commit 1fde0df2d6
81 changed files with 1539 additions and 390 deletions

View File

@@ -1,18 +1,47 @@
using Avalonia.Input;
using FileTime.App.Core.Models;
using FileTime.App.Core.Services;
using GeneralInputKey;
namespace FileTime.GuiApp.App.Extensions;
public static class KeyEventArgsExtension
{
public static GeneralKeyEventArgs? ToGeneralKeyEventArgs(this KeyEventArgs args, IAppKeyService<Key> appKeyService)
public static GeneralKeyEventArgs? ToGeneralKeyEventArgs(
this KeyEventArgs args,
IAppKeyService<Key> appKeyService,
SpecialKeysStatus specialKeysStatus)
{
var maybeKey = appKeyService.MapKey(args.Key);
if (maybeKey is not {} key1) return null;
if (maybeKey is not { } key1) return null;
var keyString = args.Key.ToString();
return new GeneralKeyEventArgs(h => args.Handled = h)
{
Key = key1
Key = key1,
KeyChar = keyString.Length > 0 ? keyString[0] : '\0',
SpecialKeysStatus = specialKeysStatus
};
}
public static GeneralKeyEventArgs? ToGeneralKeyEventArgs(
this KeyEventArgs args,
IAppKeyService<Key> appKeyService,
KeyModifiers keyModifiers)
{
var maybeKey = appKeyService.MapKey(args.Key);
if (maybeKey is not { } key1) return null;
var keyString = args.Key.ToString();
return new GeneralKeyEventArgs(h => args.Handled = h)
{
Key = key1,
KeyChar = keyString.Length > 0 ? keyString[0] : '\0',
SpecialKeysStatus = new SpecialKeysStatus(
IsAltPressed: (keyModifiers & KeyModifiers.Alt) != 0,
IsShiftPressed: (keyModifiers & KeyModifiers.Shift) != 0,
IsCtrlPressed: (keyModifiers & KeyModifiers.Control) != 0
)
};
}
}

View File

@@ -2,6 +2,7 @@
using Avalonia.Input;
using FileTime.App.Core.Models;
using FileTime.App.Core.Services;
using GeneralInputKey;
namespace FileTime.GuiApp.App.Services;
@@ -71,6 +72,7 @@ public sealed class GuiAppKeyService : IAppKeyService<Key>
{Key.Enter, Keys.Enter},
{Key.Escape, Keys.Escape},
{Key.Back, Keys.Backspace},
{Key.Delete, Keys.Delete},
{Key.Space, Keys.Space},
{Key.PageUp, Keys.PageUp},
{Key.PageDown, Keys.PageDown},

View File

@@ -5,6 +5,7 @@ using FileTime.App.Core.Services;
using FileTime.GuiApp.App.Extensions;
using FileTime.GuiApp.App.Models;
using FileTime.GuiApp.App.ViewModels;
using GeneralInputKey;
namespace FileTime.GuiApp.App.Services;
@@ -50,9 +51,9 @@ public class KeyInputHandlerService : IKeyInputHandlerService
//_appState.NoCommandFound = false;
var isAltPressed = (e.KeyModifiers & KeyModifiers.Alt) == KeyModifiers.Alt;
var isShiftPressed = (e.KeyModifiers & KeyModifiers.Shift) == KeyModifiers.Shift;
var isCtrlPressed = (e.KeyModifiers & KeyModifiers.Control) == KeyModifiers.Control;
var isAltPressed = (e.KeyModifiers & KeyModifiers.Alt) != 0;
var isShiftPressed = (e.KeyModifiers & KeyModifiers.Shift) != 0;
var isCtrlPressed = (e.KeyModifiers & KeyModifiers.Control) != 0;
if (isCtrlPressed
&& e.Key is Key.Left or Key.Right or Key.Up or Key.Down
@@ -69,16 +70,16 @@ public class KeyInputHandlerService : IKeyInputHandlerService
{
if (_appState.ViewMode.Value == ViewMode.Default)
{
if (e.ToGeneralKeyEventArgs(_appKeyService) is { } args)
if (e.ToGeneralKeyEventArgs(_appKeyService, specialKeyStatus) is { } args)
{
await _defaultModeKeyInputHandler.HandleInputKey(args, specialKeyStatus);
await _defaultModeKeyInputHandler.HandleInputKey(args);
}
}
else
{
if (e.ToGeneralKeyEventArgs(_appKeyService) is { } args)
if (e.ToGeneralKeyEventArgs(_appKeyService, specialKeyStatus) is { } args)
{
await _rapidTravelModeKeyInputHandler.HandleInputKey(args, specialKeyStatus);
await _rapidTravelModeKeyInputHandler.HandleInputKey(args);
}
}
}

View File

@@ -39,7 +39,7 @@ public partial class CommandPalette : UserControl
}
else
{
if (e.ToGeneralKeyEventArgs(_appKeyService.Value) is not { } eventArgs) return;
if (e.ToGeneralKeyEventArgs(_appKeyService.Value, e.KeyModifiers) is not { } eventArgs) return;
viewModel.HandleKeyDown(eventArgs);
}
@@ -50,7 +50,7 @@ public partial class CommandPalette : UserControl
if (e.Handled
|| DataContext is not ICommandPaletteViewModel viewModel) return;
if (e.ToGeneralKeyEventArgs(_appKeyService.Value) is not { } eventArgs) return;
if (e.ToGeneralKeyEventArgs(_appKeyService.Value, e.KeyModifiers) is not { } eventArgs) return;
viewModel.HandleKeyUp(eventArgs);
}
}

View File

@@ -1,6 +1,7 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using FileTime.App.Core.Models;
using FileTime.App.Core.Services;
using FileTime.App.FrequencyNavigation.ViewModels;
using FileTime.GuiApp.App.Extensions;
@@ -39,7 +40,7 @@ public partial class FrequencyNavigation : UserControl
}
else
{
if (e.ToGeneralKeyEventArgs(_appKeyService.Value) is not { } eventArgs) return;
if (e.ToGeneralKeyEventArgs(_appKeyService.Value, e.KeyModifiers) is not { } eventArgs) return;
viewModel.HandleKeyDown(eventArgs);
}
@@ -50,7 +51,7 @@ public partial class FrequencyNavigation : UserControl
if (e.Handled
|| DataContext is not IFrequencyNavigationViewModel viewModel) return;
if (e.ToGeneralKeyEventArgs(_appKeyService.Value) is not { } eventArgs) return;
if (e.ToGeneralKeyEventArgs(_appKeyService.Value, e.KeyModifiers) is not { } eventArgs) return;
viewModel.HandleKeyUp(eventArgs);
}
}

View File

@@ -972,7 +972,7 @@
Background="{DynamicResource BarelyTransparentBackgroundColor}"
DataContext="{Binding FrequencyNavigationService.CurrentModal}"
HorizontalAlignment="Stretch"
IsVisible="{Binding ShowWindow^, FallbackValue=False}"
IsVisible="{Binding ShowWindow.Value, FallbackValue=False}"
VerticalAlignment="Stretch">
<Grid Background="{DynamicResource ContainerBackgroundColor}" Margin="100">
<local:FrequencyNavigation IsVisible="{Binding ShowWindow^, FallbackValue=False}" />
@@ -983,7 +983,7 @@
Background="{DynamicResource BarelyTransparentBackgroundColor}"
DataContext="{Binding CommandPaletteService.CurrentModal}"
HorizontalAlignment="Stretch"
IsVisible="{Binding ShowWindow^, FallbackValue=False}"
IsVisible="{Binding ShowWindow.Value, FallbackValue=False}"
VerticalAlignment="Stretch">
<Grid Background="{DynamicResource ContainerBackgroundColor}" Margin="100">
<local:CommandPalette IsVisible="{Binding ShowWindow^, FallbackValue=False}" />