From 38986b73ac7dfaa33e145b3db7041eb6915f7bc2 Mon Sep 17 00:00:00 2001 From: Robert Date: Wed, 8 Jun 2022 21:19:08 +0200 Subject: [PATCH] Profile editor - Ensure hotkeys work whenever working i nthe editor --- src/.idea/.idea.Artemis/.idea/avalonia.xml | 1 + .../Panels/MenuBar/MenuBarView.axaml | 4 +-- .../Panels/MenuBar/MenuBarView.axaml.cs | 6 +++- .../Panels/Playback/PlaybackView.axaml | 14 ++++---- .../Panels/Playback/PlaybackViewModel.cs | 34 ++++++++++++++----- .../ProfileEditor/ProfileEditorView.axaml | 5 ++- .../ProfileEditor/ProfileEditorView.axaml.cs | 12 +++++++ .../ProfileEditor/ProfileEditorViewModel.cs | 4 ++- 8 files changed, 59 insertions(+), 21 deletions(-) diff --git a/src/.idea/.idea.Artemis/.idea/avalonia.xml b/src/.idea/.idea.Artemis/.idea/avalonia.xml index 19942bdd0..fa84392e0 100644 --- a/src/.idea/.idea.Artemis/.idea/avalonia.xml +++ b/src/.idea/.idea.Artemis/.idea/avalonia.xml @@ -32,6 +32,7 @@ + diff --git a/src/Artemis.UI/Screens/ProfileEditor/Panels/MenuBar/MenuBarView.axaml b/src/Artemis.UI/Screens/ProfileEditor/Panels/MenuBar/MenuBarView.axaml index 10c365f83..88f7a88b8 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/Panels/MenuBar/MenuBarView.axaml +++ b/src/Artemis.UI/Screens/ProfileEditor/Panels/MenuBar/MenuBarView.axaml @@ -7,7 +7,7 @@ mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:Class="Artemis.UI.Screens.ProfileEditor.MenuBar.MenuBarView" x:DataType="menuBar:MenuBarViewModel"> - + @@ -63,7 +63,7 @@ - + diff --git a/src/Artemis.UI/Screens/ProfileEditor/Panels/MenuBar/MenuBarView.axaml.cs b/src/Artemis.UI/Screens/ProfileEditor/Panels/MenuBar/MenuBarView.axaml.cs index f29875c7f..eedb4560a 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/Panels/MenuBar/MenuBarView.axaml.cs +++ b/src/Artemis.UI/Screens/ProfileEditor/Panels/MenuBar/MenuBarView.axaml.cs @@ -1,6 +1,8 @@ +using Avalonia.Controls; using Avalonia.Interactivity; using Avalonia.Markup.Xaml; using Avalonia.ReactiveUI; +using Avalonia.VisualTree; namespace Artemis.UI.Screens.ProfileEditor.MenuBar; @@ -16,7 +18,9 @@ public class MenuBarView : ReactiveUserControl AvaloniaXamlLoader.Load(this); } - private void MenuItem_OnSubmenuOpened(object? sender, RoutedEventArgs e) + private void MenuBase_OnMenuClosed(object? sender, RoutedEventArgs e) { + ProfileEditorView? profileEditorView = this.FindAncestorOfType().FindDescendantOfType(); + profileEditorView?.Focus(); } } \ No newline at end of file diff --git a/src/Artemis.UI/Screens/ProfileEditor/Panels/Playback/PlaybackView.axaml b/src/Artemis.UI/Screens/ProfileEditor/Panels/Playback/PlaybackView.axaml index eee77fd99..b092ca595 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/Panels/Playback/PlaybackView.axaml +++ b/src/Artemis.UI/Screens/ProfileEditor/Panels/Playback/PlaybackView.axaml @@ -10,33 +10,33 @@ - - - - + Command="{CompiledBinding CycleRepeating}"> diff --git a/src/Artemis.UI/Screens/ProfileEditor/Panels/Playback/PlaybackViewModel.cs b/src/Artemis.UI/Screens/ProfileEditor/Panels/Playback/PlaybackViewModel.cs index 491c05be6..a711d59c1 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/Panels/Playback/PlaybackViewModel.cs +++ b/src/Artemis.UI/Screens/ProfileEditor/Panels/Playback/PlaybackViewModel.cs @@ -1,4 +1,5 @@ using System; +using System.Reactive; using System.Reactive.Disposables; using System.Reactive.Linq; using Artemis.Core; @@ -40,8 +41,15 @@ public class PlaybackViewModel : ActivatableViewModelBase updateTimer.Start(); Disposable.Create(() => updateTimer.Stop()); }); - } + PlayFromStart = ReactiveCommand.Create(ExecutePlayFromStart); + TogglePlay = ReactiveCommand.Create(ExecuteTogglePlay); + GoToStart = ReactiveCommand.Create(ExecuteGoToStart); + GoToEnd = ReactiveCommand.Create(ExecuteGoToEnd); + GoToPreviousFrame = ReactiveCommand.Create(ExecuteGoToPreviousFrame); + GoToNextFrame = ReactiveCommand.Create(ExecuteGoToNextFrame); + CycleRepeating = ReactiveCommand.Create(ExecuteCycleRepeating); + } public TimeSpan CurrentTime => _currentTime?.Value ?? TimeSpan.Zero; public string? FormattedCurrentTime => _formattedCurrentTime?.Value; @@ -64,15 +72,23 @@ public class PlaybackViewModel : ActivatableViewModelBase get => _repeatSegment; set => RaiseAndSetIfChanged(ref _repeatSegment, value); } + + public ReactiveCommand PlayFromStart { get; } + public ReactiveCommand TogglePlay { get; } + public ReactiveCommand GoToStart { get; } + public ReactiveCommand GoToEnd { get; } + public ReactiveCommand GoToPreviousFrame { get; } + public ReactiveCommand GoToNextFrame { get; } + public ReactiveCommand CycleRepeating { get; } - public void PlayFromStart() + private void ExecutePlayFromStart() { - GoToStart(); + ExecuteGoToStart(); if (!Playing) _profileEditorService.Play(); } - public void TogglePlay() + private void ExecuteTogglePlay() { if (!Playing) _profileEditorService.Play(); @@ -80,12 +96,12 @@ public class PlaybackViewModel : ActivatableViewModelBase _profileEditorService.Pause(); } - public void GoToStart() + private void ExecuteGoToStart() { _profileEditorService.ChangeTime(TimeSpan.Zero); } - public void GoToEnd() + private void ExecuteGoToEnd() { if (_profileElement == null) return; @@ -93,7 +109,7 @@ public class PlaybackViewModel : ActivatableViewModelBase _profileEditorService.ChangeTime(_profileElement.Timeline.EndSegmentEndPosition); } - public void GoToPreviousFrame() + private void ExecuteGoToPreviousFrame() { if (_profileElement == null) return; @@ -103,7 +119,7 @@ public class PlaybackViewModel : ActivatableViewModelBase _profileEditorService.ChangeTime(TimeSpan.FromMilliseconds(newTime)); } - public void GoToNextFrame() + private void ExecuteGoToNextFrame() { if (_profileElement == null) return; @@ -114,7 +130,7 @@ public class PlaybackViewModel : ActivatableViewModelBase _profileEditorService.ChangeTime(TimeSpan.FromMilliseconds(newTime)); } - public void CycleRepeating() + private void ExecuteCycleRepeating() { if (!Repeating) { diff --git a/src/Artemis.UI/Screens/ProfileEditor/ProfileEditorView.axaml b/src/Artemis.UI/Screens/ProfileEditor/ProfileEditorView.axaml index 5d906975c..8d5878c43 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/ProfileEditorView.axaml +++ b/src/Artemis.UI/Screens/ProfileEditor/ProfileEditorView.axaml @@ -8,7 +8,8 @@ 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" + Name="ProfileEditorView"> @@ -25,6 +26,8 @@ + +