Add AttachmentsDialog component

This commit is contained in:
hart_s3 2025-12-15 14:13:36 +01:00
parent cd9ecacec5
commit 084e336f75
4 changed files with 71 additions and 9 deletions

View File

@ -8,15 +8,18 @@
} }
@if (fileInfos.Any()) @if (fileInfos.Any())
{ {
<MudBadge <MudTooltip Text="@T("Click to see your attached files")" Placement="@TOOLBAR_TOOLTIP_PLACEMENT">
Content="@this.DocumentPaths.Count" <MudBadge
Color="Color.Primary" Content="@this.DocumentPaths.Count"
Overlap="true"> Color="Color.Primary"
<MudIconButton Overlap="true"
Icon="@Icons.Material.Filled.AttachFile" OnClick="@OpenAttachmentsDialog">
Color="Color.Default" <MudIconButton
OnClick="@AddFilesManually"/> Icon="@Icons.Material.Filled.AttachFile"
</MudBadge> Color="Color.Default"
OnClick="@AddFilesManually"/>
</MudBadge>
</MudTooltip>
} }
else else
{ {

View File

@ -1,4 +1,5 @@
using AIStudio.Dialogs; using AIStudio.Dialogs;
using AIStudio.Tools.PluginSystem;
using AIStudio.Tools.Rust; using AIStudio.Tools.Rust;
using AIStudio.Tools.Services; using AIStudio.Tools.Services;
@ -10,12 +11,24 @@ using DialogOptions = Dialogs.DialogOptions;
public partial class AttachDocuments : MSGComponentBase public partial class AttachDocuments : MSGComponentBase
{ {
private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(ProfileSelection).Namespace, nameof(ProfileSelection));
[Parameter] [Parameter]
public string Name { get; set; } = string.Empty; public string Name { get; set; } = string.Empty;
[Parameter]
public bool Disabled { get; set; }
[Parameter]
public string DisabledText { get; set; } = string.Empty;
private readonly string defaultToolTipText = TB("You can edit your files here");
[Parameter] [Parameter]
public HashSet<string> DocumentPaths { get; set; } = []; public HashSet<string> DocumentPaths { get; set; } = [];
private string ToolTipText => this.Disabled ? this.DisabledText : this.defaultToolTipText;
[Parameter] [Parameter]
public EventCallback<HashSet<string>> DocumentPathsChanged { get; set; } public EventCallback<HashSet<string>> DocumentPathsChanged { get; set; }
@ -112,6 +125,18 @@ public partial class AttachDocuments : MSGComponentBase
await this.OnChange(this.DocumentPaths); await this.OnChange(this.DocumentPaths);
} }
private async Task OpenAttachmentsDialog()
{
var dialogParameters = new DialogParameters<AttachmentsDialog>
{
{ "DocumentPaths", this.DocumentPaths }
};
var dialogReference = await this.DialogService.ShowAsync<AttachmentsDialog>("Your Files", dialogParameters, DialogOptions.FULLSCREEN);
var dialogResult = await dialogReference.Result;
if (dialogResult is null || dialogResult.Canceled)
return;
}
private async Task<bool> IsFileExtensionValid(string selectedFile) private async Task<bool> IsFileExtensionValid(string selectedFile)
{ {
var ext = Path.GetExtension(selectedFile).TrimStart('.'); var ext = Path.GetExtension(selectedFile).TrimStart('.');

View File

@ -0,0 +1,19 @@
@inherits MSGComponentBase
<MudDialog>
<TitleContent>
Your attached files
</TitleContent>
<DialogContent>
@foreach (var filePath in this.DocumentPaths)
{
<MudMenuItem
Icon="@Icons.Material.Filled.AttachFile"
Label="@Path.GetFileName(filePath)">
</MudMenuItem>
}
</DialogContent>
<DialogActions>
<MudButton OnClick="@this.Cancel">Cancel</MudButton>
</DialogActions>
</MudDialog>

View File

@ -0,0 +1,15 @@
using Microsoft.AspNetCore.Components;
namespace AIStudio.Components;
public partial class AttachmentsDialog : MSGComponentBase
{
[CascadingParameter]
private IMudDialogInstance MudDialog { get; set; } = null!;
[Parameter]
public HashSet<string> DocumentPaths { get; set; } = new();
private void Cancel() => this.MudDialog.Cancel();
}