mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 15:07:44 +08:00
Add Toast Notification to Copy URL
This commit is contained in:
parent
c30e8047ab
commit
2d4655f61e
@ -12,7 +12,10 @@ using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Framework.Localisation;
|
||||
using osu.Game.Localisation;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Overlays.OSD;
|
||||
using osuTK;
|
||||
using osuTK.Graphics;
|
||||
|
||||
@ -27,6 +30,9 @@ namespace osu.Game.Graphics.UserInterface
|
||||
[Resolved]
|
||||
private GameHost host { get; set; }
|
||||
|
||||
[Resolved(canBeNull: true)]
|
||||
private OnScreenDisplay onScreenDisplay { get; set; }
|
||||
|
||||
private readonly SpriteIcon linkIcon;
|
||||
|
||||
public ExternalLinkButton(string link = null)
|
||||
@ -44,6 +50,23 @@ namespace osu.Game.Graphics.UserInterface
|
||||
};
|
||||
}
|
||||
|
||||
private class CopyUrlToast : Toast
|
||||
{
|
||||
public CopyUrlToast(LocalisableString value)
|
||||
: base(UserInterfaceStrings.GeneralHeader, value, "")
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private void copyUrl()
|
||||
{
|
||||
if (Link != null)
|
||||
{
|
||||
host.GetClipboard()?.SetText(Link);
|
||||
onScreenDisplay?.Display(new CopyUrlToast(ToastStrings.CopiedUrl));
|
||||
}
|
||||
}
|
||||
|
||||
public MenuItem[] ContextMenuItems
|
||||
{
|
||||
get
|
||||
@ -53,7 +76,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
if (Link != null)
|
||||
{
|
||||
items.Add(new OsuMenuItem("Open", MenuItemType.Standard, () => host.OpenUrlExternally(Link)));
|
||||
items.Add(new OsuMenuItem("Copy URL", MenuItemType.Standard, () => host.GetClipboard()?.SetText(Link)));
|
||||
items.Add(new OsuMenuItem("Copy URL", MenuItemType.Standard, () => copyUrl()));
|
||||
}
|
||||
|
||||
return items.ToArray();
|
||||
|
@ -44,6 +44,11 @@ namespace osu.Game.Localisation
|
||||
/// </summary>
|
||||
public static LocalisableString SkinSaved => new TranslatableString(getKey(@"skin_saved"), @"Skin saved");
|
||||
|
||||
/// <summary>
|
||||
/// "Copied URL"
|
||||
/// </summary>
|
||||
public static LocalisableString CopiedUrl => new TranslatableString(getKey(@"copied_url"), @"Copied URL");
|
||||
|
||||
private static string getKey(string key) => $@"{prefix}:{key}";
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user