Profile editor - Added back hotkeys for the tools

Profile editor - Fixed hotkeys not always working
This commit is contained in:
Robert committed 2023-10-07 20:12:35 +02:00
1 parent f985682e78
commit 543b62a715
16 files changed
+106 -38

No files matched your search

@@ -58,7 +58,7 @@ public class MenuBarViewModel : ActivatableViewModelBase
_focusNone = profileEditorService.FocusMode.Select(f => f == ProfileEditorFocusMode.None).ToProperty(this, vm => vm.FocusNone).DisposeWith(d);
_focusFolder = profileEditorService.FocusMode.Select(f => f == ProfileEditorFocusMode.Folder).ToProperty(this, vm => vm.FocusFolder).DisposeWith(d);
_focusSelection = profileEditorService.FocusMode.Select(f => f == ProfileEditorFocusMode.Selection).ToProperty(this, vm => vm.FocusSelection).DisposeWith(d);
_keyBindingsEnabled = Shared.UI.KeyBindingsEnabled.ToProperty(this, vm => vm.KeyBindingsEnabled).DisposeWith(d);
_keyBindingsEnabled = Shared.UI.CurrentKeyBindingsEnabled.ToProperty(this, vm => vm.KeyBindingsEnabled).DisposeWith(d);
});
AddFolder = ReactiveCommand.Create(ExecuteAddFolder);
@@ -53,7 +53,7 @@ public class PlaybackViewModel : ActivatableViewModelBase
_currentTime = _profileEditorService.Time.ToProperty(this, vm => vm.CurrentTime).DisposeWith(d);
_formattedCurrentTime = _profileEditorService.Time.Select(t => $"{Math.Floor(t.TotalSeconds):00}.{t.Milliseconds:000}").ToProperty(this, vm => vm.FormattedCurrentTime).DisposeWith(d);
_playing = _profileEditorService.Playing.ToProperty(this, vm => vm.Playing).DisposeWith(d);
_keyBindingsEnabled = Shared.UI.KeyBindingsEnabled.ToProperty(this, vm => vm.KeyBindingsEnabled).DisposeWith(d);
_keyBindingsEnabled = Shared.UI.CurrentKeyBindingsEnabled.ToProperty(this, vm => vm.KeyBindingsEnabled).DisposeWith(d);
// Update timer
Timer updateTimer = new(TimeSpan.FromMilliseconds(60.0 / 1000));
@@ -46,7 +46,7 @@ public class ProfileTreeViewModel : TreeItemViewModel
_focusNone = profileEditorService.FocusMode.Select(f => f == ProfileEditorFocusMode.None).ToProperty(this, vm => vm.FocusNone).DisposeWith(d);
_focusFolder = profileEditorService.FocusMode.Select(f => f == ProfileEditorFocusMode.Folder).ToProperty(this, vm => vm.FocusFolder).DisposeWith(d);
_focusSelection = profileEditorService.FocusMode.Select(f => f == ProfileEditorFocusMode.Selection).ToProperty(this, vm => vm.FocusSelection).DisposeWith(d);
_keyBindingsEnabled = Shared.UI.KeyBindingsEnabled.ToProperty(this, vm => vm.KeyBindingsEnabled).DisposeWith(d);
_keyBindingsEnabled = Shared.UI.CurrentKeyBindingsEnabled.ToProperty(this, vm => vm.KeyBindingsEnabled).DisposeWith(d);
});
ClearSelection = ReactiveCommand.Create(() => profileEditorService.ChangeCurrentProfileElement(null), this.WhenAnyValue(vm => vm.KeyBindingsEnabled));
@@ -7,6 +7,7 @@ using Artemis.Core;
using Artemis.Core.Services;
using Artemis.UI.Shared.Services.ProfileEditor;
using Artemis.UI.Shared.Services.ProfileEditor.Commands;
using Avalonia.Input;
using Material.Icons;
using ReactiveUI;
using SkiaSharp;
@@ -45,9 +46,12 @@ public class SelectionAddToolViewModel : ToolViewModel
/// <inheritdoc />
public override MaterialIconKind Icon => MaterialIconKind.SelectionDrag;
/// <inheritdoc />
public override Hotkey? Hotkey { get; } = new(KeyboardKey.OemPlus, KeyboardModifierKey.Control);
/// <inheritdoc />
public override string ToolTip => "Add LEDs to the current layer";
public override string ToolTip => "Add LEDs to the current layer (Ctrl + +)";
public void AddLedsInRectangle(SKRect rect, bool expand, bool inverse)
{
@@ -4,8 +4,10 @@ using System.Linq;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using Artemis.Core;
using Artemis.Core.Services;
using Artemis.UI.Shared.Services.ProfileEditor;
using Artemis.UI.Shared.Services.ProfileEditor.Commands;
using Avalonia.Input;
using Material.Icons;
using ReactiveUI;
using SkiaSharp;
@@ -38,12 +40,15 @@ public class SelectionRemoveToolViewModel : ToolViewModel
/// <inheritdoc />
public override int Order => 3;
/// <inheritdoc />
public override Hotkey? Hotkey { get; } = new(KeyboardKey.OemMinus, KeyboardModifierKey.Control);
/// <inheritdoc />
public override MaterialIconKind Icon => MaterialIconKind.SelectOff;
/// <inheritdoc />
public override string ToolTip => "Remove LEDs from the current layer";
public override string ToolTip => "Remove LEDs from the current layer (Ctrl + -)";
public void RemoveLedsInRectangle(SKRect rect)
{
@@ -3,11 +3,13 @@ using System.Reactive;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using Artemis.Core;
using Artemis.Core.Services;
using Artemis.UI.Exceptions;
using Artemis.UI.Shared.Extensions;
using Artemis.UI.Shared.Services.ProfileEditor;
using Artemis.UI.Shared.Services.ProfileEditor.Commands;
using Avalonia;
using Avalonia.Input;
using Material.Icons;
using ReactiveUI;
using SkiaSharp;
@@ -95,12 +97,15 @@ public class TransformToolViewModel : ToolViewModel
/// <inheritdoc />
public override int Order => 3;
/// <inheritdoc />
public override Hotkey? Hotkey { get; } = new(KeyboardKey.T, KeyboardModifierKey.Control);
/// <inheritdoc />
public override MaterialIconKind Icon => MaterialIconKind.TransitConnectionVariant;
/// <inheritdoc />
public override string ToolTip => "Transform the shape of the current layer";
public override string ToolTip => "Transform the shape of the current layer (Ctrl+T)";
public Rect ShapeBounds
{
@@ -8,19 +8,11 @@
xmlns:shared="clr-namespace:Artemis.UI.Shared.Services.ProfileEditor;assembly=Artemis.UI.Shared"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Artemis.UI.Screens.ProfileEditor.ProfileEditorView"
x:DataType="profileEditor:ProfileEditorViewModel">
x:DataType="profileEditor:ProfileEditorViewModel"
Focusable="True">
<UserControl.Resources>
<converters:DoubleToGridLengthConverter x:Key="DoubleToGridLengthConverter" />
</UserControl.Resources>
<UserControl.KeyBindings>
<KeyBinding Command="{CompiledBinding History.Undo}" Gesture="Ctrl+Z" />
<KeyBinding Command="{CompiledBinding History.Redo}" Gesture="Ctrl+Y" />
<KeyBinding Command="{CompiledBinding ToggleSuspend}" Gesture="F5" />
<KeyBinding Command="{CompiledBinding ToggleAutoSuspend}" Gesture="Shift+F5" />
<KeyBinding Command="{CompiledBinding PropertiesViewModel.PlaybackViewModel.TogglePlay}" Gesture="Space" />
<KeyBinding Command="{CompiledBinding PropertiesViewModel.PlaybackViewModel.PlayFromStart}" Gesture="Shift+Space" />
<KeyBinding Command="{Binding TitleBarViewModel.MenuBarViewModel.CycleFocusMode}" Gesture="F" />
</UserControl.KeyBindings>
<UserControl.Styles>
<Style Selector="Border.suspended-editing">
<Setter Property="Margin" Value="-10" />
@@ -1,5 +1,3 @@
using Avalonia;
using Avalonia.Markup.Xaml;
using Avalonia.ReactiveUI;
namespace Artemis.UI.Screens.ProfileEditor;
@@ -10,16 +8,4 @@ public partial class ProfileEditorView : ReactiveUserControl<ProfileEditorViewMo
{
InitializeComponent();
}
#region Overrides of Visual
/// <inheritdoc />
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
{
base.OnAttachedToVisualTree(e);
Focus();
}
#endregion
}
@@ -28,6 +28,7 @@ public class ProfileEditorViewModel : RoutableScreen<ProfileEditorViewModelParam
private readonly IProfileEditorService _profileEditorService;
private readonly IProfileService _profileService;
private readonly ISettingsService _settingsService;
private readonly IMainWindowService _mainWindowService;
private readonly SourceList<IToolViewModel> _tools;
private ObservableAsPropertyHelper<ProfileEditorHistory?>? _history;
private ProfileConfiguration? _profileConfiguration;
@@ -44,11 +45,13 @@ public class ProfileEditorViewModel : RoutableScreen<ProfileEditorViewModelParam
DisplayConditionScriptViewModel displayConditionScriptViewModel,
StatusBarViewModel statusBarViewModel,
IEnumerable<IToolViewModel> toolViewModels,
IMainWindowService mainWindowService)
IMainWindowService mainWindowService,
IInputService inputService)
{
_profileService = profileService;
_profileEditorService = profileEditorService;
_settingsService = settingsService;
_mainWindowService = mainWindowService;
_tools = new SourceList<IToolViewModel>();
_tools.AddRange(toolViewModels);
@@ -72,11 +75,13 @@ public class ProfileEditorViewModel : RoutableScreen<ProfileEditorViewModelParam
_history = profileEditorService.History.ToProperty(this, vm => vm.History).DisposeWith(d);
_suspendedEditing = profileEditorService.SuspendedEditing.ToProperty(this, vm => vm.SuspendedEditing).DisposeWith(d);
inputService.KeyboardKeyDown += InputServiceOnKeyboardKeyDown;
mainWindowService.MainWindowFocused += MainWindowServiceOnMainWindowFocused;
mainWindowService.MainWindowUnfocused += MainWindowServiceOnMainWindowUnfocused;
Disposable.Create(() =>
{
inputService.KeyboardKeyDown -= InputServiceOnKeyboardKeyDown;
mainWindowService.MainWindowFocused -= MainWindowServiceOnMainWindowFocused;
mainWindowService.MainWindowUnfocused -= MainWindowServiceOnMainWindowUnfocused;
foreach (IToolViewModel toolViewModel in _tools.Items)
@@ -139,6 +144,33 @@ public class ProfileEditorViewModel : RoutableScreen<ProfileEditorViewModelParam
});
}
private void InputServiceOnKeyboardKeyDown(object? sender, ArtemisKeyboardKeyEventArgs e)
{
if (!Shared.UI.KeyBindingsEnabled || !_mainWindowService.IsMainWindowFocused)
return;
if (e.Modifiers == KeyboardModifierKey.Control && e.Key == KeyboardKey.Z)
History?.Undo.Execute().Subscribe();
else if (e.Modifiers == KeyboardModifierKey.Control && e.Key == KeyboardKey.Y)
History?.Redo.Execute().Subscribe();
else if (e.Modifiers == KeyboardModifierKey.None && e.Key == KeyboardKey.F5)
ToggleSuspend.Execute().Subscribe();
else if (e.Modifiers == KeyboardModifierKey.Shift && e.Key == KeyboardKey.F5)
ToggleAutoSuspend.Execute().Subscribe();
else if (e.Modifiers == KeyboardModifierKey.None && e.Key == KeyboardKey.Space)
PropertiesViewModel?.PlaybackViewModel.TogglePlay.Execute().Subscribe();
else if (e.Modifiers == KeyboardModifierKey.Shift && e.Key == KeyboardKey.Space)
PropertiesViewModel?.PlaybackViewModel.PlayFromStart.Execute().Subscribe();
else if (e.Modifiers == KeyboardModifierKey.None && e.Key == KeyboardKey.F)
(TitleBarViewModel as ProfileEditorTitleBarViewModel)?.MenuBarViewModel.CycleFocusMode.Execute().Subscribe();
else
{
IToolViewModel? tool = Tools.FirstOrDefault(t => t.Hotkey != null && t.Hotkey.MatchesEventArgs(e));
if (tool != null)
tool.IsSelected = true;
}
}
private void MainWindowServiceOnMainWindowFocused(object? sender, EventArgs e)
{
if (_settingsService.GetSetting("ProfileEditor.AutoSuspend", true).Value)