2025-08-10 13:59:44 +00:00
|
|
|
|
using AIStudio.Chat;
|
|
|
|
|
|
using AIStudio.Tools.PluginSystem;
|
|
|
|
|
|
using AIStudio.Tools.Services;
|
|
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
|
|
|
|
|
|
|
namespace AIStudio.Components;
|
|
|
|
|
|
|
|
|
|
|
|
public partial class MudCopyClipboardButton : ComponentBase
|
|
|
|
|
|
{
|
|
|
|
|
|
private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(MudCopyClipboardButton).Namespace, nameof(MudCopyClipboardButton));
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// The string, if you want to copy a string.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
|
public string StringContent { get; set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// The content, if you want to copy content.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
|
public IContent? Content { get; init; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// The content type, if you want to copy Content.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
|
public ContentType Type { get; init; } = ContentType.NONE;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// The tooltip that should be shown to the user.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
|
public string TooltipMessage { get; set; } = TB("Copies the content to the clipboard");
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// The size of the button. The default size is small.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
|
public Size Size { get; set; } = Size.Small;
|
2026-08-02 19:41:12 +00:00
|
|
|
|
|
2025-08-10 13:59:44 +00:00
|
|
|
|
[Inject]
|
|
|
|
|
|
private RustService RustService { get; init; } = null!;
|
|
|
|
|
|
|
|
|
|
|
|
private async Task HandleCopyClick()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (this.Type is ContentType.NONE)
|
|
|
|
|
|
await this.CopyToClipboard(this.StringContent);
|
|
|
|
|
|
else
|
|
|
|
|
|
await this.CopyToClipboard(this.Content);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Copy this the string to the clipboard.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private async Task CopyToClipboard(string textContent)
|
|
|
|
|
|
{
|
2026-08-02 19:41:12 +00:00
|
|
|
|
await this.RustService.CopyText2Clipboard(textContent);
|
2025-08-10 13:59:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Copy this block's content to the clipboard.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private async Task CopyToClipboard(IContent? contentToCopy)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (contentToCopy is null)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
switch (this.Type)
|
|
|
|
|
|
{
|
|
|
|
|
|
case ContentType.TEXT:
|
|
|
|
|
|
var textContent = (ContentText) contentToCopy;
|
2026-08-02 19:41:12 +00:00
|
|
|
|
await this.RustService.CopyText2Clipboard(textContent.Text);
|
2025-08-10 13:59:44 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
2026-08-02 19:41:12 +00:00
|
|
|
|
// This component is no MSGComponentBase, so it uses the shared bus instance the same
|
|
|
|
|
|
// way FileExtensionValidation does:
|
|
|
|
|
|
await MessageBus.INSTANCE.SendError(new(Icons.Material.Filled.ContentCopy, TB("Cannot copy this content type to clipboard.")));
|
2025-08-10 13:59:44 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|