Resolve Clipboard via DI

This commit is contained in:
Susko3 2023-07-11 11:42:31 +02:00
parent 99d4d2be37
commit 2dcd790442
5 changed files with 20 additions and 8 deletions

View File

@ -43,6 +43,9 @@ namespace osu.Game.Graphics
[Resolved]
private GameHost host { get; set; }
[Resolved]
private Clipboard clipboard { get; set; }
private Storage storage;
[Resolved]
@ -116,7 +119,7 @@ namespace osu.Game.Graphics
using (var image = await host.TakeScreenshotAsync().ConfigureAwait(false))
{
host.GetClipboard()?.SetImage(image);
clipboard.SetImage(image);
(string filename, var stream) = getWritableStream();

View File

@ -27,6 +27,9 @@ namespace osu.Game.Graphics.UserInterface
[Resolved]
private GameHost host { get; set; } = null!;
[Resolved]
private Clipboard clipboard { get; set; } = null!;
[Resolved]
private OnScreenDisplay? onScreenDisplay { get; set; }
@ -92,8 +95,11 @@ namespace osu.Game.Graphics.UserInterface
private void copyUrl()
{
host.GetClipboard()?.SetText(Link);
onScreenDisplay?.Display(new CopyUrlToast());
if (Link != null)
{
clipboard.SetText(Link);
onScreenDisplay?.Display(new CopyUrlToast());
}
}
}
}

View File

@ -18,6 +18,9 @@ namespace osu.Game.Online.Chat
[Resolved]
private GameHost host { get; set; } = null!;
[Resolved]
private Clipboard clipboard { get; set; } = null!;
[Resolved(CanBeNull = true)]
private IDialogOverlay? dialogOverlay { get; set; }
@ -32,7 +35,7 @@ namespace osu.Game.Online.Chat
public void OpenUrlExternally(string url, bool bypassWarning = false)
{
if (!bypassWarning && externalLinkWarning.Value && dialogOverlay != null)
dialogOverlay.Push(new ExternalLinkDialog(url, () => host.OpenUrlExternally(url), () => host.GetClipboard()?.SetText(url)));
dialogOverlay.Push(new ExternalLinkDialog(url, () => host.OpenUrlExternally(url), () => clipboard.SetText(url)));
else
host.OpenUrlExternally(url);
}

View File

@ -85,7 +85,7 @@ namespace osu.Game.Overlays.Comments
private IAPIProvider api { get; set; } = null!;
[Resolved]
private GameHost host { get; set; } = null!;
private Clipboard clipboard { get; set; } = null!;
[Resolved]
private OnScreenDisplay? onScreenDisplay { get; set; }
@ -444,7 +444,7 @@ namespace osu.Game.Overlays.Comments
private void copyUrl()
{
host.GetClipboard()?.SetText($@"{api.APIEndpointUrl}/comments/{Comment.Id}");
clipboard.SetText($@"{api.APIEndpointUrl}/comments/{Comment.Id}");
onScreenDisplay?.Display(new CopyUrlToast());
}

View File

@ -23,7 +23,7 @@ namespace osu.Game.Screens.Edit.Compose
public partial class ComposeScreen : EditorScreenWithTimeline, IGameplaySettings
{
[Resolved]
private GameHost host { get; set; }
private Clipboard hostClipboard { get; set; } = null!;
[Resolved]
private EditorClock clock { get; set; }
@ -116,7 +116,7 @@ namespace osu.Game.Screens.Edit.Compose
// regardless of whether anything was even selected at all.
// UX-wise this is generally strange and unexpected, but make it work anyways to preserve muscle memory.
// note that this means that `getTimestamp()` must handle no-selection case, too.
host.GetClipboard()?.SetText(getTimestamp());
hostClipboard.SetText(getTimestamp());
if (CanCopy.Value)
clipboard.Value = new ClipboardContent(EditorBeatmap).Serialize();