Add a copy to clipboard button on alert popups. (#5336)

* Add a copy button to clipboard on Alert Popups.

* ButtonFlag and better formatting.

* Localization and style cleanup
This commit is contained in:
Repo
2024-08-09 04:56:32 +12:00
committed by GitHub
parent 49c831b48d
commit 87725f27c3
4 changed files with 41 additions and 4 deletions

View File

@@ -0,0 +1,2 @@
popup-copy-button = Copy
popup-title = Alert!

View File

@@ -64,7 +64,7 @@ namespace Robust.Client.UserInterface
IDebugMonitors DebugMonitors { get; }
void Popup(string contents, string title = "Alert!");
void Popup(string contents, string? title = null, bool clipboardButton = true);
Control? MouseGetControl(ScreenCoordinates coordinates);

View File

@@ -4,6 +4,7 @@ using System.Numerics;
using Robust.Client.Graphics;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.Localization;
using Robust.Shared.Log;
using Robust.Shared.Maths;
using Robust.Shared.Profiling;
@@ -53,14 +54,47 @@ internal sealed partial class UserInterfaceManager
}
}
public void Popup(string contents, string title = "Alert!")
public void Popup(string contents, string? title = null, bool clipboardButton = true)
{
var popup = new DefaultWindow
{
Title = title
Title = string.IsNullOrEmpty(title) ? Loc.GetString("popup-title") : title,
};
popup.Contents.AddChild(new Label {Text = contents});
var label = new Label { Text = contents };
var vBox = new BoxContainer
{
Orientation = BoxContainer.LayoutOrientation.Vertical,
};
vBox.AddChild(label);
if (clipboardButton)
{
var copyButton = new Button
{
Text = Loc.GetString("popup-copy-button"),
HorizontalExpand = true,
};
copyButton.OnPressed += _ =>
{
_clipboard.SetText(contents);
};
var hBox = new BoxContainer
{
Orientation = BoxContainer.LayoutOrientation.Horizontal,
HorizontalAlignment = Control.HAlignment.Right,
};
hBox.AddChild(copyButton);
vBox.AddChild(hBox);
}
popup.Contents.AddChild(vBox);
popup.OpenCentered();
}

View File

@@ -54,6 +54,7 @@ namespace Robust.Client.UserInterface
[Dependency] private readonly IEntitySystemManager _systemManager = default!;
[Dependency] private readonly ILogManager _logManager = default!;
[Dependency] private readonly IRuntimeLog _runtime = default!;
[Dependency] private readonly IClipboardManager _clipboard = null!;
private IAudioSource? _clickSource;
private IAudioSource? _hoverSource;