mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-12 21:38:38 +00:00
Profile editor - Added back hotkeys for the tools
Profile editor - Fixed hotkeys not always working
This commit is contained in:
parent
f985682e78
commit
543b62a715
@ -1,4 +1,5 @@
|
||||
using Artemis.Core.Services;
|
||||
using System;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
|
||||
namespace Artemis.Core;
|
||||
@ -16,6 +17,14 @@ public class Hotkey : CorePropertyChanged, IStorageModel
|
||||
Entity = new ProfileConfigurationHotkeyEntity();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Hotkey(KeyboardKey? key, KeyboardModifierKey? modifiers)
|
||||
{
|
||||
Key = key;
|
||||
Modifiers = modifiers;
|
||||
Entity = new ProfileConfigurationHotkeyEntity();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="Hotkey" /> based on the provided entity
|
||||
/// </summary>
|
||||
@ -46,7 +55,7 @@ public class Hotkey : CorePropertyChanged, IStorageModel
|
||||
/// <returns><see langword="true" /> if the event args match the hotkey; otherwise <see langword="false" /></returns>
|
||||
public bool MatchesEventArgs(ArtemisKeyboardKeyEventArgs eventArgs)
|
||||
{
|
||||
return eventArgs.Key == Key && eventArgs.Modifiers == Modifiers;
|
||||
return eventArgs.Key == Key && (eventArgs.Modifiers == Modifiers || (eventArgs.Modifiers == KeyboardModifierKey.None && Modifiers == null));
|
||||
}
|
||||
|
||||
#region Implementation of IStorageModel
|
||||
|
||||
@ -34,4 +34,13 @@ public class ArtemisKeyboardKeyEventArgs : EventArgs
|
||||
/// Gets the modifiers that are pressed
|
||||
/// </summary>
|
||||
public KeyboardModifierKey Modifiers { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a hotkey matching the event.
|
||||
/// </summary>
|
||||
/// <returns>The resulting hotkey.</returns>
|
||||
public Hotkey ToHotkey()
|
||||
{
|
||||
return new Hotkey {Key = Key, Modifiers = Modifiers};
|
||||
}
|
||||
}
|
||||
@ -12,6 +12,11 @@ public interface IMainWindowService : IArtemisSharedUIService
|
||||
/// </summary>
|
||||
bool IsMainWindowOpen { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a boolean indicating whether the main window is currently focused
|
||||
/// </summary>
|
||||
bool IsMainWindowFocused { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Sets up the main window provider that controls the state of the main window
|
||||
/// </summary>
|
||||
|
||||
@ -10,6 +10,9 @@ internal class MainWindowService : IMainWindowService
|
||||
/// <inheritdoc />
|
||||
public bool IsMainWindowOpen { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsMainWindowFocused { get; private set; }
|
||||
|
||||
protected virtual void OnMainWindowOpened()
|
||||
{
|
||||
MainWindowOpened?.Invoke(this, EventArgs.Empty);
|
||||
@ -24,11 +27,13 @@ internal class MainWindowService : IMainWindowService
|
||||
protected virtual void OnMainWindowFocused()
|
||||
{
|
||||
MainWindowFocused?.Invoke(this, EventArgs.Empty);
|
||||
IsMainWindowFocused = true;
|
||||
}
|
||||
|
||||
protected virtual void OnMainWindowUnfocused()
|
||||
{
|
||||
MainWindowUnfocused?.Invoke(this, EventArgs.Empty);
|
||||
IsMainWindowFocused = false;
|
||||
}
|
||||
|
||||
private void SyncWithManager()
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using Artemis.Core;
|
||||
using Avalonia.Input;
|
||||
using Material.Icons;
|
||||
|
||||
namespace Artemis.UI.Shared.Services.ProfileEditor;
|
||||
@ -43,6 +45,11 @@ public interface IToolViewModel : IDisposable
|
||||
/// Gets the tooltip which this tool should show in the toolbar.
|
||||
/// </summary>
|
||||
public string ToolTip { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the keyboard hotkey that activates the tool.
|
||||
/// </summary>
|
||||
Hotkey? Hotkey { get; }
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IToolViewModel" />
|
||||
@ -98,5 +105,8 @@ public abstract class ToolViewModel : ActivatableViewModelBase, IToolViewModel
|
||||
/// <inheritdoc />
|
||||
public abstract string ToolTip { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public abstract Hotkey? Hotkey { get; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
@ -22,7 +22,8 @@ public static class UI
|
||||
|
||||
static UI()
|
||||
{
|
||||
KeyBindingsEnabled = InputElement.GotFocusEvent.Raised.Select(e => e.Item2.Source is not TextBox).StartWith(true);
|
||||
CurrentKeyBindingsEnabled = InputElement.GotFocusEvent.Raised.Select(e => e.Item2.Source is not TextBox).StartWith(true);
|
||||
CurrentKeyBindingsEnabled.Subscribe(b => KeyBindingsEnabled = b);
|
||||
MicaEnabled = MicaEnabledSubject.AsObservable();
|
||||
}
|
||||
|
||||
@ -36,10 +37,15 @@ public static class UI
|
||||
/// </summary>
|
||||
public static IClipboard Clipboard { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets an observable boolean indicating whether hotkeys are to be disabled.
|
||||
/// </summary>
|
||||
public static IObservable<bool> CurrentKeyBindingsEnabled { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a boolean indicating whether hotkeys are to be disabled.
|
||||
/// </summary>
|
||||
public static IObservable<bool> KeyBindingsEnabled { get; }
|
||||
public static bool KeyBindingsEnabled { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a boolean indicating whether the Mica effect should be enabled.
|
||||
|
||||
@ -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;
|
||||
@ -47,7 +48,10 @@ public class SelectionAddToolViewModel : ToolViewModel
|
||||
public override MaterialIconKind Icon => MaterialIconKind.SelectionDrag;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToolTip => "Add LEDs to the current layer";
|
||||
public override Hotkey? Hotkey { get; } = new(KeyboardKey.OemPlus, KeyboardModifierKey.Control);
|
||||
|
||||
/// <inheritdoc />
|
||||
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;
|
||||
@ -39,11 +41,14 @@ 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;
|
||||
@ -96,11 +98,14 @@ 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)
|
||||
|
||||
@ -64,7 +64,7 @@ public class NodeScriptWindowViewModel : NodeScriptWindowViewModelBase
|
||||
|
||||
this.WhenActivated(d =>
|
||||
{
|
||||
_keyBindingsEnabled = Shared.UI.KeyBindingsEnabled.ToProperty(this, vm => vm.KeyBindingsEnabled).DisposeWith(d);
|
||||
_keyBindingsEnabled = Shared.UI.CurrentKeyBindingsEnabled.ToProperty(this, vm => vm.KeyBindingsEnabled).DisposeWith(d);
|
||||
|
||||
Timer updateTimer = new(TimeSpan.FromMilliseconds(25.0 / 1000));
|
||||
Timer saveTimer = new(TimeSpan.FromMinutes(2));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user