From b25ad8dfcb498dea0068de61397108c2074daee9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Wed, 10 Nov 2021 12:49:04 +0100 Subject: [PATCH] Copy editor timestamp to OS clipboard even when triggered via menu bar Would only work when triggered via Ctrl+C before, and not work at all for Ctrl+X. --- .../Screens/Edit/Compose/ComposeScreen.cs | 49 ++++++------------- 1 file changed, 16 insertions(+), 33 deletions(-) diff --git a/osu.Game/Screens/Edit/Compose/ComposeScreen.cs b/osu.Game/Screens/Edit/Compose/ComposeScreen.cs index d78dce5b60..3b02d42b41 100644 --- a/osu.Game/Screens/Edit/Compose/ComposeScreen.cs +++ b/osu.Game/Screens/Edit/Compose/ComposeScreen.cs @@ -7,9 +7,6 @@ using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; -using osu.Framework.Input; -using osu.Framework.Input.Bindings; -using osu.Framework.Input.Events; using osu.Framework.Platform; using osu.Game.Beatmaps; using osu.Game.Extensions; @@ -20,7 +17,7 @@ using osu.Game.Screens.Edit.Compose.Components.Timeline; namespace osu.Game.Screens.Edit.Compose { - public class ComposeScreen : EditorScreenWithTimeline, IKeyBindingHandler + public class ComposeScreen : EditorScreenWithTimeline { [Resolved] private GameHost host { get; set; } @@ -89,35 +86,6 @@ namespace osu.Game.Screens.Edit.Compose clipboard.BindValueChanged(_ => updateClipboardActionAvailability(), true); } - #region Input Handling - - public bool OnPressed(KeyBindingPressEvent e) - { - if (e.Action == PlatformAction.Copy) - host.GetClipboard()?.SetText(formatSelectionAsString()); - - return false; - } - - public void OnReleased(KeyBindingReleaseEvent e) - { - } - - private string formatSelectionAsString() - { - if (composer == null) - return string.Empty; - - double displayTime = EditorBeatmap.SelectedHitObjects.OrderBy(h => h.StartTime).FirstOrDefault()?.StartTime ?? clock.CurrentTime; - string selectionAsString = composer.ConvertSelectionToString(); - - return !string.IsNullOrEmpty(selectionAsString) - ? $"{displayTime.ToEditorFormattedString()} ({selectionAsString}) - " - : $"{displayTime.ToEditorFormattedString()} - "; - } - - #endregion - #region Clipboard operations protected override void PerformCut() @@ -133,6 +101,8 @@ namespace osu.Game.Screens.Edit.Compose base.PerformCopy(); clipboard.Value = new ClipboardContent(EditorBeatmap).Serialize(); + + host.GetClipboard()?.SetText(formatSelectionAsString()); } protected override void PerformPaste() @@ -164,6 +134,19 @@ namespace osu.Game.Screens.Edit.Compose CanPaste.Value = !string.IsNullOrEmpty(clipboard.Value); } + private string formatSelectionAsString() + { + if (composer == null) + return string.Empty; + + double displayTime = EditorBeatmap.SelectedHitObjects.OrderBy(h => h.StartTime).FirstOrDefault()?.StartTime ?? clock.CurrentTime; + string selectionAsString = composer.ConvertSelectionToString(); + + return !string.IsNullOrEmpty(selectionAsString) + ? $"{displayTime.ToEditorFormattedString()} ({selectionAsString}) - " + : $"{displayTime.ToEditorFormattedString()} - "; + } + #endregion } }